mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-22 00:02:08 +00:00
Compare commits
5 Commits
c87f152371
...
01a944d692
Author | SHA1 | Date | |
---|---|---|---|
|
01a944d692 | ||
|
e4251e1175 | ||
|
5ec7057185 | ||
|
84e592d530 | ||
|
aebe6c21c6 |
49
twoot.py
49
twoot.py
|
@ -49,10 +49,11 @@ NITTER_URLS = [
|
|||
'https://nitter.lacontrevoie.fr',
|
||||
'https://nitter.privacydev.net',
|
||||
'https://nitter.fdn.fr',
|
||||
'https://nitter.privacy.com.de',
|
||||
'https://https://nitter.namazso.eu',
|
||||
'https://twitter.beparanoid.de',
|
||||
'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/
|
||||
|
@ -115,10 +116,10 @@ def build_config(args):
|
|||
loaded_toml = tomllib.load(config_file)
|
||||
except FileNotFoundError:
|
||||
print('config file not found')
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
except tomllib.TOMLDecodeError:
|
||||
print('Malformed config file')
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
|
||||
TOML['config'] = loaded_toml['config']
|
||||
for k in TOML['options'].keys():
|
||||
|
@ -156,13 +157,13 @@ def build_config(args):
|
|||
# Verify that we have a minimum config to run
|
||||
if 'twitter_account' not in TOML['config'].keys() or TOML['config']['twitter_account'] == "":
|
||||
print('CRITICAL: Missing Twitter account')
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
if 'mastodon_instance' not in TOML['config'].keys() or TOML['config']['mastodon_instance'] == "":
|
||||
print('CRITICAL: Missing Mastodon instance')
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
if 'mastodon_user' not in TOML['config'].keys() or TOML['config']['mastodon_user'] == "":
|
||||
print('CRITICAL: Missing Mastodon user')
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
|
||||
|
||||
def deredir_url(url):
|
||||
|
@ -487,7 +488,7 @@ def login(password):
|
|||
except MastodonError as me:
|
||||
logging.fatal('failed to create app on ' + TOML['config']['mastodon_instance'])
|
||||
logging.fatal(me)
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
|
||||
mastodon = None
|
||||
|
||||
|
@ -509,7 +510,7 @@ def login(password):
|
|||
except MastodonError as me:
|
||||
logging.fatal('Login to ' + TOML['config']['mastodon_instance'] + ' Failed\n')
|
||||
logging.fatal(me)
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
|
||||
if os.path.isfile(TOML['config']['mastodon_user'] + '.secret'):
|
||||
logging.warning('You successfully logged in using a password and an access token \
|
||||
|
@ -526,17 +527,28 @@ def login(password):
|
|||
except MastodonError as me:
|
||||
logging.fatal('Login to ' + TOML['config']['mastodon_instance'] + ' Failed\n')
|
||||
logging.fatal(me)
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
else:
|
||||
logging.fatal('No .secret file found. Password required to log in')
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
|
||||
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):
|
||||
# Start stopwatch
|
||||
start_time = time.time()
|
||||
global START_TIME
|
||||
START_TIME = time.time()
|
||||
|
||||
# Build parser for command line arguments
|
||||
parser = argparse.ArgumentParser(description='toot tweets.')
|
||||
|
@ -576,6 +588,8 @@ def main(argv):
|
|||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
)
|
||||
|
||||
logging.info('_____________________________________________________________________________________')
|
||||
|
||||
logging.info('Running with the following configuration:')
|
||||
logging.info(' Config File : ' + str(args['f']))
|
||||
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)
|
||||
except requests.exceptions.ConnectionError:
|
||||
logging.fatal('Host did not respond when trying to download ' + url)
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
except requests.exceptions.Timeout:
|
||||
logging.fatal(nitter_url + ' took too long to respond')
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
|
||||
# Verify that download worked
|
||||
if twit_account_page.status_code != 200:
|
||||
logging.fatal('The Nitter page did not download correctly from ' + url + ' (' + str(
|
||||
twit_account_page.status_code) + '). Aborting')
|
||||
exit(-1)
|
||||
terminate(-1)
|
||||
|
||||
logging.debug('Nitter page downloaded successfully from ' + url)
|
||||
|
||||
|
@ -944,9 +958,8 @@ def main(argv):
|
|||
sql.commit()
|
||||
|
||||
logging.info('Deleted ' + str(excess_count) + ' old records from database.')
|
||||
|
||||
logging.info('Run time : %2.1f seconds' % (time.time() - start_time))
|
||||
logging.info('_____________________________________________________________________________________')
|
||||
|
||||
terminate(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue
Block a user