From 41712a2ecf0ebdfb031a1c145bd13b388f02fe62 Mon Sep 17 00:00:00 2001 From: Gabriel-Andrew Pollo Guilbert Date: Fri, 5 Aug 2016 22:09:46 -0400 Subject: [PATCH 1/2] Format link in the message using markdown --- App.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/App.py b/App.py index 6894de5..25b9d97 100644 --- a/App.py +++ b/App.py @@ -45,6 +45,16 @@ 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, @@ -52,16 +62,28 @@ def create_payload(self, message): '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): From 5d73b3b4218c6473492b6abb187037ea7d2ecbbe Mon Sep 17 00:00:00 2001 From: Gabriel-Andrew Pollo Guilbert Date: Fri, 5 Aug 2016 22:33:01 -0400 Subject: [PATCH 2/2] Add Dockerfile --- Dockerfile | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..50ecb09 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM frolvlad/alpine-python3:latest +MAINTAINER Gabriel G. + +ADD App.py . +ADD conf/template . + +RUN pip install tweepy simplejson urllib3 + +ENTRYPOINT ["python3", "App.py", "template"]