From 482c455f71bcdcc2e2dc86abe2637ff6ed0404e5 Mon Sep 17 00:00:00 2001 From: FoxMaSk Date: Sat, 7 Oct 2017 00:25:03 +0200 Subject: [PATCH] Content of the data that are published - fixed #212 --- th_mastodon/my_mastodon.py | 41 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/th_mastodon/my_mastodon.py b/th_mastodon/my_mastodon.py index 1a86142..c30b407 100644 --- a/th_mastodon/my_mastodon.py +++ b/th_mastodon/my_mastodon.py @@ -184,12 +184,16 @@ def save_data(self, trigger_id, **data): title, content = super(ServiceMastodon, self).save_data( trigger_id, **data) + # check if we have a 'good' title if self.title_or_content(title): - content = str("{title} {link}").format( - title=title, link=data.get('link')) - - content += self.get_tags(trigger_id) + content = str("{title} {link}").format(title=title, + link=data.get('link')) + content += self.get_tags(trigger_id) + # if not then use the content + else: + content += " " + data.get('link') + content += " " + self.get_tags(trigger_id) content = self.set_mastodon_content(content) @@ -206,15 +210,16 @@ def save_data(self, trigger_id, **data): ) except ValueError as e: logger.error(e) - update_result(trigger_id, msg=e, status=False) + status = False + update_result(trigger_id, msg=e, status=status) try: toot_api.toot(content) status = True except Exception as inst: logger.critical("Mastodon ERR {}".format(inst)) - update_result(trigger_id, msg=inst, status=False) status = False + update_result(trigger_id, msg=inst, status=status) return status @@ -240,6 +245,19 @@ def get_tags(self, trigger_id): return tags + def title_or_content(self, title): + """ + If the title always contains 'Tweet from' + drop the title and get 'the content' instead + this allow to have a complet content and not + just a little piece of string + :param title: + :return: + """ + if "Tweet from" in title: + return False + return True + def set_mastodon_content(self, content): """ cleaning content by removing any existing html tag @@ -253,17 +271,6 @@ def set_mastodon_content(self, content): return content - def title_or_content(self, title): - """ - If the title always contains 'New status from' - drop the title and get 'the content' instead - :param title: - :return: - """ - if "New status by" in title: - return False - return True - def auth(self, request): """ get the auth of the services