summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--README.md6
-rw-r--r--steamrelationships/sr.py45
3 files changed, 53 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8d69a6f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
1__pycache__
2main.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 @@
5Ever 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 5Ever 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
6 6
7Steam 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 7Steam 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
8
9## REQUIREMENTS
10
111. A [Steam DevAPI key](https://steamcommunity.com/dev/apikey)
12
13## 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 @@
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