reads from files now
parent
c8d8bd7a64
commit
53fba8d1dc
|
@ -14,18 +14,20 @@ import os
|
|||
import time
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
import random
|
||||
|
||||
class Tooter(Mastodon):
|
||||
credentials: dict = {}
|
||||
hostname: str = ''
|
||||
files: dict = {}
|
||||
client_id: str = '.toota-palooza.env'
|
||||
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
cred_dict = self.credentials[self.name]
|
||||
self.username = cred_dict['addr']
|
||||
self.password = cred_dict['pass']
|
||||
self.client_id = f'.toota-palooza.env'
|
||||
self.cred_file = f'.toota-palooza-usercred-{self.name}.env'
|
||||
|
||||
super().__init__(client_id=self.client_id, api_base_url=self.hostname)
|
||||
|
@ -52,6 +54,14 @@ class Tooter(Mastodon):
|
|||
raise KeyError(f'`pass` field missing from {username}')
|
||||
cls.credentials = as_dict
|
||||
|
||||
@classmethod
|
||||
def load_src_files(cls, dir: Path) -> None:
|
||||
for item in dir.iterdir():
|
||||
if not item.is_file():
|
||||
continue
|
||||
with item.open('r') as f:
|
||||
cls.files[f.name] = f.readlines()
|
||||
|
||||
|
||||
def check_public_timeline(tooter: Tooter):
|
||||
"""Do one run. Connect to the database, connect to the server, get the public timeline.
|
||||
|
@ -107,7 +117,22 @@ def once(tooter: Tooter):
|
|||
"""Run from a command line."""
|
||||
# message = check_public_timeline(tooter)
|
||||
message = f'{tooter.name} says hi!'
|
||||
tooter.toot(message)
|
||||
print(
|
||||
# random sentence
|
||||
random.choice(
|
||||
# from a random line
|
||||
random.choice(
|
||||
# from a random file
|
||||
random.choice(
|
||||
list(tooter.files.values())
|
||||
)
|
||||
)
|
||||
# stripped and split on full stops
|
||||
.strip().split('.')
|
||||
)
|
||||
# stripped of weird punctuation
|
||||
.strip()
|
||||
)
|
||||
return 0
|
||||
|
||||
def main():
|
||||
|
@ -117,10 +142,22 @@ def main():
|
|||
help='Enable debugging messages.')
|
||||
parser.add_argument( '-o', '--once', action='store_true',
|
||||
help='Run once and exit. Default is to run as a daemon.')
|
||||
parser.add_argument( 'file', nargs='?', default='users.toml',
|
||||
parser.add_argument( '-D', '--directory', default='text',
|
||||
help='Change directory to source files from.')
|
||||
parser.add_argument( 'file', type=argparse.FileType('r'),
|
||||
help='Change file to source users from.')
|
||||
args = parser.parse_args()
|
||||
|
||||
p = Path(args.directory)
|
||||
if not p.exists():
|
||||
print(f'{sys.argv[0]}: {args.directory}: No such file or directory', file=sys.stderr)
|
||||
return 2
|
||||
if not p.is_dir():
|
||||
print(f'{sys.argv[0]}: {args.directory}: Is not a directory', file=sys.stderr)
|
||||
return 2
|
||||
|
||||
Tooter.load_src_files(p)
|
||||
|
||||
Tooter.load_credentials(args.file)
|
||||
|
||||
if args.once:
|
||||
|
|
Loading…
Reference in New Issue