-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteamScrape.py
190 lines (167 loc) · 6.79 KB
/
steamScrape.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import requests
import urllib.parse
from time import sleep
import os
from dotenv import load_dotenv
from urllib.parse import quote
import pickle
import re
load_dotenv()
KEY = os.getenv('KEY')
def getUserReviews(reviewAppid, params):
#userReviewsUrl = f'https://store.steampowered.com/appreviews/{reviewAppid}'
cursor = params['cursor']
userReviewsUrl = f"https://store.steampowered.com/appreviews/{reviewAppid}?json=1&cursor={cursor}&filter_offtopic_activity=0&filter=recent&language=english&num_per_page=100"
userReviewsResponse = requests.get(
userReviewsUrl,
#params=params
)
print(f"Status Code: {userReviewsResponse.status_code}")
if (userReviewsResponse.status_code != 200) and (userReviewsResponse.status_code != 429):
print(f'Fail to get response for {reviewAppid}. Status code: {userReviewsResponse.status_code}')
return {'success' : 0}, userReviewsResponse.status_code
try:
userReviews = userReviewsResponse.json()
except:
return {"success": 0}, userReviewsResponse.status_code
return userReviews, userReviewsResponse.status_code
gamesOfInterestFemale = {
'870780' : 'Control Ultimate Edition',
'752590' : 'A Plague Tale Innocence',
'750920' : 'Shadow of the Tomb Raider',
'414340' : "Hellblade: Senua's Sacrifice",
'524220' : 'Nier:Automata',
'1265920' : 'Life is Strange Remastered',
}
gamesOfInterestMale = {
'108710' : 'Alan Wake',
'532210' : 'Life is Strange 2',
'1659420' : 'Uncharted: Legacy of Thieves Collection',
'814380' : 'Sekiro: Shadows Die Twice - GOTY Edition',
'1687950' : 'Persona 5 Royal',
'2050650' : 'Resident Evil 4'
}
allGamesOfInterest = {
'female' : gamesOfInterestFemale,
'male' : gamesOfInterestMale
}
def parseResponse(gameId, gameTitle):
reviewsSkipped = 0
reviews = []
name = gameTitle
reviewMax = 100
#reviewMax = 20
params = {
#'json' : 1,
#'language' : 'english',
'cursor' : '*',
#'filter_offtopic_activity' : 1,
#'num_per_page': 100,
#'key' : KEY,
#'filter' : 'recent'
}
while(True):
reviewMin = reviewMax - 100
#reviewMin = reviewMax - 20
print(f"Getting Reviews: {reviewMin}-{reviewMax} for {name}")
print(f"Params: {params}")
response,status = getUserReviews(gameId,params)
if status == 429:
print(f"Rate Limiting")
sleep(300)
continue
print(f"Extracted {len(response['reviews'])} reviews")
#print(response['reviews'])
#if response['success'] != 1:
# print(f'Fail to get response for {gameId}.')
# return {'allReviewsGot' : 0}, []
for review in response['reviews']:
try:
recommendationId = review['recommendationid']
timestampCreated = review['timestamp_created']
timestampUpdated = review['timestamp_updated']
authorSteamId = review['author']['steamid']
playtimeForever = review['author']['playtime_forever']
playtimeLastTwoWeeks = review['author']['playtime_last_two_weeks']
playtimeAtReviewMinutes = review['author']['playtime_at_review']
lastPlayed = review['author']['last_played']
reviewText = review['review']
votedUp = review['voted_up']
votesUp = review['votes_up']
votesFunny = review['votes_funny']
weightedVoteScore = review['weighted_vote_score']
steamPurchase = review['steam_purchase']
receivedForFree = review['received_for_free']
writtenDuringEarlyAccess = review['written_during_early_access']
myReviewDict = {
'recommendationid': recommendationId,
'authorSteamid': authorSteamId,
'playtimeAtReviewMinutes': playtimeAtReviewMinutes,
'playtimeForeverMinutes': playtimeForever,
'playtimeLastTwoWeeksMinutes': playtimeLastTwoWeeks,
'lastPlayed': lastPlayed,
'reviewText': reviewText,
'timestampCreated': timestampCreated,
'timestampUpdated': timestampUpdated,
'votedUp': votedUp,
'votesUp': votesUp,
'votesFunny': votesFunny,
'weightedVoteScore': weightedVoteScore,
'steamPurchase': steamPurchase,
'receivedForFree': receivedForFree,
'writtenDuringEarlyAccess': writtenDuringEarlyAccess,
}
reviews.append(myReviewDict)
except:
print("Skipped Review")
reviewsSkipped += 1
print(f'Reviews Skipped: {reviewsSkipped}')
if response['cursor'] == params['cursor']:
return reviews
if response['query_summary']['num_reviews'] == 0:
print(f'No more reviews: {response}')
return reviews
try:
cursor = response['cursor']
print(cursor)
params['cursor'] = quote(cursor)
print(params['cursor'])
except:
return reviews
reviewMax += 100
#reviewMax += 20
sleep(1.5)
steamIDs = ['870780','752590','750920','414340','524220','1265920','108710','532210','1659420','814380','1687950','2050650']
'''
while (steamIDs):
for key,items in allGamesOfInterest.items():
for key,val in items.items():
info, reviews = parseResponse(key,val)
title = val.strip().replace(" ","_").lower()
titleClean = re.sub(r'[^\w_. -]', '_', title)
data = [key,info,reviews]
if info['allReviewsGot'] == 1:
with open(f'{titleClean}.pkl','wb') as f:
pickle.dump(data,f)
try:
steamIDs.remove(key)
except:
print("Crying is a free action")
else:
print(f"Failed to get all data, Only scraped: {len(reviews)} reviews")
print()
sleep(3600)
'''
for key,items in allGamesOfInterest.items():
for key,val in items.items():
reviews = parseResponse(key,val)
title = val.strip().replace(" ","_").lower()
titleClean = re.sub(r'[^\w_. -]', '_', title)
data = {key : reviews}
with open(f'./data/pkl/{titleClean}.pkl','wb') as f:
pickle.dump(data,f)
try:
steamIDs.remove(key)
print(f"{len(steamIDs)} games left")
except:
print("Crying is a free action")