Add task to bulk import avatars from forum

This commit is contained in:
rubenwardy
2018-12-25 19:49:17 +00:00
parent 21960f2404
commit 0b83d2f2b5
4 changed files with 24 additions and 5 deletions

View File

@@ -25,7 +25,8 @@ import urllib.request
from urllib.parse import urlparse, quote_plus
@celery.task()
def checkForumAccount(username):
def checkForumAccount(username, forceNoSave=False):
print("Checking " + username)
try:
profile = getProfile("https://forum.minetest.net", username)
except OSError:
@@ -52,9 +53,23 @@ def checkForumAccount(username):
user.profile_pic = pic
# Save
if needsSaving:
if needsSaving and not forceNoSave:
db.session.commit()
return needsSaving
@celery.task()
def checkAllForumAccounts(forceNoSave=False):
needsSaving = False
query = User.query.filter(User.forums_username.isnot(None))
for user in query.all():
needsSaving = checkForumAccount(user.username) or needsSaving
if needsSaving and not forceNoSave:
db.session.commit()
return needsSaving
regex_tag = re.compile(r"\[([a-z0-9_]+)\]")
BANNED_NAMES = ["mod", "game", "old", "outdated", "wip", "api", "beta", "alpha", "git"]