-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriend_crawler.py
54 lines (43 loc) · 2.01 KB
/
friend_crawler.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
import time
import tracemalloc
from steam_pyp.steam import Steam
from steam_pyp.utilities import read_steam_key
if __name__ == "__main__":
# Start utilities
tracemalloc.start()
start_time = time.time()
# Initialize SteamAPI with our steam api key
steam = Steam(key=read_steam_key("steam.key"), return_format="json")
steam_id = '76561199223184522' # Must have a public friend list
friends = steam.player_friends(steam_id=[steam_id], relationship="all")['friendslist']['friends']
friends_dict = {}
for i in friends:
if i['steamid'] not in friends_dict:
try:
friends_dict.update({i['steamid']: steam.player_friends(steam_id=[i['steamid']], relationship="all")[
'friendslist']['friends']})
print("Added ", i['steamid'], len(friends_dict))
except KeyError:
friends_dict.update({i['steamid']: None})
for _ in range(0, 1):
new_dict = {}
for i in friends_dict.keys():
if friends_dict[i] is not None:
for j in friends_dict[i]:
if j['steamid'] not in friends_dict and j['steamid'] not in new_dict:
try:
new_dict.update({j['steamid']:
steam.player_friends(steam_id=[j['steamid']], relationship="all")[
'friendslist']['friends']})
print("Added ", j['steamid'], len(friends_dict) + len(new_dict))
except KeyError:
new_dict.update({j['steamid']: None})
friends_dict.update(new_dict)
print(len(friends_dict))
print("Done!")
# Initialize a user
print("Steam API calls: ", steam.api_calls)
tracemalloc.stop()
print(f"Project takes up approximately {tracemalloc.get_traced_memory()[1] / 1000000} MB of memory.")
# Print time spent
print(f"Time spent: {time.time() - start_time}")