forked from martinjc/cs-so-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.py
69 lines (44 loc) · 1.65 KB
/
get_data.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
import time
import json
import requests
from urllib.parse import urlencode, quote
from _credentials import *
BASE_URL = "https://api.stackexchange.com/"
VERSION = "2.2"
HEADERS = {"X-API-Access-Token": access_token}
PARAMETERS = {"site": "stackoverflow", "team": "stackoverflow.com/c/comsc", "key": key}
def make_request_url(endpoint, params):
return BASE_URL + VERSION + "/" + endpoint + "?" + urlencode(params)
def get_answers():
endpoint = "answers"
request_url = make_request_url(endpoint, PARAMETERS)
r = requests.get(request_url, headers=HEADERS)
with open("answers.%s.json" % (time.time()), "w") as outfile:
json.dump(r.json(), outfile)
def get_questions():
endpoint = "questions"
request_url = make_request_url(endpoint, PARAMETERS)
r = requests.get(request_url, headers=HEADERS)
with open("questions.%s.json" % (time.time()), "w") as outfile:
json.dump(r.json(), outfile)
def get_users():
endpoint = "users"
request_url = make_request_url(endpoint, PARAMETERS)
r = requests.get(request_url, headers=HEADERS)
with open("users.%s.json" % (time.time()), "w") as outfile:
json.dump(r.json(), outfile)
def get_tags():
endpoint = "tags"
parameters = PARAMETERS.copy()
parameters["sort"] = "popular"
parameters["order"] = "desc"
parameters["pagesize"] = "100"
request_url = make_request_url(endpoint, parameters)
r = requests.get(request_url, headers=HEADERS)
with open("tags.%s.json" % (time.time()), "w") as outfile:
json.dump(r.json(), outfile)
if __name__ == "__main__":
get_tags()
get_questions()
get_answers()
get_users()