aboutsummaryrefslogtreecommitdiff
path: root/app/tasks/forumtasks.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-06-02 18:22:57 +0100
committerrubenwardy <rw@rubenwardy.com>2018-06-02 18:26:17 +0100
commit70afb94d3b985e314ff1f922294875e43c56fefc (patch)
tree6743df30af1b00f5ed457155bbca0724f639c97d /app/tasks/forumtasks.py
parent8984adaa728c6c1c9bafb8c1ba5ea227bb17aa5b (diff)
downloadcheatdb-70afb94d3b985e314ff1f922294875e43c56fefc.tar.xz
Add topics todo list based on forum parser
Diffstat (limited to 'app/tasks/forumtasks.py')
-rw-r--r--app/tasks/forumtasks.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/app/tasks/forumtasks.py b/app/tasks/forumtasks.py
index df8dbb8..a0339b0 100644
--- a/app/tasks/forumtasks.py
+++ b/app/tasks/forumtasks.py
@@ -75,3 +75,47 @@ def importUsersFromModList():
db.session.commit()
for author in found:
checkForumAccount.delay(author, None)
+
+
+BANNED_NAMES = ["mod", "game", "old", "outdated", "wip", "api"]
+ALLOWED_TYPES = [1, 2, 6]
+
+@celery.task()
+def importKrocksModList():
+ contents = urllib.request.urlopen("http://krock-works.16mb.com/MTstuff/modList.php").read().decode("utf-8")
+ list = json.loads(contents)
+ username_to_user = {}
+
+ KrockForumTopic.query.delete()
+
+ for x in list:
+ type = int(x["type"])
+ if not type in ALLOWED_TYPES:
+ continue
+
+ username = x["author"]
+ user = username_to_user.get(username)
+ if user is None:
+ user = User.query.filter_by(forums_username=username).first()
+ assert(user is not None)
+ username_to_user[username] = user
+
+ import re
+ tags = re.findall("\[([a-z0-9_]+)\]", x["title"])
+ name = None
+ for tag in reversed(tags):
+ if len(tag) < 50 and not tag in BANNED_NAMES and \
+ not re.match("^([a-z][0-9]+)$", tag):
+ name = tag
+ break
+
+ topic = KrockForumTopic()
+ topic.topic_id = x["topicId"]
+ topic.author_id = user.id
+ topic.ttype = type
+ topic.title = x["title"]
+ topic.name = name
+ topic.link = x.get("link")
+ db.session.add(topic)
+
+ db.session.commit()