mirror of
https://gitlab.com/jeancf/twoot.git
synced 2024-11-23 20:11:11 +00:00
Going with update_profile() only
This commit is contained in:
parent
d021b20d81
commit
bf0797a002
43
twoot.py
43
twoot.py
|
@ -169,43 +169,44 @@ def build_config(args):
|
|||
print('CRITICAL: Missing Mastodon user')
|
||||
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 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
|
||||
new_avatar_url = 'https://' + unquote(soup.find('div', class_='profile-card-info').findChild('a').findChild('img').get('src').removeprefix('/pic/'))
|
||||
|
||||
# Extract banner picture address
|
||||
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'],))
|
||||
profile_in_db = db.fetchone()
|
||||
|
||||
if profile_in_db is not None:
|
||||
cur_avatar_url = profile_in_db[0]
|
||||
cur_banner_url = profile_in_db[1]
|
||||
|
||||
# Check if urls have changed
|
||||
if new_avatar_url!= cur_avatar_url or new_banner_url!= cur_banner_url:
|
||||
return new_avatar_url, new_banner_url
|
||||
else:
|
||||
return None
|
||||
if new_avatar_url == cur_avatar_url:
|
||||
new_avatar_url = None
|
||||
if new_banner_url == cur_banner_url:
|
||||
new_banner_url = None
|
||||
|
||||
# If profile was not found in db, return urls
|
||||
return new_avatar_url, new_banner_url
|
||||
mastodon = None
|
||||
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):
|
||||
"""
|
||||
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
|
||||
return mastodon
|
||||
|
||||
def deredir_url(url):
|
||||
"""
|
||||
|
@ -966,9 +967,7 @@ def main(argv):
|
|||
mastodon = None
|
||||
|
||||
# Update profile if it has changed
|
||||
if profile_has_changed(soup, db) is not None:
|
||||
mastodon = login(mast_password)
|
||||
update_profile()
|
||||
mastodon = update_profile(soup, db, mast_password)
|
||||
|
||||
# Login to account on maston instance
|
||||
if len(tweets) != 0 and mastodon is None:
|
||||
|
|
Loading…
Reference in New Issue
Block a user