forked from Watchful1/Sketchpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostCounter.py
33 lines (27 loc) · 864 Bytes
/
postCounter.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
import requests
from datetime import datetime
from datetime import timedelta
subreddit = 'reddeadredemption'
lookback_hours = 24
types = ['comment', 'submission']
url = "https://api.pushshift.io/reddit/{}/search?&limit=1000&sort=desc&subreddit={}&before="
startTime = datetime.utcnow()
endTime = startTime - timedelta(hours=lookback_hours)
endEpoch = int(endTime.timestamp())
for type in types:
count = 0
breakOut = False
previousEpoch = int(startTime.timestamp())
while True:
newUrl = url.format(type, subreddit)+str(previousEpoch)
json = requests.get(newUrl, headers={'User-Agent': "Object counter by /u/Watchful1"})
objects = json.json()['data']
for object in objects:
previousEpoch = object['created_utc'] - 1
if previousEpoch < endEpoch:
breakOut = True
break
count += 1
if breakOut:
print(f"{count} {type}s")
break