-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixietooth.py
48 lines (42 loc) · 1.6 KB
/
pixietooth.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
48
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
from mastodon import Mastodon
import argparse
parser = argparse.ArgumentParser(description="Post to a Pixelfed instance with YAML files",
prog="pixietooth")
parser.add_argument("-f","--token-file",
help="A file containing a Pixelfed access token",
required=True)
parser.add_argument("-i","--instance",
help="A Pixelfed instance (https://pixelfed.social by default)",
default="https://pixelfed.social")
parser.add_argument("-s","--sensitive",
help="Sensitive/NSFW content",
action="store_true")
parser.add_argument("-w","--visibility",
help="One of 'direct', 'private', 'unlisted' and 'public'")
parser.add_argument("file",nargs="+",help="YAML file describing the post (UTF-8)")
args = parser.parse_args()
token_file = args.token_file
instance = args.instance
sensitive = args.sensitive
visibility = args.visibility
names = args.file
with open(token_file,"r") as file:
personal_access_token = file.read().rstrip()
mastodon = Mastodon(
access_token = personal_access_token,
api_base_url = instance,
version_check_mode = "none" # Pixelfed's versioning is independent of Mastodon's
)
for name in names:
stream = open(name,"r",encoding="UTF-8")
post = load(stream,Loader=Loader)
ids = []
for item in post["items"]:
media = mastodon.media_post(media_file=item)
ids.append(media["id"])
mastodon.status_post(post["text"],media_ids=ids,sensitive=sensitive,visibility=visibility)