-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreview.py
84 lines (74 loc) · 2.75 KB
/
review.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
"""
UWE Review Scraper Tool
Core Module
author: [email protected]
"""
import datetime
import sys
import csv
from source.review import Review
from source.batch import Batch
from source.review import Review
OUTPUT_FILE = None
APP_ID = None
THREADS = None
HELP_TEXT = """
Configuration flags:
--app (-a): [Required] Specify the Steam AppID to target.
E.g. python3 review.py -a 264710
--file (-f): [Required] Specify a file in which to write reviews.
E.g. python3 review.py -f all_subnautica_reviews.csv
--threads (-t): [Optional] Specify the number of concurrent requests
that should be made to Steamworks. If you push this
too high, you may hit a rate-limit. Defaults to 8.
E.g. python3 review.py -t 10
"""
if len(sys.argv[1:]) < 1:
print(HELP_TEXT)
VALID_ARGUMENTS = ['--file', '-f', '--help', '-h', '--app', '-a', '--threads', '-t']
SKIP = False
ITERATION = -1
for argument in sys.argv[1:]:
ITERATION += 1
if SKIP == True:
SKIP = False
continue
if argument not in VALID_ARGUMENTS:
error_string = "Invalid argument '" + str(argument) + '" supplied'
error_string += '. Run with -h flag to see available commands'
raise RuntimeError(error_string)
if argument == '-h' or argument == '--help':
quit()
if str(argument) == '-a' or argument == '--app':
try:
APP_ID = int(sys.argv[1:][ITERATION + 1])
except:
raise RuntimeError('Value associated with --app flag invalid.')
SKIP = True
continue
if argument == '--file' or argument == '-f':
try:
OUTPUT_FILE = str(sys.argv[1:][ITERATION + 1])
except:
raise RuntimeError('Value associated with --file flag invalid.')
SKIP = True
continue
if argument == '--threads' or argument == '-t':
try:
THREADS = int(sys.argv[1:][ITERATION + 1])
except:
raise RuntimeError('Invalid valie associated with --threads flag')
SKIP = True
continue
if OUTPUT_FILE == None or APP_ID == None:
raise RuntimeError('Required configuration flag missing. Run with --help flag.')
with open(OUTPUT_FILE, 'w') as output_file:
writer = csv.writer(output_file)
writer.writerow(Review.csv_headers())
start = datetime.datetime.now()
current_batch = Batch(264710, 0)
estimated_available = current_batch.estimated_total_available()
while current_batch.number_of_reviews_retrieved() > 0:
print(current_batch.estimate_progress(start, estimated_available), end='\r')
writer.writerows(current_batch.csv_lines())
current_batch = Batch(264710, current_batch.next_batch_start())