mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-23 08:38:30 +00:00
Compare commits
5 Commits
c87f152371
...
01a944d692
Author | SHA1 | Date | |
---|---|---|---|
|
01a944d692 | ||
|
e4251e1175 | ||
|
5ec7057185 | ||
|
84e592d530 | ||
|
aebe6c21c6 |
47
twoot.py
47
twoot.py
@ -49,10 +49,11 @@ 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://nitter.privacy.com.de',
|
'https://https://nitter.namazso.eu',
|
||||||
'https://twitter.beparanoid.de',
|
'https://twitter.beparanoid.de',
|
||||||
'https://n.l5.ca',
|
'https://n.l5.ca',
|
||||||
'https://nitter.bus-hit.me',
|
'https://nitter.privacytools.io',
|
||||||
|
'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/
|
||||||
@ -115,10 +116,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')
|
||||||
exit(-1)
|
terminate(-1)
|
||||||
except tomllib.TOMLDecodeError:
|
except tomllib.TOMLDecodeError:
|
||||||
print('Malformed config file')
|
print('Malformed config file')
|
||||||
exit(-1)
|
terminate(-1)
|
||||||
|
|
||||||
TOML['config'] = loaded_toml['config']
|
TOML['config'] = loaded_toml['config']
|
||||||
for k in TOML['options'].keys():
|
for k in TOML['options'].keys():
|
||||||
@ -156,13 +157,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')
|
||||||
exit(-1)
|
terminate(-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')
|
||||||
exit(-1)
|
terminate(-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')
|
||||||
exit(-1)
|
terminate(-1)
|
||||||
|
|
||||||
|
|
||||||
def deredir_url(url):
|
def deredir_url(url):
|
||||||
@ -487,7 +488,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)
|
||||||
exit(-1)
|
terminate(-1)
|
||||||
|
|
||||||
mastodon = None
|
mastodon = None
|
||||||
|
|
||||||
@ -509,7 +510,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)
|
||||||
exit(-1)
|
terminate(-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 \
|
||||||
@ -526,17 +527,28 @@ 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)
|
||||||
exit(-1)
|
terminate(-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')
|
||||||
exit(-1)
|
terminate(-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
|
||||||
start_time = time.time()
|
global START_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.')
|
||||||
@ -576,6 +588,8 @@ 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'])
|
||||||
@ -637,16 +651,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)
|
||||||
exit(-1)
|
terminate(-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')
|
||||||
exit(-1)
|
terminate(-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')
|
||||||
exit(-1)
|
terminate(-1)
|
||||||
|
|
||||||
logging.debug('Nitter page downloaded successfully from ' + url)
|
logging.debug('Nitter page downloaded successfully from ' + url)
|
||||||
|
|
||||||
@ -945,8 +959,7 @@ def main(argv):
|
|||||||
|
|
||||||
logging.info('Deleted ' + str(excess_count) + ' old records from database.')
|
logging.info('Deleted ' + str(excess_count) + ' old records from database.')
|
||||||
|
|
||||||
logging.info('Run time : %2.1f seconds' % (time.time() - start_time))
|
terminate(0)
|
||||||
logging.info('_____________________________________________________________________________________')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user