-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkingWithSteamAPI.py
151 lines (124 loc) · 3.71 KB
/
WorkingWithSteamAPI.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
import requests
import pandas as pd
import sys
import math
import time
pd.options.mode.chained_assignment = None # default='warn'
api_key = 0
r = requests.get(f"http://api.steampowered.com/ISteamApps/GetAppList/v0002/?key={api_key}&format=json")
games = r.json()["applist"]["apps"]
#store.steampowered.com/appreviews/<appid>?json=1
#https://store.steampowered.com/api/appdetails?appids=<appid>
#(pd.DataFrame.from_dict(games)).to_csv("games_fresh")
#df = pd.DataFrame.from_dict(games)
#dfCopy = df
#testDF = df.tail(10)
df = pd.read_csv("fullSteamV4.csv")
def getReviewInfo(appid):
r = requests.get(f"http://store.steampowered.com/appreviews/{appid}?json=1")
try:
review_info = r.json()["query_summary"]
del review_info["num_reviews"]
return review_info
except:
return
def getGameInfo(appid):
game_info = {}
r = requests.get(f"https://store.steampowered.com/api/appdetails?appids={appid}")
success = r.json()[str(appid)]["success"]
try:
data = r.json()[str(appid)]["data"]
except:
pass
#Add success
game_info["success"] = success
#Add isfree
try:
is_free = data["is_free"]
game_info["is_free"] = is_free
except:
pass
#Add price data
try:
price = data["price_overview"]["final_formatted"]
game_info["price"] = price
except:
pass
#Add release date
try:
release_date = data["release_date"]["date"]
game_info["release_date"] = release_date
except:
pass
#Add genre data
try:
genres = []
for i in data["genres"]:
genres.append(i["description"])
genres = ", ".join(genres)
game_info["genres"] = genres
except:
pass
#Add category data
try:
tags = []
for i in data["categories"]:
tags.append(i["description"])
tags = ", ".join(tags)
game_info["tags"] = tags
except:
pass
#Add developers (IF MULTIPLE, THEN IT IS JOINED BY " & ")
try:
developers = data["developers"]
developers = " & ".join(developers)
game_info["developers"] = developers
except:
pass
#Add publishers (IF MULTIPLE, THEN IT IS JOINED BY " & ")
try:
publishers = data["publishers"]
publishers = " & ".join(publishers)
game_info["publishers"] = publishers
except:
pass
#Add short_description
try:
short_description = data["short_description"]
game_info["short_description"] = short_description
except:
pass
#Add metacritic score
try:
metacritic = data["metacritic"]["score"]
game_info["metacritic_score"] = metacritic
except:
pass
return game_info
def addInfo(df, index, dictInfo):
for k,v in dictInfo.items():
df.at[index, k] = v
#df[index]
def extract(csvname):
i = 1
for index, row in df.iterrows():
if math.isnan(df.at[index, "success"]):
print(str(index) + " out of " + str(len(df)))
i = i+1
if i % 200 == 0:
print("Waiting 1,5 minutes! (API Throttle Limit)")
time.sleep(90)
try:
review_info = getReviewInfo(row["appid"])
game_info = getGameInfo(row["appid"])
addInfo(df, index, game_info)
if review_info is not None:
addInfo(df, index, review_info)
if i % 20 == 0:
df.to_csv(csvname+".csv", index = False)
except:
print(sys.exc_info()[0])
continue
df.to_csv(csvname + ".csv", index = False)
#extract(df, "fullSteamV4")
#extract(testDF, "newTest")