Post messages in the languge of the original feed

This commit is contained in:
Gabor Sebestyen 2023-07-12 08:00:01 +02:00
parent 89518b2478
commit 2e2b436e78
3 changed files with 13 additions and 6 deletions

View File

@ -103,6 +103,12 @@ class Main:
sys.exit(0) sys.exit(0)
# sort entries and check if they were not previously sent # sort entries and check if they were not previously sent
totweet = sort_entries(clioptions.all, cache, entries) totweet = sort_entries(clioptions.all, cache, entries)
# get language of the feed
# language code should conform to ISO-639-1
if 'language' in feed['feed']:
language = feed['feed']['language']
else:
language = 'en'
for entry in totweet: for entry in totweet:
# populate rss with new entry to send # populate rss with new entry to send
rss = populate_rss(entry) rss = populate_rss(entry)
@ -120,7 +126,7 @@ class Main:
if clioptions.dryrun: if clioptions.dryrun:
send_message_dry_run(config, entrytosend, finaltweet) send_message_dry_run(config, entrytosend, finaltweet)
else: else:
send_message(config, clioptions, options, entrytosend, finaltweet, cache, rss) send_message(config, clioptions, options, entrytosend, finaltweet, cache, rss, language)
# plugins # plugins
if plugins and entrytosend: if plugins and entrytosend:
activate_plugins(plugins, finaltweet) activate_plugins(plugins, finaltweet)

View File

@ -64,7 +64,7 @@ def send_message_dry_run(config, entrytosend, finaltweet):
else: else:
logging.debug('This rss entry did not meet pattern criteria. Should have not been sent') logging.debug('This rss entry did not meet pattern criteria. Should have not been sent')
def send_message(config, clioptions, options, entrytosend, finaltweet, cache, rss): def send_message(config, clioptions, options, entrytosend, finaltweet, cache, rss, language):
'''send message''' '''send message'''
storeit = True storeit = True
if entrytosend and not clioptions.populate: if entrytosend and not clioptions.populate:
@ -73,7 +73,7 @@ def send_message(config, clioptions, options, entrytosend, finaltweet, cache, rs
visibility=config.get( visibility=config.get(
'mastodon', 'toot_visibility', 'mastodon', 'toot_visibility',
fallback='public'))) fallback='public')))
twp = TootPost(config, options, finaltweet) twp = TootPost(config, options, finaltweet, language)
storeit = twp.storeit() storeit = twp.storeit()
else: else:
logging.debug('populating RSS entry {}'.format(rss['id'])) logging.debug('populating RSS entry {}'.format(rss['id']))

View File

@ -21,12 +21,13 @@ from mastodon import Mastodon
class TootPost: class TootPost:
'''TootPost class''' '''TootPost class'''
def __init__(self, config, options, toot): def __init__(self, config, options, toot, lang):
'''Constructore of the TootPost class''' '''Constructore of the TootPost class'''
self.config = config self.config = config
self.options = options self.options = options
self.store = True self.store = True
self.toot = toot self.toot = toot
self.lang = lang
self.main() self.main()
def main(self): def main(self):
@ -39,9 +40,9 @@ class TootPost:
toot_visibility = self.config.get('mastodon', 'toot_visibility', fallback='public') toot_visibility = self.config.get('mastodon', 'toot_visibility', fallback='public')
if 'custom' in self.options['media']: if 'custom' in self.options['media']:
mediaid = mastodon.media_post(self.config['media']['custom']) mediaid = mastodon.media_post(self.config['media']['custom'])
mastodon.status_post(self.toot, media_ids=[mediaid], visibility=toot_visibility) mastodon.status_post(self.toot, media_ids=[mediaid], visibility=toot_visibility, language=self.lang)
else: else:
mastodon.status_post(self.toot, visibility=toot_visibility) mastodon.status_post(self.toot, visibility=toot_visibility, language=self.lang)
def storeit(self): def storeit(self):
'''Indicate if the tweet should be stored or not''' '''Indicate if the tweet should be stored or not'''