Browse Source

Add Multi-Account functionality

Signed-off-by: Amy Aronsohn <WagThatTail@Me.com>
master 0.4.0
Amelia A 3 years ago
parent
commit
132252664e
Signed by: amy GPG Key ID: 70C320ABA95D38C1
5 changed files with 39 additions and 21 deletions
  1. +1
    -1
      Makefile
  2. +5
    -0
      README.md
  3. +1
    -0
      tootlogger.toml.example
  4. +27
    -19
      tootlogger/cli.py
  5. +5
    -1
      tootlogger/templates/template.jinja2

+ 1
- 1
Makefile View File

@ -1,4 +1,4 @@
.PHONY: clean clean-test clean-pyc clean-build
.PHONY: clean clean-test clean-pyc clean-build upload
dist: clean
pipenv run python setup.py sdist


+ 5
- 0
README.md View File

@ -30,8 +30,13 @@ You will need to manually generate your access token and create a config file
### Config file
```toml
["account_name"]
instance = "https://mastodon.social"
access_token = "really big string"
["cool account @ bofh.lol"]
instance = "https://bofh.lol"
access_token = "different big string"
```
## Usage


+ 1
- 0
tootlogger.toml.example View File

@ -1,2 +1,3 @@
["account_name"]
instance = "https://mastadon.social"
access_token = "You really need this"

+ 27
- 19
tootlogger/cli.py View File

@ -54,7 +54,9 @@ def get_toots(api_base_url, access_token, last_id=None):
def parse_toots_to_journal(toots):
cleaned_toot_data = map(toot_cleaner, toots)
cleaned_toot_data = {}
for account, account_toots in toots.items():
cleaned_toot_data[account] = map(toot_cleaner, account_toots)
jinja_env = Environment(
loader=PackageLoader(APP_NAME, "templates"),
@ -63,7 +65,7 @@ def parse_toots_to_journal(toots):
lstrip_blocks=True,
)
template = jinja_env.get_template('template.jinja2')
return template.render(toots=cleaned_toot_data)
return template.render(toot_data=cleaned_toot_data)
def toot_cleaner(toot):
@ -84,22 +86,28 @@ def main():
if not os.path.isfile(DAYONE_CLI):
fatal(f"DayOne cli {DAYONE_CLI} is not present. Please install")
toots = get_toots(
conf['instance'],
conf['access_token'],
conf.get('last_id')
toots = {}
for account, settings in conf.items():
toots[account] = get_toots(
settings['instance'],
settings['access_token'],
settings.get('last_id')
)
journal = parse_toots_to_journal(toots)
subprocess.run(
[DAYONE_CLI, DAYONE_COMMAND],
input=journal,
text=True,
check=True,
)
# Don't try to update things if I didn't toot
if toots:
journal = parse_toots_to_journal(toots)
subprocess.run(
[DAYONE_CLI, DAYONE_COMMAND],
input=journal,
text=True,
check=True
)
conf['last_id'] = get_latest_post_id(toots)
save_config(conf)
else:
print("Gosh! No toots today so no journal")
for account, toot_list in toots.items():
if toot_list:
conf[account]['last_id'] = get_latest_post_id(toot_list)
save_config(conf)
if __name__ == '__main__':
main()

+ 5
- 1
tootlogger/templates/template.jinja2 View File

@ -1,10 +1,14 @@
The day's toots!
{% for account, toots in toot_data.items() %}
## On account {{ account }}
{% for toot in toots %}
At {{ toot.created_at.strftime("%Y-%m-%d %H:%M:%S %Z") }} I tooted;
{{ toot.content }}
---
{% else %}
You didn't toot at all today!
No toots for this account!
{% endfor %}
{% endfor %}

Loading…
Cancel
Save