aboutsummaryrefslogtreecommitdiffstats
path: root/bot.py
blob: 5ed95eb33897cca206e7e3320b00f3f85bd3bb27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
os.chdir("/home/eden/yaoi-communism")

from twython import Twython
import get_images

os.environ["SSL_CERT_DIR"] = "/etc/ssl/certs"

twitter = Twython(*get_images.CONFIG["twitterapi"].values())

def post():
    images = get_images.main()
    while images is None:
        images = get_images.main()
    impath, source, text = images
    with open(impath, "rb") as img:
        response = twitter.upload_media(media = img)
        message = f"{text} ({source})"
        out = twitter.update_status(status=message, media_ids=[response["media_id"]])

    get_images.logging.info("Posted to twitter.")

if __name__ == "__main__":
    post()