diff --git a/feed2toot/main.py b/feed2toot/main.py index 1c70e03..a1f00b1 100644 --- a/feed2toot/main.py +++ b/feed2toot/main.py @@ -43,6 +43,7 @@ from feed2toot.plugins import activate_plugins from feed2toot.rss import populate_rss from feed2toot.sortentries import sort_entries + class Main: '''Main class of Feed2toot''' @@ -103,6 +104,15 @@ 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']['feed']: + # Only the first two letters count ... + language = feed['feed']['feed']['language'][:2] + else: + language = 'en' + print("Language of feeds: {}".format(language)) + for entry in totweet: # populate rss with new entry to send rss = populate_rss(entry) @@ -111,8 +121,8 @@ class Main: elements = re.findall(r"\{(.*?)\}",tweetformat) # strip : from elements to allow string formating, eg. {title:.20} for i,s in enumerate(elements): - if s.find(':'): - elements[i] = s.split(':')[0] + if s.find(':'): + elements[i] = s.split(':')[0] fe = FilterEntry(elements, entry, options, feed['patterns'], feed['rssobject'], feed['feedname']) entrytosend = fe.finalentry if entrytosend: @@ -120,7 +130,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) diff --git a/feed2toot/message.py b/feed2toot/message.py index ef431d6..5b212a2 100644 --- a/feed2toot/message.py +++ b/feed2toot/message.py @@ -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'])) diff --git a/feed2toot/tootpost.py b/feed2toot/tootpost.py index 9cf7d0d..a7743e9 100644 --- a/feed2toot/tootpost.py +++ b/feed2toot/tootpost.py @@ -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'''