mirror of https://gitlab.com/chaica/feed2toot
Post messages in the languge of the original feed
This commit is contained in:
parent
89518b2478
commit
2e2b436e78
|
@ -103,6 +103,12 @@ class Main:
|
|||
sys.exit(0)
|
||||
# sort entries and check if they were not previously sent
|
||||
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:
|
||||
# populate rss with new entry to send
|
||||
rss = populate_rss(entry)
|
||||
|
@ -120,7 +126,7 @@ class Main:
|
|||
if clioptions.dryrun:
|
||||
send_message_dry_run(config, entrytosend, finaltweet)
|
||||
else:
|
||||
send_message(config, clioptions, options, entrytosend, finaltweet, cache, rss)
|
||||
send_message(config, clioptions, options, entrytosend, finaltweet, cache, rss, language)
|
||||
# plugins
|
||||
if plugins and entrytosend:
|
||||
activate_plugins(plugins, finaltweet)
|
||||
|
|
|
@ -64,7 +64,7 @@ def send_message_dry_run(config, entrytosend, finaltweet):
|
|||
else:
|
||||
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'''
|
||||
storeit = True
|
||||
if entrytosend and not clioptions.populate:
|
||||
|
@ -73,7 +73,7 @@ def send_message(config, clioptions, options, entrytosend, finaltweet, cache, rs
|
|||
visibility=config.get(
|
||||
'mastodon', 'toot_visibility',
|
||||
fallback='public')))
|
||||
twp = TootPost(config, options, finaltweet)
|
||||
twp = TootPost(config, options, finaltweet, language)
|
||||
storeit = twp.storeit()
|
||||
else:
|
||||
logging.debug('populating RSS entry {}'.format(rss['id']))
|
||||
|
|
|
@ -21,12 +21,13 @@ from mastodon import Mastodon
|
|||
class TootPost:
|
||||
'''TootPost class'''
|
||||
|
||||
def __init__(self, config, options, toot):
|
||||
def __init__(self, config, options, toot, lang):
|
||||
'''Constructore of the TootPost class'''
|
||||
self.config = config
|
||||
self.options = options
|
||||
self.store = True
|
||||
self.toot = toot
|
||||
self.lang = lang
|
||||
self.main()
|
||||
|
||||
def main(self):
|
||||
|
@ -39,9 +40,9 @@ class TootPost:
|
|||
toot_visibility = self.config.get('mastodon', 'toot_visibility', fallback='public')
|
||||
if 'custom' in self.options['media']:
|
||||
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:
|
||||
mastodon.status_post(self.toot, visibility=toot_visibility)
|
||||
mastodon.status_post(self.toot, visibility=toot_visibility, language=self.lang)
|
||||
|
||||
def storeit(self):
|
||||
'''Indicate if the tweet should be stored or not'''
|
||||
|
|
Loading…
Reference in New Issue