Going with update_profile() only

This commit is contained in:
jeancf 2023-06-14 16:49:15 +02:00
parent d021b20d81
commit bf0797a002

View File

@ -169,43 +169,44 @@ def build_config(args):
print('CRITICAL: Missing Mastodon user') print('CRITICAL: Missing Mastodon user')
terminate(-1) terminate(-1)
def profile_has_changed(soup, db):
def update_profile(soup, db, mast_password):
""" """
Check if the profile has changed since the last time we checked Update the profile on Mastodon
:param soup: BeautifulSoup object containing the page :param soup: BeautifulSoup object containing the page
:param db: database object :param db: database object
:return: None if no change, tuple of new avatar and banner URLs if changed :param mast_password: <PASSWORD>
:return: mastodon object we had to login to update, None otherwise
""" """
# TODO Check if TOML option to update profile is set
# Extract avatar picture address # Extract avatar picture address
new_avatar_url = 'https://' + unquote(soup.find('div', class_='profile-card-info').findChild('a').findChild('img').get('src').removeprefix('/pic/')) new_avatar_url = 'https://' + unquote(soup.find('div', class_='profile-card-info').findChild('a').findChild('img').get('src').removeprefix('/pic/'))
# Extract banner picture address # Extract banner picture address
new_banner_url = unquote(soup.find('div', class_='profile-banner').findChild('a').findChild('img').get('src').removeprefix('/pic/')) new_banner_url = unquote(soup.find('div', class_='profile-banner').findChild('a').findChild('img').get('src').removeprefix('/pic/'))
# Get the original urls of the avatar and banner pictures on the account profile
db.execute("SELECT avatar_url, banner_url FROM profiles WHERE mastodon_account=?", (TOML['config']['mastodon_user'],)) db.execute("SELECT avatar_url, banner_url FROM profiles WHERE mastodon_account=?", (TOML['config']['mastodon_user'],))
profile_in_db = db.fetchone() profile_in_db = db.fetchone()
if profile_in_db is not None: if profile_in_db is not None:
cur_avatar_url = profile_in_db[0] cur_avatar_url = profile_in_db[0]
cur_banner_url = profile_in_db[1] cur_banner_url = profile_in_db[1]
# Check if urls have changed # Check if urls have changed
if new_avatar_url!= cur_avatar_url or new_banner_url!= cur_banner_url: if new_avatar_url == cur_avatar_url:
return new_avatar_url, new_banner_url new_avatar_url = None
else: if new_banner_url == cur_banner_url:
return None new_banner_url = None
# If profile was not found in db, return urls mastodon = None
return new_avatar_url, new_banner_url if new_avatar_url is not None or new_banner_url is not None:
mastodon = login(mast_password)
# TODO update profile on Mastodon
# TODO update database
def update_profile(mastodon, avatar_url, banner_url, db): return mastodon
"""
Update the profile of the Mastodon account
:param mastodon: Mastodon object
:param avatar_url: URL of the new avatar picture
:param banner_url: URL of the new banner picture
:param db: database object
:return:
"""
pass
def deredir_url(url): def deredir_url(url):
""" """
@ -966,9 +967,7 @@ def main(argv):
mastodon = None mastodon = None
# Update profile if it has changed # Update profile if it has changed
if profile_has_changed(soup, db) is not None: mastodon = update_profile(soup, db, mast_password)
mastodon = login(mast_password)
update_profile()
# Login to account on maston instance # Login to account on maston instance
if len(tweets) != 0 and mastodon is None: if len(tweets) != 0 and mastodon is None: