From 6e145dcfbb36f68ff014aa85ec4304a7e8adc176 Mon Sep 17 00:00:00 2001 From: NW/RL Date: Mon, 11 Mar 2024 00:17:46 -0500 Subject: Hammer out the basics --- steamrelationships/sr.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 steamrelationships/sr.py (limited to 'steamrelationships') 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 @@ +import requests +import json + +class SteamRelationships: + session = requests.Session() + scanlist = [] + + def __init__(self, webapikey, recursion=3, timeout=30) -> None: + self.webapikey = webapikey + self.recursion = recursion + self.timeout = timeout + + def _getFriendsList(self, steamid64 = None) -> dict: + # example url: http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamid=76561197960435530&relationship=friend + if not steamid64: + print("Requested id must not be blank") + return + + # Format url and make a request + url = "https://api.steampowered.com/ISteamUser/GetFriendList/v0001/" + options = {"key": self.webapikey, "steamid": steamid64, "relationship": "friend"} + response = self.session.get(url, params=options, timeout=self.timeout) # GET should be as secure as POST because ssl is being used + + # TODO: Implement proper error checking so that this doesn't just break if someone has a private friends list + response.raise_for_status() + return response.json() + + def parseFriendsList(self, steamid64 = None) -> list: + # Retrieve a user's friends list + friendslist = self._getFriendsList(steamid64) + + final = [] + for friend in friendslist['friendslist']['friends']: + final.append(friend['steamid']) + + return final + + def recurse(self, startid = None) -> list: + self.scanlist = self.parseFriendsList(startid) # initialize scanlist + templist = [] + + for friend in self.scanlist: + templist.append(self.parseFriendsList(friend)) + + return templist \ No newline at end of file -- cgit v1.2.3