Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
philippesasseville committed Aug 8, 2016
2 parents e3b3794 + 7dafaea commit 11b996d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
26 changes: 24 additions & 2 deletions App.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,45 @@ def create_payload(self, message):
profile = '@' + screen
url = 'https://twitter.com/' + screen

# Format the message with markdown, if possible
msg = ''
for word in message.split():
if word[0] == '@':
msg += self.format_link(word)
else:
msg += word
msg += ' '

# Create the payload itself
return {
'username' : bot,
'icon_url' : avatar,

'attachments' : [{
'color' : '#FF8000',
'author_name': name,
'author_icon': icon,
'author_icon': icon,
'title' : profile,
'title_link' : url,
'fields': [{
'short' : False,
'value' : message
'value' : msg
}]
}]
}

def format_link(self, name):
# Find the range of the name
for i in range(1, len(name)):
if not ((name[i].isalnum()) or (name[i] == '_')):
break

# Fix the range if the last letter is valid
if (name[i].isalnum()) or (name[i] == '_'):
i += 1

return '[@' + name[1:i] + '](https://twitter.com/' + name[1:i] + ')' + name[i:]

if __name__ == '__main__':
# Make sure the config file was given
if (len(sys.argv) != 2):
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM frolvlad/alpine-python3:latest
MAINTAINER Gabriel G. <[email protected]>

ADD App.py .
ADD conf/template .

RUN pip install tweepy simplejson urllib3

ENTRYPOINT ["python3", "App.py", "template"]

0 comments on commit 11b996d

Please sign in to comment.