Add support for using forum profile pictures
This commit is contained in:
@@ -25,7 +25,7 @@ import urllib.request
|
||||
from urllib.parse import urlparse, quote_plus
|
||||
|
||||
@celery.task()
|
||||
def checkForumAccount(username, token=None):
|
||||
def checkForumAccount(username):
|
||||
try:
|
||||
profile = getProfile("https://forum.minetest.net", username)
|
||||
except OSError:
|
||||
@@ -47,6 +47,10 @@ def checkForumAccount(username, token=None):
|
||||
user.github_username = github_username
|
||||
needsSaving = True
|
||||
|
||||
pic = profile.avatar
|
||||
needsSaving = needsSaving or pic != user.profile_pic
|
||||
user.profile_pic = pic
|
||||
|
||||
# Save
|
||||
if needsSaving:
|
||||
db.session.commit()
|
||||
|
||||
@@ -15,8 +15,9 @@ def urlEncodeNonAscii(b):
|
||||
|
||||
class Profile:
|
||||
def __init__(self, username):
|
||||
self.username = username
|
||||
self.signature = ""
|
||||
self.username = username
|
||||
self.signature = ""
|
||||
self.avatar = None
|
||||
self.properties = {}
|
||||
|
||||
def set(self, key, value):
|
||||
@@ -33,6 +34,11 @@ def __extract_properties(profile, soup):
|
||||
if el is None:
|
||||
return None
|
||||
|
||||
res1 = el.find_all("dl")
|
||||
imgs = res1[0].find_all("img")
|
||||
if len(imgs) == 1:
|
||||
profile.avatar = imgs[0]["src"]
|
||||
|
||||
res = el.find_all("dl", class_ = "left-box details")
|
||||
if len(res) != 1:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user