Built out interaction choices and stubbed out tagged toot method
parent
ac6896af87
commit
6d0ecd9c1d
|
@ -62,36 +62,64 @@ class Tooter(Mastodon):
|
|||
with item.open('r') as f:
|
||||
cls.files[f.name] = f.readlines()
|
||||
|
||||
def tagged_public_toot(self):
|
||||
message = self.new_message()
|
||||
if( args.dry_run ):
|
||||
print(f"tagged toot message: \"{message}\"")
|
||||
else:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} tagged toots \"{message}\"")
|
||||
|
||||
self.toot(message)
|
||||
return 0
|
||||
|
||||
def plain_public_toot(self):
|
||||
message = self.new_message()
|
||||
if( args.dry_run ):
|
||||
print(f"toot message: \"{message}\"")
|
||||
else:
|
||||
if( args.debug ):
|
||||
print(f"{self.name} toots \"{message}\"")
|
||||
|
||||
self.toot(message)
|
||||
return 0
|
||||
|
||||
@classmethod
|
||||
def new_message(cls):
|
||||
sourcefile = random.choice(list(cls.files.values()))
|
||||
startline = random.randint(0,len(sourcefile))
|
||||
sourceline = ''
|
||||
i=0
|
||||
# Starting at a random line, keep adding more lines to my
|
||||
# toot until I get over 400 characters (max is 500 on most
|
||||
# mastodon servers)
|
||||
while(len(sourceline) < 400 and startline+i < len(sourcefile)):
|
||||
sourceline=sourceline+sourcefile[startline+i]
|
||||
i+=1
|
||||
|
||||
# Try to find a 400-odd character string that ends in a full stop
|
||||
tootline = re.search( '((\s|\S){,400})\.', sourceline )
|
||||
if( tootline ):
|
||||
message=tootline.group(0).strip()
|
||||
else:
|
||||
message=sourceline.strip()
|
||||
|
||||
return(message)
|
||||
|
||||
def random_interaction(self):
|
||||
"""Choose one possible interaction according to the weights, and do it."""
|
||||
interactions = [ self.plain_public_toot, self.tagged_public_toot ]
|
||||
weights = [1, 1]
|
||||
chosen = random.choices(population=interactions, weights=weights)[0]
|
||||
chosen()
|
||||
|
||||
def daemon_main(tooter: Tooter):
|
||||
"""Run from a command line."""
|
||||
|
||||
while True:
|
||||
# do a thing
|
||||
time.sleep(600)
|
||||
|
||||
def once(tooter: Tooter):
|
||||
"""Run from a command line."""
|
||||
# message = check_public_timeline(tooter)
|
||||
message = f'{tooter.name} says hi!'
|
||||
sourcefile = random.choice(list(Tooter.files.values()))
|
||||
startline = random.randint(0,len(sourcefile))
|
||||
sourceline = ''
|
||||
i=0
|
||||
while(len(sourceline) < 400 and startline+i < len(sourcefile)):
|
||||
sourceline=sourceline+sourcefile[startline+i]
|
||||
i+=1
|
||||
|
||||
tootline = re.search( '((\s|\S){,400})\.', sourceline )
|
||||
if( tootline ):
|
||||
message=tootline.group(0).strip()
|
||||
else:
|
||||
message=sourceline.strip()
|
||||
|
||||
if( args.dry_run ):
|
||||
print(f"toot message: \"{message}\"")
|
||||
else:
|
||||
tooter.toot(message)
|
||||
return 0
|
||||
|
||||
def main():
|
||||
global args
|
||||
|
@ -124,7 +152,7 @@ def main():
|
|||
if args.once:
|
||||
for name in Tooter.credentials:
|
||||
t = Tooter(name)
|
||||
once(t)
|
||||
t.random_interaction()
|
||||
return 0
|
||||
|
||||
daemon_main(t)
|
||||
|
|
Loading…
Reference in New Issue