mirror of
https://gitlab.com/jeancf/twoot.git
synced 2025-02-23 16:38:42 +00:00
Compare commits
4 Commits
c4b6e94178
...
b886f90bdb
Author | SHA1 | Date | |
---|---|---|---|
|
b886f90bdb | ||
|
9081fe2156 | ||
|
3a18242480 | ||
|
acfe033865 |
@ -1,5 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
**21 FEB 2023** VERSION 3.2.1 Updated user agents and list of nitter instances
|
||||
|
||||
**15 FEB 2023** VERSION 3.2 Added mitigation for Mastodon API error 422, 'Unprocessable Entity',
|
||||
'Cannot attach files that have not finished processing. Try again in a moment!' reported
|
||||
on some instances when posting toots with video.
|
||||
|
@ -3,7 +3,7 @@
|
||||
Twoot is a python script that mirrors tweets from a twitter account to a Mastodon account.
|
||||
It is simple to set-up on a local machine, configurable and feature-rich.
|
||||
|
||||
**21 FEB 2023** VERSION 3.2.1 Updated user agents and list of nitter instances
|
||||
**13 MAR 2023** VERSION 3.2.2 Updated list of nitter instances
|
||||
|
||||
> Previous updates can be found in CHANGELOG.
|
||||
|
||||
|
23
twoot.py
23
twoot.py
@ -44,12 +44,15 @@ HTTPS_REQ_TIMEOUT = 10
|
||||
|
||||
NITTER_URLS = [
|
||||
'https://nitter.lacontrevoie.fr', # rate limited
|
||||
'https://nitter.namazso.eu',
|
||||
'https://twitter.beparanoid.de',
|
||||
'https://twitter.femboy.hu', # Replace beparanoid 27/02/2023
|
||||
'https://n.l5.ca',
|
||||
'https://nitter.it', # added 27/02/2023
|
||||
'https://nitter.grimneko.de', # added 27/02/2023
|
||||
'https://nitter.cutelab.space', # USA, added 16/02/2023
|
||||
'https://nitter.fly.dev', # anycast, added 06/02/2023
|
||||
'https://notabird.site', # anycast, added 06/02/2023
|
||||
# 'https://nitter.namazso.eu', # lots of 403 27/02/2023
|
||||
# 'https://twitter.beparanoid.de', # moved 27/022023
|
||||
# 'https://nitter.fdn.fr', # not updated, rate limited, removed 06/02/2023
|
||||
# 'https://nitter.hu',
|
||||
# 'https://nitter.privacydev.net', # USA, added 06/02/2023, removed 15/02/2023 too slow
|
||||
@ -109,7 +112,7 @@ def build_config(args):
|
||||
except ModuleNotFoundError:
|
||||
# for python < 3.11, tomli module must be installed
|
||||
import tomli as tomllib
|
||||
|
||||
|
||||
loaded_toml = None
|
||||
# Load toml file
|
||||
try:
|
||||
@ -121,7 +124,7 @@ def build_config(args):
|
||||
except tomllib.TOMLDecodeError:
|
||||
print('Malformed config file')
|
||||
terminate(-1)
|
||||
|
||||
|
||||
TOML['config'] = loaded_toml['config']
|
||||
for k in TOML['options'].keys():
|
||||
try: # Go through all valid keys
|
||||
@ -259,7 +262,7 @@ def substitute_source(orig_url):
|
||||
domain = parsed_url.netloc
|
||||
|
||||
logging.debug("Checking domain %s for substitution ", domain)
|
||||
|
||||
|
||||
# Handle twitter
|
||||
twitter_subst = TOML["options"]["subst_twitter"]
|
||||
# Do not substitiute if subdomain is present (e.g. i.twitter.com)
|
||||
@ -353,7 +356,7 @@ def process_media_body(tt_iter):
|
||||
url = deredir_url(tag.get('href'))
|
||||
url = substitute_source(url)
|
||||
url = clean_url(url)
|
||||
|
||||
|
||||
tweet_text += url
|
||||
else:
|
||||
logging.warning("No handler for tag in twitter text: " + tag.prettify())
|
||||
@ -520,7 +523,7 @@ def login(password):
|
||||
logging.fatal('Login to ' + TOML['config']['mastodon_instance'] + ' Failed\n')
|
||||
logging.fatal(me)
|
||||
terminate(-1)
|
||||
|
||||
|
||||
if os.path.isfile(TOML['config']['mastodon_user'] + '.secret'):
|
||||
logging.warning('You successfully logged in using a password and an access token \
|
||||
has been saved. The password can therefore be omitted from the \
|
||||
@ -689,7 +692,7 @@ def main(argv):
|
||||
logging.info(' subst_twitter : ' + str(TOML['options']['subst_reddit']))
|
||||
logging.info(' log_level : ' + str(TOML['options']['log_level']))
|
||||
logging.info(' log_days : ' + str(TOML['options']['log_days']))
|
||||
|
||||
|
||||
# Try to open database. If it does not exist, create it
|
||||
sql = sqlite3.connect('twoot.db')
|
||||
db = sql.cursor()
|
||||
@ -990,7 +993,7 @@ def main(argv):
|
||||
toot = mastodon.status_post(tweet['tweet_text'], media_ids=media_ids)
|
||||
|
||||
except MastodonAPIError:
|
||||
# Assuming this is an:
|
||||
# Assuming this is an:
|
||||
# ERROR ('Mastodon API returned error', 422, 'Unprocessable Entity', 'Cannot attach files that have not finished processing. Try again in a moment!')
|
||||
logging.warning('Mastodon API Error 422: Cannot attach files that have not finished processing. Waiting 15 seconds and retrying.')
|
||||
# Wait 15 seconds
|
||||
@ -1047,7 +1050,7 @@ def main(argv):
|
||||
sql.commit()
|
||||
|
||||
logging.info('Deleted ' + str(excess_count) + ' old records from database.')
|
||||
|
||||
|
||||
terminate(0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user