forked from Watchful1/Sketchpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatsFinder.py
105 lines (82 loc) · 2.75 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
import requests
from datetime import datetime, timedelta
import time
import praw
import discord_logging
from collections import defaultdict
log = discord_logging.init_logging()
usernames = [
"ModWilliam",
]
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)