dont setup twitter by default
[pdt.git] / t.py
CommitLineData
f9ace606
IK
1#!/usr/bin/env python3
2
3# based on
4# https://github.com/python-twitter-tools/twitter
5
6import sys
7import os
8from twitter import *
9import fileinput
10
11# if needed for development, just hardcode
12#oauth_token = ""
13#oauth_secret = ""
14
15
16first = True
213207f1 17with fileinput.input(files=(os.environ.get('HOME') + os.sep + '.rainbow_oauth')) as f:
f9ace606
IK
18 # ok, this is dumb, but it works
19 for line in f:
20 if first:
21 oauth_token = line.rstrip()
22 first = False
23 else:
24 oauth_secret = line.rstrip()
25
26CONSUMER_KEY = 'hJHyPhuU7nSVHrKTVsGVDM4Lw'
27CONSUMER_SECRET = '8UCYePqc1y9DY6mg0yQzLoTuq57AIysype2Si63714uACGMCbO'
28
29t = Twitter(auth=OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
30
31tweet_text = input()
32have_image = False
33try:
34 image_path = input()
35 have_image = True
36except:
37 pass
38
39have_alt = False
40try:
41 alt = input()
42 have_alt = True
43except:
44 pass
45
46if have_image:
47 with open(image_path, "rb") as imagefile:
48 imagedata = imagefile.read()
49 t_upload = Twitter(domain='upload.twitter.com',
50 auth=OAuth(oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET))
51 id_img = t_upload.media.upload(media=imagedata)["media_id_string"]
52
53if have_alt:
54 t_upload.media.metadata.create(media_id=id_img, text=alt)
55
56if have_image:
57 t.statuses.update(status=tweet_text, media_ids=id_img)
58else:
59 t.statuses.update(status=tweet_text)