forked from ticketfrei/ticketfrei
implement basic auto-reblogging
This commit is contained in:
parent
12fb550737
commit
3f02891223
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,3 +1,7 @@
|
|||
*.swp
|
||||
ticketfrei.cfg
|
||||
seen_toots.pickle
|
||||
seen_toots.pickle.part
|
||||
pip-selfcheck.json
|
||||
bin/
|
||||
include/
|
||||
|
|
2
README
2
README
|
@ -9,5 +9,5 @@ $ . bin/activate
|
|||
```
|
||||
Install dependencies
|
||||
```shell
|
||||
$ pip3 install Mastodon.py
|
||||
$ pip3 install Mastodon.py pytoml
|
||||
```
|
||||
|
|
2
appkeys/.gitignore
vendored
Normal file
2
appkeys/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
7
ticketfrei.cfg.example
Normal file
7
ticketfrei.cfg.example
Normal file
|
@ -0,0 +1,7 @@
|
|||
[app]
|
||||
app_name = 'yourcity_ticketfrei'
|
||||
|
||||
[user]
|
||||
email = 'youremail@server.tld'
|
||||
password = 'yourpassword'
|
||||
server = 'yourmastodoninstance'
|
50
ticketfrei.py
Normal file
50
ticketfrei.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import pytoml as toml
|
||||
import mastodon
|
||||
import pickle
|
||||
import os
|
||||
import time
|
||||
|
||||
# read config in TOML format (https://github.com/toml-lang/toml#toml)
|
||||
with open('ticketfrei.cfg') as configfile:
|
||||
config = toml.load(configfile)
|
||||
|
||||
client_id = os.path.join(
|
||||
'appkeys',
|
||||
config['app']['name'] + '@' + config['user']['server']
|
||||
)
|
||||
|
||||
if not os.path.isfile(client_id):
|
||||
mastodon.Mastodon.create_app(
|
||||
config['app']['name'],
|
||||
api_base_url=config['user']['server'],
|
||||
to_file=client_id
|
||||
)
|
||||
|
||||
m = mastodon.Mastodon(
|
||||
client_id=client_id,
|
||||
api_base_url=config['user']['server']
|
||||
)
|
||||
m.log_in(config['user']['email'], config['user']['password'])
|
||||
|
||||
try:
|
||||
with open('seen_toots.pickle', 'rb') as f:
|
||||
seen_toots = pickle.load(f)
|
||||
except IOError:
|
||||
seen_toots = set()
|
||||
|
||||
while True:
|
||||
for notification in m.notifications():
|
||||
if (notification['type'] == 'mention'
|
||||
and notification['status']['id'] not in seen_toots):
|
||||
print('Boosting toot %d from %s: %s' % (
|
||||
notification['status']['id'],
|
||||
notification['status']['account']['acct'],
|
||||
notification['status']['content']))
|
||||
seen_toots.add(notification['status']['id'])
|
||||
m.status_reblog(notification['status']['id'])
|
||||
with open('seen_toots.pickle.part', 'wb') as f:
|
||||
pickle.dump(seen_toots, f)
|
||||
os.rename('seen_toots.pickle.part', 'seen_toots.pickle')
|
||||
time.sleep(1)
|
Loading…
Reference in a new issue