Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Content of the data that are published - fixed #212
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxMaSk committed Oct 6, 2017
1 parent 15efb61 commit 482c455
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions th_mastodon/my_mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 482c455

Please sign in to comment.