diff --git a/app/models.py b/app/models.py index ece47a9e..d85a8881 100644 --- a/app/models.py +++ b/app/models.py @@ -678,6 +678,25 @@ class EditRequestChange(db.Model): else: setattr(package, self.key.name, self.newValue) + + +class KrockForumTopic(db.Model): + topic_id = db.Column(db.Integer, primary_key=True, autoincrement=False) + author_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) + author = db.relationship("User") + + ttype = db.Column(db.Integer, nullable=False) + title = db.Column(db.String(200), nullable=False) + name = db.Column(db.String(30), nullable=True) + link = db.Column(db.String(50), nullable=True) + + def getType(self): + if self.ttype == 1 or self.ttype == 2: + return PackageType.MOD + elif self.ttype == 6: + return PackageType.GAME + + # Setup Flask-User db_adapter = SQLAlchemyAdapter(db, User) # Register the User model user_manager = UserManager(db_adapter, app) # Initialize Flask-User diff --git a/app/tasks/forumtasks.py b/app/tasks/forumtasks.py index df8dbb8f..a0339b00 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() diff --git a/app/templates/admin/list.html b/app/templates/admin/list.html index ff422bad..e5049f90 100644 --- a/app/templates/admin/list.html +++ b/app/templates/admin/list.html @@ -18,6 +18,7 @@