1
+ #!/usr/bin/env python
2
+
1
3
import sys
2
4
import json
3
5
import time
4
6
import urllib .request
7
+ import urllib .parse
5
8
import re
6
9
7
10
HOST = "http://api.steampowered.com"
11
14
DELAY = 0.1 # How long to delay between requests
12
15
FILENAME = "addons.txt"
13
16
14
- ignore_words = ["content" , "server" ]
17
+ # Not a whole word search, so nav also gets navmesh
18
+ ignore_words = [
19
+ "content" ,
20
+ "server" ,
21
+ "nav" ,
22
+ "node" ,
23
+ "icon"
24
+ ]
25
+
15
26
ignore_reg = "(?<!_){0}(?!_)" # Allow ignore words to be a part of the map name (surrounding underscores)
16
27
def containsIgnoreWord (str , word ):
17
- return re .search (ignore_reg .format (word ), str ) is not None
28
+ return re .search (ignore_reg .format (word ), str , flags = re . IGNORECASE ) is not None
18
29
19
30
def containsIgnoreWords (str ):
20
31
for word in ignore_words :
21
32
if containsIgnoreWord (str , word ):
22
33
return True
23
-
34
+
24
35
return False
25
36
26
37
if __name__ == "__main__" :
@@ -38,14 +49,20 @@ def containsIgnoreWords(str):
38
49
39
50
f = open (FILENAME , "w" )
40
51
41
- while True :
42
- req = "{0}/{1}?key={2}&appid={3}&requiredtags[0]=map&numperpage={4}&page={5}&return_metadata=1&query_type=1" .format (HOST , ENDPOINT , key , APPID , NUMPERPAGE , page )
43
- response = urllib .request .urlopen (req ).read ()
44
- resobj = json .loads (response .decode ("utf-8" , "ignore" ))
45
- total = resobj ["response" ]["total" ]
46
-
47
- for addon in resobj ["response" ]["publishedfiledetails" ]:
48
- if "title" in addon and containsIgnoreWords (addon ["title" ]):
52
+ cursor = "*"
53
+ last_cursor = None
54
+ while cursor != None and cursor != last_cursor :
55
+ req = "{0}/{1}?key={2}&appid={3}&requiredtags[0]=map&numperpage={4}&cursor={5}&return_metadata=1&query_type=1" .format (HOST , ENDPOINT , key , APPID , NUMPERPAGE , urllib .parse .quote_plus (cursor ))
56
+ response_data = urllib .request .urlopen (req ).read ()
57
+ response = json .loads (response_data .decode ("utf-8" , "ignore" ))["response" ]
58
+ total = response ["total" ]
59
+ last_cursor = cursor
60
+ cursor = response ["next_cursor" ]
61
+
62
+ for addon in response ["publishedfiledetails" ]:
63
+ hasignorewords = "title" in addon and containsIgnoreWords (addon ["title" ])
64
+ sexyfuntimes = "maybe_inappropriate_sex" in addon and addon ["maybe_inappropriate_sex" ] == True
65
+ if hasignorewords or sexyfuntimes :
49
66
ign_str = u"Ignoring: " + addon ["title" ]
50
67
print (ign_str .encode ('utf-8' ))
51
68
continue
@@ -56,18 +73,18 @@ def containsIgnoreWords(str):
56
73
workshopids .append (wsid )
57
74
58
75
# Informative output
59
- finished = page * NUMPERPAGE + len (resobj [ " response" ] ["publishedfiledetails" ])
76
+ finished = page * NUMPERPAGE + len (response ["publishedfiledetails" ])
60
77
print ("Finished {0} addons. ({1:.2f}% of {2})" .format (finished , finished * 100.0 / total , total ))
61
78
62
79
# Move onto to the next page
63
80
page += 1
64
81
65
- if page * NUMPERPAGE > resobj [ " response" ] ["total" ]:
82
+ if page * NUMPERPAGE > response ["total" ]:
66
83
break
67
- else :
84
+ else :
68
85
# so valve doesn't get angry at us
69
86
time .sleep (DELAY )
70
-
87
+
71
88
# Results come back sorted, but reverse it so
72
89
# newer entries are added at the end instead of shifting everything at the beginning
73
90
workshopids .reverse ()
@@ -78,4 +95,3 @@ def containsIgnoreWords(str):
78
95
79
96
print ("Finished!!" )
80
97
f .close ()
81
-
0 commit comments