-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_call.py
156 lines (104 loc) · 4.24 KB
/
api_call.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
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 26 13:05:51 2022
@author: avanjavakam
"""
# code to save all data to a single file
import pandas as pd
import glob
path = './*.json'
files = glob.glob(path)
data_frames = []
for file in files:
f = open(file, 'r', encoding="utf8")
data_frames.append(pd.read_json(f))
f.close()
pd.concat(data_frames).to_csv("data.csv")
with open('platforms.json', encoding='utf8') as f_input:
df = pd.read_json(f_input)
df.to_csv('platforms.csv', encoding='utf-8', index=False)
with open('involved_companies.json', encoding='utf8') as f_input:
df = pd.read_json(f_input)
df.to_csv('involved_companies.csv', encoding='utf-8', index=False)
with open('player_perspectives.json', encoding='utf8') as f_input:
df = pd.read_json(f_input)
df.to_csv('player_perspectives.csv', encoding='utf-8', index=False)
with open('themes.json', encoding='utf8') as f_input:
df = pd.read_json(f_input)
df.to_csv('themes.csv', encoding='utf-8', index=False)
from igdb.wrapper import IGDBWrapper
wrapper = IGDBWrapper("xxxxx", "xxxxx")
#querying game data. This is the dataset I will be using for analysis.
for i in range(0, 210000, 500):
'''With a wrapper instance already created'''
# JSON API request
byte_array = wrapper.api_request(
'games',
'fields age_ratings,aggregated_rating,aggregated_rating_count,category,created_at,dlcs,expanded_games,expansions,external_games,first_release_date,follows,forks,franchise,franchises,game_engines,game_modes,genres,hypes,involved_companies,multiplayer_modes,name,parent_game,platforms,player_perspectives,ports,rating,rating_count,release_dates,remakes,remasters,screenshots,similar_games,slug,standalone_expansions,status,storyline,summary,tags,themes,total_rating,total_rating_count,updated_at,url,version_parent,version_title,videos,websites; limit 500; offset' + str(i) + ';'
)
data = json.loads(byte_array)
data_1 = pd.json_normalize(data)
data_frames.append(pd.DataFrame(data_1))
pd.concat(data_frames).to_csv("data_200K.csv")
# querying genres mappings
data_frames = []
'''With a wrapper instance already created'''
# JSON API request
byte_array = wrapper.api_request(
'genres',
'fields *; limit 500;'
)
df = pd.read_json(byte_array)
df.to_csv('genres.csv', encoding='utf-8', index=False)
# querying companies mappings
data_frames = []
for i in range(0, 50000, 500):
'''With a wrapper instance already created'''
# JSON API request
byte_array = wrapper.api_request(
'companies',
'fields *; limit 500; offset' + str(i) + ';'
)
data = json.loads(byte_array)
data = pd.json_normalize(data)
data_frames.append(pd.DataFrame(data))
pd.concat(data_frames).to_csv("companies.csv")
# querying involved_companies mappings
data_frames = []
for i in range(0, 200000, 500):
'''With a wrapper instance already created'''
# JSON API request
byte_array = wrapper.api_request(
'involved_companies',
'fields *; limit 500; offset' + str(i) + ';'
)
data = json.loads(byte_array)
data = pd.json_normalize(data)
data_frames.append(pd.DataFrame(data))
pd.concat(data_frames).to_csv("involved_companies.csv")
# querying age_ratings mappings
data_frames = []
for i in range(0, 200000, 500):
'''With a wrapper instance already created'''
# JSON API request
byte_array = wrapper.api_request(
'age_ratings',
'fields *; limit 500; offset' + str(i) + ';'
)
data = json.loads(byte_array)
data = pd.json_normalize(data)
data_frames.append(pd.DataFrame(data))
pd.concat(data_frames).to_csv("age_ratings.csv")
#age_rating_content_descriptions
data_frames = []
for i in range(0, 100000, 500):
'''With a wrapper instance already created'''
# JSON API request
byte_array = wrapper.api_request(
'age_rating_content_descriptions',
'fields *; limit 500; offset' + str(i) + ';'
)
data = json.loads(byte_array)
data = pd.json_normalize(data)
data_frames.append(pd.DataFrame(data))
pd.concat(data_frames).to_csv("age_rating_content_descriptions.csv")