Module: init

Right now there is nothing here. Someday I hoped to make an interactive init command that will ask you for all the things you need to put in your mastoscore.ini file. There's nothing useful here right now. Just a stub.


Code Reference

Initialise the environment for mastoscore

init()

Someday this will be an interactive way to setup your mastoscore.ini file.

Source code in mastoscore/init.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def init():
    """
    Someday this will be an interactive way to setup your mastoscore.ini file.
    """

    print(
        """
Welcome to Mastoscore, a bot that will fetch a bunch of toots related to a hashtag,
then toot about what happened. This was originally created to write about #monsterdon,
but you can use it for lots of things.
""")
    config = configparser.ConfigParser(default_section='mastoscore')
    logger = logging.getLogger(__name__)
    logging.basicConfig(format='%(levelname)s\t%(message)s')
    logger.setLevel(debug)

    interval = datetime.timedelta(days=lookback)
    oldest_date = datetime.datetime.utcnow() - interval
    oldest_str = oldest_date.strftime("%Y-%m-%d")
    logger.debug(f"Lookback is {lookback} days, which is {oldest_str}")

    try:
        t = Tooter(config, 'fetch')
    except Exception as e:
        logger.critical("no tooter")
        logger.critical(e)
        exit(1)

    logger.debug(
        f"Looking for at most {maxtoots} toots with #{hashtag} since {oldest_str}")
    toots = t.search_hashtag(hashtag, interval, maxtoots)
    try:
        jfile = open(journal, "w")
        json.dump(toots, jfile, default=jsonencode)
    except Exception as e:
        logger.critical(
            f"Failed to write {len(toots)} toots to {journal}")
        logger.critical(e)
        exit(1)
    logger.info(f"Wrote {len(toots)} toots to {journal}")