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 --- .gitignore | 2 ++ README.md | 6 ++++++ steamrelationships/sr.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 .gitignore create mode 100644 steamrelationships/sr.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d69a6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +main.py \ No newline at end of file diff --git a/README.md b/README.md index 216c0bf..3a8ba06 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,9 @@ Ever ran into a cheater, looked at their profile, and realized all their friends are cheaters too? I have, and this tool is a way to measure degrees of separation from a specific individual Steam Relationships querries the Steam WebAPI to get public friends lists, and then recursively search those friend lists as well. This process repeats until a certain number of "degrees" have been met (a set recursion level specified by the user). The results of these querries are put in a database that can then be shared and used for other purposes + +## REQUIREMENTS + +1. A [Steam DevAPI key](https://steamcommunity.com/dev/apikey) + +## USAGE 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