-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsub_repost.py
53 lines (43 loc) · 2.04 KB
/
sub_repost.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
49
50
51
52
53
import praw
import tweepy
import json
import urllib.request
import time
import datetime
import schedule
import os # file handling
def RunAction():
reddit = praw.Reddit(user_agent='VALUE', client_id='VALUE', client_secret='VALUE', username='VALUE', password='VALUE')
twitter_auth_info = {
"consumer_key" : "VALUE",
"consumer_secret" : "VALUE",
"access_token" : "VALUE",
"access_token_secret" : "VALUE"
}
auth = tweepy.OAuthHandler(twitter_auth_info['consumer_key'], twitter_auth_info['consumer_secret'])
auth.set_access_token(twitter_auth_info['access_token'], twitter_auth_info['access_token_secret'])
twitter = tweepy.API(auth)
dateToday = datetime.date.today()
dateYesterday = datetime.date.today() - datetime.timedelta(1)
# initial search done on pushshift which unforunately as of now lacks score updating, use reddit's api to get actual score
url = "https://api.pushshift.io/reddit/submission/search/?subreddit=AssassinsCreedOdyssey&after={}&before={}&size=512".format(dateYesterday, dateToday)
data = json.loads(urllib.request.urlopen(url).read().decode())
most_upvotes = 0
chosen_post_info = {}
for x in range(len(data["data"])):
if "link_flair_text" in data["data"][x] and data["data"][x]["link_flair_text"] == "Photo Mode":
postinfo = reddit.submission(data["data"][x]["id"])
if postinfo.score > most_upvotes:
chosen_post_info = {'author': postinfo.author, "url": postinfo.permalink,'imgurl': postinfo.url, "score": postinfo.score}
most_upvotes = postinfo.score
if "imgurl" in chosen_post_info:
tempFile = "temp." + chosen_post_info["imgurl"][-3:]
urllib.request.urlretrieve(chosen_post_info["imgurl"], tempFile)
tweet_text = "Tweet Test"
twitter.update_with_media(filename = tempFile, status = tweet_text)
os.remove(tempFile)
schedule.every().day.at("00:15").do(RunAction)
while True:
schedule.run_pending()
time.sleep(30)
#RunAction()