summaryrefslogtreecommitdiff
path: root/steamrelationships
diff options
context:
space:
mode:
Diffstat (limited to 'steamrelationships')
-rw-r--r--steamrelationships/sr.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/steamrelationships/sr.py b/steamrelationships/sr.py
new file mode 100644
index 0000000..3943770
--- /dev/null
+++ b/steamrelationships/sr.py
@@ -0,0 +1,45 @@
1import requests
2import json
3
4class SteamRelationships:
5 session = requests.Session()
6 scanlist = []
7
8 def __init__(self, webapikey, recursion=3, timeout=30) -> None:
9 self.webapikey = webapikey
10 self.recursion = recursion
11 self.timeout = timeout
12
13 def _getFriendsList(self, steamid64 = None) -> dict:
14 # example url: http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamid=76561197960435530&relationship=friend
15 if not steamid64:
16 print("Requested id must not be blank")
17 return
18
19 # Format url and make a request
20 url = "https://api.steampowered.com/ISteamUser/GetFriendList/v0001/"
21 options = {"key": self.webapikey, "steamid": steamid64, "relationship": "friend"}
22 response = self.session.get(url, params=options, timeout=self.timeout) # GET should be as secure as POST because ssl is being used
23
24 # TODO: Implement proper error checking so that this doesn't just break if someone has a private friends list
25 response.raise_for_status()
26 return response.json()
27
28 def parseFriendsList(self, steamid64 = None) -> list:
29 # Retrieve a user's friends list
30 friendslist = self._getFriendsList(steamid64)
31
32 final = []
33 for friend in friendslist['friendslist']['friends']:
34 final.append(friend['steamid'])
35
36 return final
37
38 def recurse(self, startid = None) -> list:
39 self.scanlist = self.parseFriendsList(startid) # initialize scanlist
40 templist = []
41
42 for friend in self.scanlist:
43 templist.append(self.parseFriendsList(friend))
44
45 return templist \ No newline at end of file