-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (46 loc) · 1.42 KB
/
Copy pathmain.py
File metadata and controls
57 lines (46 loc) · 1.42 KB
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
from math import perm
import requests
import json
import json
import datetime
def get_pushshift_data(ticker, after, before, sub):
url = 'https://api.pushshift.io/reddit/search/submission/?q=' + str(ticker) + '&after' + str(after) + '&before' + str(before) + '&subreddit=' + str(sub)
print(url)
r = requests.get(url)
data = json.loads(r.text, strict=False)
return data['data']
def collect_subData(subm):
subData = list()
title = subm['title']
url = subm['url']
try:
flair = subm['link_flair_text']
except KeyError:
flair = "NaN"
try:
body = subm['selftext']
except KeyError:
body = ''
author = subm['author']
subId = subm['id']
score = subm['score']
created = datetime.datetime.fromtimestamp(subm['created_utc'])
numComms = subm['num_comments']
permalink = subm['permalink']
subData.append((subId, title, body, url, author, score, created, numComms, permalink, flair))
subStats = {}
subCount = 0
sub = 'wallstreetbets'
after = '1641960870'
before = datetime.time
data = get_pushshift_data(after, before, sub)
while len(data) > 0:
for submission in data:
collect_subData(submission)
subCount += 1
print(len(data))
print(str(datetime.datetime.fromtimestamp((data[-1]['created_utc']))))
after = data[-1]['created_utc']
data = get_pushshift_data(after, before, sub)
print(len(data))
print(data)