From 56bcf6615a51989dfbe4c7dbbb2d03b4af5f32fb Mon Sep 17 00:00:00 2001 From: NW/RL Date: Tue, 2 Apr 2024 00:59:24 -0500 Subject: Get a basic recursive scan working --- steamrelationships/sr.py | 63 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'steamrelationships') diff --git a/steamrelationships/sr.py b/steamrelationships/sr.py index d5b63e1..4bad716 100644 --- a/steamrelationships/sr.py +++ b/steamrelationships/sr.py @@ -7,7 +7,7 @@ CONST = _Const() class SteamRelationships: session: object = requests.Session() # Session object so repeated querries to steam's api use the same TCP connection - scanlist: list = [] # To be populated by recurse() + scanlist: dict = {} # To be populated by recursivescan() reqjson: str = "requests.json" # Path to the JSON file that handles requests def __init__(self, webapikey: str, timeout: int = 30, timeout_retries: int = 5, reqdelay: float = 0.5, delayrand: float = 1.25, reqsafetybuffer: float = 0.9, reqjson: str = "requests.json") -> None: @@ -146,7 +146,7 @@ class SteamRelationships: # Error out on request error if result.status_code != requests.codes.ok: - print("[_getFriendsList] Got bad status code") + print(f"[_getFriendsList] Got bad status code (Requested id: {steamid64}, status: {result.status_code})") return {} # Get the json contents from the response @@ -182,4 +182,61 @@ class SteamRelationships: return people def basicscan(self, steamid64: str) -> dict: - return {steamid64: self._parseFriendsList(self._getFriendsList(steamid64))} \ No newline at end of file + ''' + basicscan - do a basic scan of someone's steam friends + + PARAMS: + (str) steamid64 - The 64 bit steam id of the user you want to scan + + RETURN VALUES: + (dict) EMPTY - There was an error scanning the user's friends list + (dict) {steamid64: [friendID1, friendID2, ...]} - A dict with a single key, that of the scanned user, which maps to a list of the users's friends + + ''' + return {steamid64: self._parseFriendsList(self._getFriendsList(steamid64))} + + def recursivescan(self, steamid64: str, recurselevel: int = 2) -> dict: + ''' + recursivescan - Scan a user's friends list, then scan their friends as well + + PARAMS: + (str) steamid64 - The starting user to scan + (int) recurselevel - The number of recursive scans to complete + + RETURN VALUES: + (dict) EMPTY - Some catastrophic error has occured and no scan could be started + (dict) { + steamid64: + [friend1id, friend2id, friend3id, ...], + friend1id: + [other_friend, other_friend, ...], + friend2id: + [other_friend, other_friend, ...], + ... + } + + - A dict containing the starting steamid, then the friends contained in the original scan with the results of their scan + + NOTE: + Please do not use a value greater than 3. While theoretically any value works, due to the exponential + nature of friendship relations, you will very quickly spam Steam with tens of thousands of requests. + If this concept is unfamiliar to you, please take a quick glance at the Wikipedia page for + "six degress of separation": https://en.wikipedia.org/wiki/Six_degrees_of_separation + ''' + + testlist: dict = self.basicscan(steamid64) + alreadyscanned: list = [steamid64] + + for i in range(recurselevel): + tempdict: dict = {} + for person in testlist: + for friend in testlist[person]: + if friend not in alreadyscanned: + tempdict.update(self.basicscan(friend)) + alreadyscanned.append(friend) + + testlist.update(tempdict) + tempdict.clear() + + self.scanlist.update(testlist) + return testlist \ No newline at end of file -- cgit v1.2.3