Skip to content

Commit

Permalink
Merge pull request #6 from murych/beautiful-code
Browse files Browse the repository at this point in the history
Update message.py
  • Loading branch information
murych authored Jan 31, 2017
2 parents eeb1644 + c32127b commit 5bbdc20
Showing 1 changed file with 17 additions and 31 deletions.
48 changes: 17 additions & 31 deletions message.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,14 @@ def __init__(self, post):
self.post = Post(post, attachments=True)

def create_attachments(self):
data_to_send = self.post.json_prepare()
try:
if self.repost:
return json.dumps([{
'fallback': '',
'color': self.post.color,
'text': self.post.text,
'ts': self.post.ts,
'footer': self.post.footer,
'footer_icon': self.post.footer_icon,
'image_url': self.post.image_url,
'thumb_url': self.post.thumb_url,
}, {
'fallback': '',
'color': self.repost.color,
'text': self.repost.text,
'ts': self.repost.ts,
'footer': self.repost.footer,
'footer_icon': self.repost.footer_icon,
'image_url': self.repost.image_url,
'thumb_url': self.repost.thumb_url,
}])
data_repost_to_send = self.repost.json_prepare()
return json.dumps([data_to_send, data_repost_to_send])
except AttributeError:
return json.dumps([{
'fallback': '',
'color': self.post.color,
'text': self.post.text,
'ts': self.post.ts,
'footer': self.post.footer,
'footer_icon': self.post.footer_icon,
'image_url': self.post.image_url,
'thumb_url': self.post.thumb_url,
'mrkdwn_in': ['text'],
}])
data_to_send['mrkdwn_in'] = ['text']
return json.dumps([data_to_send])

@staticmethod
def send_message(auth, channel, text, attachments=None, as_user=True):
Expand All @@ -87,7 +62,6 @@ def __init__(self, post, attachments=None):
self.color = '#0093DA'
self.footer = 'Lambda ФРЭЛА | Лямбда'
self.footer_icon = 'http://lambda-it.ru/static/img/lambda_logo_mid.png'
# try:
if attachments:
try:
if post['attachments']:
Expand Down Expand Up @@ -115,6 +89,18 @@ def get_image(attachments):
else:
return None, None

def json_prepare(self):
return {
'fallback': '',
'color': self.color,
'text': self.text,
'ts': self.ts,
'footer': self.footer,
'footer_icon': self.footer_icon,
'image_url': self.image_url,
'thumb_url': self.thumb_url,
}


class Repost(Post):
def __init__(self, repost):
Expand Down

0 comments on commit 5bbdc20

Please sign in to comment.