diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-15 15:00:12 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-15 15:00:12 +0100 |
commit | 0bdcbd741c32c7d6a85b16a24968df00d9cb0584 (patch) | |
tree | 1e0fa9931d6eb94bf0fef264fb8fa3301599268b /app/tasks/forumtasks.py | |
parent | e669b18062c6282a8787a48d996811d198cf88f4 (diff) | |
download | cheatdb-0bdcbd741c32c7d6a85b16a24968df00d9cb0584.tar.xz |
Add import users from Krock's mod list feature
Diffstat (limited to 'app/tasks/forumtasks.py')
-rw-r--r-- | app/tasks/forumtasks.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/app/tasks/forumtasks.py b/app/tasks/forumtasks.py index e4ddc59..27d90e7 100644 --- a/app/tasks/forumtasks.py +++ b/app/tasks/forumtasks.py @@ -1,9 +1,11 @@ -import flask +import flask, json from flask.ext.sqlalchemy import SQLAlchemy from app import app from app.models import * from app.tasks import celery from .phpbbparser import getProfile +import urllib.request +from urllib.parse import urlparse, quote_plus @celery.task() def checkForumAccount(username, token=None): @@ -24,10 +26,35 @@ def checkForumAccount(username, token=None): # Get github username github_username = profile.get("github") if github_username is not None and github_username.strip() != "": - print("Updated github username") + print("Updated github username for " + user.display_name + " to " + github_username) user.github_username = github_username needsSaving = True # Save if needsSaving: db.session.commit() + +@celery.task() +def importUsersFromModList(): + contents = urllib.request.urlopen("http://krock-works.16mb.com/MTstuff/modList.php").read().decode("utf-8") + list = json.loads(contents) + found = {} + imported = [] + + for user in User.query.all(): + found[user.username] = True + if user.forums_username is not None: + found[user.forums_username] = True + + for x in list: + author = x.get("author") + if author is not None and not author in found: + user = User(author) + user.forums_username = author + imported.append(author) + found[author] = True + db.session.add(user) + + db.session.commit() + for author in found: + checkForumAccount.delay(author, None) |