-
Notifications
You must be signed in to change notification settings - Fork 1
/
API_games.py
59 lines (51 loc) · 2.03 KB
/
API_games.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
'''
Koodissa haetaan Steam Web APIn kautta käyttäjien steamID:t ja heidän käyttäjännimensä, jotka yhdistetään kirjastoksi.
'''
import pandas as pd
import requests
import util
import json
import csv
import sys
def write_to_node_csv(data):
# TBD dialect
with open('gamesID_network.csv', 'w', encoding="utf-8") as f:
nodewriter = csv.writer(f, delimiter=' ', quoting=csv.QUOTE_NONNUMERIC)
nodewriter.writerows(data)
#API-key:n haku ja sijoittaminen
def main():
from_to = []
config = util.load_config()
with open(config["steam_ids"]["results"], 'r') as f:
results_json = json.load(f)
keys = [n for n in results_json.keys()]
steamids = results_json[keys[0]]
print("Closing config...")
api_key = config['steam_api_key']['key']
steam_data = []
print("Starting to iterate...")
for i in range(10):
steamid = steamids[i]
#Web API osoitteet, joista voidaan hakea tietoa
api_getownedgames = 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v001/?key={}&steamid={}&format=json&include_appinfo=1&include_played_free_games=1'.format(api_key, steamid)
#Haetaan webistä steamID:n käyttäjän kaverit listaan steamIDs
print(f'Making request with: {api_getownedgames}')
try:
r = requests.get(api_getownedgames)
data = r.json()
game_nodes = [s for s in data['response']['games']]
gameIDs = [n['name'] for n in game_nodes]
print(steamid)
from_to = [n for n in gameIDs]
for node in from_to:
steam_data.append([int(steamid), node])
'''
OBS! Not sure if this works in gephi, as it saves game names (str). If 'name' from row 42 changed to
'appid' it gives a int, which works with gephi
'''
except KeyError:
print("Failed request, KeyError")
continue
write_to_node_csv(steam_data)
return 0
main()