-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvndb_query.py
executable file
·46 lines (36 loc) · 1.2 KB
/
vndb_query.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import csv
import os
import urllib.request
# Output files
_OUTPUT_FOLDER = "output/"
# Edited from first-fm
def load_secrets():
# Load secret credentials from local file
secrets_file = ".env.local"
if os.path.isfile(secrets_file):
with open(secrets_file, "r", encoding="utf-8") as f:
lines = f.readlines()
doc = {}
for line in lines:
if "=" in line:
key, value = line.split("=")
doc[key.strip()] = value.strip().strip("'")
return doc
def get_data(query_id, output):
# Get query results
url = "https://query.vndb.org/" + query_id + ".csv"
# trunk-ignore(bandit/B310)
with urllib.request.urlopen(url, timeout=30) as response:
data = response.read().decode("utf-8").splitlines()
os.makedirs(_OUTPUT_FOLDER, exist_ok=True)
with open(_OUTPUT_FOLDER + output, "w", encoding="utf-8") as file:
writer = csv.writer(file)
for row in csv.reader(data):
writer.writerow(row)
secrets = load_secrets()
lvid = secrets["LVID"]
mmid = secrets["MMID"]
get_data(lvid, "lengthvotes.csv")
get_data(mmid, "monthly.csv")