-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathstatsFinder.py
121 lines (98 loc) · 2.98 KB
/
statsFinder.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
120
121
import requests
from datetime import datetime, timedelta
import time
import praw
import discord_logging
from collections import defaultdict
log = discord_logging.init_logging()
usernames = [
"DatGameGuy",
"Lolburger13",
"Loomisam",
"Rinqed",
"Professional_Ad8814",
"Ali219",
"Technicoloral",
"TheUltimate721",
"Fullthrottlesolo",
"overawtch",
"kewlaid33",
"unknownQTY",
"Joeranahan1",
"--GoldenFire--",
"KloudToo",
"HeyThere8_",
"Kanshan",
]
count_url = "https://api.pushshift.io/reddit/{}/search?limit=1000&sort=desc&subreddit={}&author={}&before="
periods_url = "https://api.pushshift.io/reddit/comment/search?limit=1000&sort=desc&author={}&before="
start_time = datetime.utcnow()
end_time = start_time - timedelta(days=30 * 6)
def countObjects(object_type, username, subreddit):
count = 0
previous_epoch = int(start_time.timestamp())
break_out = False
while True:
new_url = count_url.format(object_type, subreddit, username)+str(previous_epoch)
json_data = requests.get(new_url, headers={'User-Agent': "Stat finder by /u/Watchful1"}).json()
time.sleep(0.8)
if 'data' not in json_data:
break
objects = json_data['data']
if len(objects) == 0:
break
for object in objects:
if datetime.utcfromtimestamp(object['created_utc']) < end_time:
break_out = True
break
previous_epoch = object['created_utc'] - 1
count += 1
if break_out:
break
return count
def timePeriods(username):
previous_epoch = int(start_time.timestamp())
break_out = False
hours = defaultdict(int)
offset = 4
while True:
new_url = periods_url.format(username)+str(previous_epoch)
json_data = requests.get(new_url, headers={'User-Agent': "Stat finder by /u/Watchful1"}).json()
time.sleep(0.8)
if 'data' not in json_data:
break
objects = json_data['data']
if len(objects) == 0:
break
for object in objects:
object_time = datetime.utcfromtimestamp(object['created_utc'])
if object_time < end_time:
break_out = True
break
hours[object_time.hour + offset] += 1
previous_epoch = object['created_utc'] - 1
if break_out:
break
night_est = 0
morning_est = 0
afternoon_est = 0
evening_est = 0
for hour in range(0, 6):
night_est += hours[hour]
for hour in range(7, 12):
morning_est += hours[hour]
for hour in range(13, 18):
afternoon_est += hours[hour]
for hour in range(19, 24):
evening_est += hours[hour]
print(f"{night_est}:{morning_est}:{afternoon_est}:{evening_est}")
r = praw.Reddit("Watchful1BotTest")
for username in usernames:
countComments = countObjects("comment", username, "competitiveoverwatch")
countSubmissions = countObjects("submission", username, "competitiveoverwatch")
countTmz = countObjects("comment", username, "overwatchtmz")
user = r.redditor(username)
account_age = (start_time - datetime.utcfromtimestamp(user.created_utc)).days / 365
subreddits = [f"r/{sub.display_name}" for sub in user.moderated()]
print(f"{account_age:.1f} {countComments} {countSubmissions} {countTmz} {', '.join(subreddits)}")
#timePeriods(username)