-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoot_spam.py
executable file
·47 lines (38 loc) · 1.49 KB
/
toot_spam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
import os.path
import sys
import re
from mastodon import Mastodon
import requests
if len(sys.argv) < 4:
print("Usage: python3 toot_spam.py mastodon_login mastodon_passwd mastodon_instance text [pic_url]") # noqa
sys.exit(1)
pic = None
if len(sys.argv) > 4:
pic = sys.argv[5]
mastodon = sys.argv[1]
passwd = sys.argv[2]
instance = sys.argv[3]
text = sys.argv[4]
mastodon_api = None
if mastodon_api is None:
# Create application if it does not exist
if not os.path.isfile(instance+'.secret'):
if Mastodon.create_app('toot_spam', api_base_url='https://'+instance, to_file=instance+'.secret'):
print('toot_spam app created on instance '+instance)
else:
print('failed to create app on instance '+instance)
sys.exit(1)
try:
mastodon_api = Mastodon(client_id=instance+'.secret', api_base_url='https://'+instance)
mastodon_api.log_in(username=mastodon, password=passwd, scopes=['read', 'write'], to_file=mastodon+".secret")
except:
print("ERROR: First Login Failed!")
sys.exit(1)
toot_media = []
# get the pictures...
if pic is not None:
media = requests.get(pic)
media_posted = mastodon_api.media_post(media.content, mime_type=media.headers.get('content-type'))
toot_media.append(media_posted['id'])
if toot_media is not None:
toot = mastodon_api.status_post(text, in_reply_to_id=None, media_ids=toot_media, sensitive=False, visibility='unlisted', spoiler_text=None)