-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.py
executable file
·34 lines (28 loc) · 929 Bytes
/
post.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
# !/bin/python
# -*- encoding: utf-8 -*-
import json
import twitter
import random
import time
import private
def poster():
api = twitter.Api(private.consumer_key,
private.consumer_secret,
private.access_token_key,
private.access_token_secret)
with open('reddit.json', 'r') as f:
subreddits = json.load(f)
chosen_subreddit = random.choice(list(subreddits.keys()))
chosen_image = random.choice(subreddits[chosen_subreddit])
api.PostUpdate('From: /r/{}'.format(chosen_subreddit), media=chosen_image)
subreddits[chosen_subreddit].remove(chosen_image)
with open('reddit.json', 'w') as f:
json.dump(subreddits, f)
if __name__ == '__main__':
times = input('Number of tweets: ')
for x in range(int(times)):
try:
poster()
time.sleep(5)
except:
print('Error')