Put it in a function

This commit is contained in:
jeancf 2023-06-13 17:28:05 +02:00
parent 17bbcb7372
commit 3583186d3f
2 changed files with 17 additions and 12 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.idea/ .idea/
.vscode/ .vscode/
venv/ venv/
__pycache__/
*.secret *.secret
*.sh *.sh
*.log *.log

View File

@ -169,6 +169,16 @@ def build_config(args):
print('CRITICAL: Missing Mastodon user') print('CRITICAL: Missing Mastodon user')
terminate(-1) terminate(-1)
def update_profile(TOML, soup, db, mast_password):
# Extract avatar picture address
avatar_url = 'https://' + unquote(soup.find('div', class_='profile-card-info').findChild('a').findChild('img').get('src').removeprefix('/pic/'))
# Extract banner picture address
banner_url = unquote(soup.find('div', class_='profile-banner').findChild('a').findChild('img').get('src').removeprefix('/pic/'))
mastodon_account = TOML['config']['mastodon_user']
exit()
def deredir_url(url): def deredir_url(url):
""" """
@ -750,22 +760,16 @@ def main(argv):
logging.debug('Nitter page downloaded successfully from ' + url) logging.debug('Nitter page downloaded successfully from ' + url)
# DEBUG: Save page to file # DEBUG: Save page to file
of = open(TOML['config']['twitter_account'] + '.html', 'w') # of = open(TOML['config']['twitter_account'] + '.html', 'w')
of.write(twit_account_page.text) # of.write(twit_account_page.text)
of.close() # of.close()
# Make soup # Make soup
soup = BeautifulSoup(twit_account_page.text, 'html.parser') soup = BeautifulSoup(twit_account_page.text, 'html.parser')
# Extract avatar picture address # Update profile if it has changed
avatar = 'https://' + unquote(soup.find('div', class_='profile-card-info').findChild('a').findChild('img').get('src').removeprefix('/pic/')) # TODO Make conditional to TOML option
update_profile(TOML, soup, db, mast_password)
# Extract banner picture address
banner = unquote(soup.find('div', class_='profile-banner').findChild('a').findChild('img').get('src').removeprefix('/pic/'))
print(avatar)
print(banner)
exit(0)
# Extract twitter timeline # Extract twitter timeline
timeline = soup.find_all('div', class_='timeline-item') timeline = soup.find_all('div', class_='timeline-item')