mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-23 16:38:42 +00:00
Compare commits
No commits in common. "01a944d6929e5faad074cda4605755ee8bbe3d1f" and "c87f152371e6cb222a3ab54bdad0d4ee41cc4a69" have entirely different histories.
01a944d692
...
c87f152371
47
twoot.py
47
twoot.py
@ -49,11 +49,10 @@ NITTER_URLS = [
|
|||||||
'https://nitter.lacontrevoie.fr',
|
'https://nitter.lacontrevoie.fr',
|
||||||
'https://nitter.privacydev.net',
|
'https://nitter.privacydev.net',
|
||||||
'https://nitter.fdn.fr',
|
'https://nitter.fdn.fr',
|
||||||
'https://https://nitter.namazso.eu',
|
'https://nitter.privacy.com.de',
|
||||||
'https://twitter.beparanoid.de',
|
'https://twitter.beparanoid.de',
|
||||||
'https://n.l5.ca',
|
'https://n.l5.ca',
|
||||||
'https://nitter.privacytools.io',
|
'https://nitter.bus-hit.me',
|
||||||
'https://nitter.hu',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# Update from https://www.whatismybrowser.com/guides/the-latest-user-agent/
|
# Update from https://www.whatismybrowser.com/guides/the-latest-user-agent/
|
||||||
@ -116,10 +115,10 @@ def build_config(args):
|
|||||||
loaded_toml = tomllib.load(config_file)
|
loaded_toml = tomllib.load(config_file)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print('config file not found')
|
print('config file not found')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
except tomllib.TOMLDecodeError:
|
except tomllib.TOMLDecodeError:
|
||||||
print('Malformed config file')
|
print('Malformed config file')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
|
|
||||||
TOML['config'] = loaded_toml['config']
|
TOML['config'] = loaded_toml['config']
|
||||||
for k in TOML['options'].keys():
|
for k in TOML['options'].keys():
|
||||||
@ -157,13 +156,13 @@ def build_config(args):
|
|||||||
# Verify that we have a minimum config to run
|
# Verify that we have a minimum config to run
|
||||||
if 'twitter_account' not in TOML['config'].keys() or TOML['config']['twitter_account'] == "":
|
if 'twitter_account' not in TOML['config'].keys() or TOML['config']['twitter_account'] == "":
|
||||||
print('CRITICAL: Missing Twitter account')
|
print('CRITICAL: Missing Twitter account')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
if 'mastodon_instance' not in TOML['config'].keys() or TOML['config']['mastodon_instance'] == "":
|
if 'mastodon_instance' not in TOML['config'].keys() or TOML['config']['mastodon_instance'] == "":
|
||||||
print('CRITICAL: Missing Mastodon instance')
|
print('CRITICAL: Missing Mastodon instance')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
if 'mastodon_user' not in TOML['config'].keys() or TOML['config']['mastodon_user'] == "":
|
if 'mastodon_user' not in TOML['config'].keys() or TOML['config']['mastodon_user'] == "":
|
||||||
print('CRITICAL: Missing Mastodon user')
|
print('CRITICAL: Missing Mastodon user')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
def deredir_url(url):
|
def deredir_url(url):
|
||||||
@ -488,7 +487,7 @@ def login(password):
|
|||||||
except MastodonError as me:
|
except MastodonError as me:
|
||||||
logging.fatal('failed to create app on ' + TOML['config']['mastodon_instance'])
|
logging.fatal('failed to create app on ' + TOML['config']['mastodon_instance'])
|
||||||
logging.fatal(me)
|
logging.fatal(me)
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
|
|
||||||
mastodon = None
|
mastodon = None
|
||||||
|
|
||||||
@ -510,7 +509,7 @@ def login(password):
|
|||||||
except MastodonError as me:
|
except MastodonError as me:
|
||||||
logging.fatal('Login to ' + TOML['config']['mastodon_instance'] + ' Failed\n')
|
logging.fatal('Login to ' + TOML['config']['mastodon_instance'] + ' Failed\n')
|
||||||
logging.fatal(me)
|
logging.fatal(me)
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
|
|
||||||
if os.path.isfile(TOML['config']['mastodon_user'] + '.secret'):
|
if os.path.isfile(TOML['config']['mastodon_user'] + '.secret'):
|
||||||
logging.warning('You successfully logged in using a password and an access token \
|
logging.warning('You successfully logged in using a password and an access token \
|
||||||
@ -527,28 +526,17 @@ def login(password):
|
|||||||
except MastodonError as me:
|
except MastodonError as me:
|
||||||
logging.fatal('Login to ' + TOML['config']['mastodon_instance'] + ' Failed\n')
|
logging.fatal('Login to ' + TOML['config']['mastodon_instance'] + ' Failed\n')
|
||||||
logging.fatal(me)
|
logging.fatal(me)
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
else:
|
else:
|
||||||
logging.fatal('No .secret file found. Password required to log in')
|
logging.fatal('No .secret file found. Password required to log in')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
|
|
||||||
return mastodon
|
return mastodon
|
||||||
|
|
||||||
|
|
||||||
def terminate(exit_code):
|
|
||||||
"""
|
|
||||||
Cleanly stop execution with a message on execution duration
|
|
||||||
:param exit_code: return value to pass to shell when exiting
|
|
||||||
"""
|
|
||||||
logging.info('Run time : {t:2.1f} seconds.'.format(t=time.time() - START_TIME))
|
|
||||||
logging.info('_____________________________________________________________________________________')
|
|
||||||
exit(exit_code)
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
# Start stopwatch
|
# Start stopwatch
|
||||||
global START_TIME
|
start_time = time.time()
|
||||||
START_TIME = time.time()
|
|
||||||
|
|
||||||
# Build parser for command line arguments
|
# Build parser for command line arguments
|
||||||
parser = argparse.ArgumentParser(description='toot tweets.')
|
parser = argparse.ArgumentParser(description='toot tweets.')
|
||||||
@ -588,8 +576,6 @@ def main(argv):
|
|||||||
datefmt='%Y-%m-%d %H:%M:%S',
|
datefmt='%Y-%m-%d %H:%M:%S',
|
||||||
)
|
)
|
||||||
|
|
||||||
logging.info('_____________________________________________________________________________________')
|
|
||||||
|
|
||||||
logging.info('Running with the following configuration:')
|
logging.info('Running with the following configuration:')
|
||||||
logging.info(' Config File : ' + str(args['f']))
|
logging.info(' Config File : ' + str(args['f']))
|
||||||
logging.info(' twitter_account : ' + TOML['config']['twitter_account'])
|
logging.info(' twitter_account : ' + TOML['config']['twitter_account'])
|
||||||
@ -651,16 +637,16 @@ def main(argv):
|
|||||||
twit_account_page = session.get(url, headers=headers, timeout=HTTPS_REQ_TIMEOUT)
|
twit_account_page = session.get(url, headers=headers, timeout=HTTPS_REQ_TIMEOUT)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
logging.fatal('Host did not respond when trying to download ' + url)
|
logging.fatal('Host did not respond when trying to download ' + url)
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
logging.fatal(nitter_url + ' took too long to respond')
|
logging.fatal(nitter_url + ' took too long to respond')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
|
|
||||||
# Verify that download worked
|
# Verify that download worked
|
||||||
if twit_account_page.status_code != 200:
|
if twit_account_page.status_code != 200:
|
||||||
logging.fatal('The Nitter page did not download correctly from ' + url + ' (' + str(
|
logging.fatal('The Nitter page did not download correctly from ' + url + ' (' + str(
|
||||||
twit_account_page.status_code) + '). Aborting')
|
twit_account_page.status_code) + '). Aborting')
|
||||||
terminate(-1)
|
exit(-1)
|
||||||
|
|
||||||
logging.debug('Nitter page downloaded successfully from ' + url)
|
logging.debug('Nitter page downloaded successfully from ' + url)
|
||||||
|
|
||||||
@ -959,7 +945,8 @@ def main(argv):
|
|||||||
|
|
||||||
logging.info('Deleted ' + str(excess_count) + ' old records from database.')
|
logging.info('Deleted ' + str(excess_count) + ' old records from database.')
|
||||||
|
|
||||||
terminate(0)
|
logging.info('Run time : %2.1f seconds' % (time.time() - start_time))
|
||||||
|
logging.info('_____________________________________________________________________________________')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user