-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths.py
119 lines (87 loc) · 2.74 KB
/
s.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# coding: utf-8
# In[2]:
import os
import praw
import time
import json
from dropboxUP import upload
number = 2500
user_data = {"username": os.environ["username"],
"password": os.environ["password"],
"client_id": os.environ["client_id"],
"client_secret": os.environ["client_secret"],
"user_agent": "Reddit python extractor by /u/Aad1tya23"}
TOKEN = os.environ["dropbox_token"]
# In[3]:
def submissionData(num, submission, now):
id_ = submission.id
tmp = (now - submission.created_utc)/(60*60)
utc_ = int(tmp * 1000)/1000
upv_ = submission.score
return {"rank": num, "id": id_, "time": utc_, "upvote": upv_}
def authorize():
reddit = praw.Reddit(username = user_data["username"],
password = user_data["password"],
client_id = user_data["client_id"],
client_secret = user_data["client_secret"],
user_agent = user_data["user_agent"])
return reddit
# In[4]:
def get_hot(reddit, now):
num = 0
data_hot = []
#Make list of data
for _ in reddit.subreddit('all').hot(limit=number):
num = num+1
if num%100 == 0: print(int(num/100), end=" ")
data_hot.append(submissionData(num, _, now))
return data_hot
def get_top(reddit, now):
num = 0
data_top = []
#Make list of data
for _ in reddit.subreddit('all').top("hour"):
num = num+1
if num%100 == 0: print(int(num/100), end=" ")
data_top.append(submissionData(num, _, now))
return data_top
# In[5]:
def output_json(now, data_hot, data_top):
#Create empty data.json, start again
# json_Data = json.dumps({"filename": []})
# with open('data.json', 'w') as outfile:
# json.dump(json_Data, outfile)
#Save data in json form
json_dump = {
"time": now,
"data_hot": data_hot,
"data_top": data_top,
"keys": "Id, Hours uploaded, Upvotes"
}
dropbox_files = upload(TOKEN, str(int(now)), json_dump)
return dropbox_files
def main():
reddit = authorize()
print("Authorized: ", reddit.user.me())
now = time.time()
print("Hot: ", end="")
data_hot = get_hot(reddit, now)
print("Top: ", end="")
data_top = get_top(reddit, now)
print("\nNow uploading to Dropbox...\nFiles: ", end="")
files = output_json(now, data_hot, data_top)
print(files)
last_did = time.time()
print("Started at: ", last_did)
# while True:
# present = time.time()
# if present - last_did > 6*60:
# print()
# main()
# last_did = present
# else:
# print(".", end=" ")
# time.sleep(60* 2)
while True:
main()
time.sleep(3590)