From 47a19ea86346260ec9f9fad11eec0981e193ba70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rita=20Gra=C3=A7a?= Date: Wed, 20 Feb 2019 18:59:29 +0000 Subject: [PATCH] new --- archive-bot/.DS_Store | Bin 0 -> 6148 bytes archive-bot/archive_bot.py | 178 ++++++++++++++++++++++--------------- 2 files changed, 107 insertions(+), 71 deletions(-) create mode 100644 archive-bot/.DS_Store diff --git a/archive-bot/.DS_Store b/archive-bot/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5e3a412786d7aaccea10e51e80f46baed2a1a4f6 GIT binary patch literal 6148 zcmeH~KTE_w5XIl>6$ip`rR9Et153N*I16h(fSOZKIEaWI*roGh>zhA{AzIj2$Qzh_ zyOWu0@+&e~0A>Ara{?>@%;~0hwP9*@-F#vP87Wjc?{SYkZgGhY{UrPQfYmN=jYn*8 zH>!Wa3J-WW-}T#W*LTdbhdiaP-rP8oiGT=*fCz|y2>h0S^ zrJJ_YA=Ez|9Q+7CoiXgjxt}Gd)dJL(I)pMpD^W^~(vnAv66K87%xkGbXq2P)&b&|V zT=Ilce0RpHr=zq`jUpfdV*-bqyKRJ9~WsQ0wVCQ2$b38VzcHeWpAClob}pD tzoLH_b3L7dw_>WdVlJ!|AAiZKHs|%0I)r*T<6chHkAQKJiNIeFcn3f_9EAV? literal 0 HcmV?d00001 diff --git a/archive-bot/archive_bot.py b/archive-bot/archive_bot.py index 1403832..b62b0cc 100644 --- a/archive-bot/archive_bot.py +++ b/archive-bot/archive_bot.py @@ -37,7 +37,7 @@ class MUCBot(slixmpp.ClientXMPP): self.nick = nick self.output = output self.outputparanodal = outputparanodal - + self.tmp = None # The session_start event will be triggered when @@ -97,89 +97,125 @@ class MUCBot(slixmpp.ClientXMPP): """ # Some inspection commands - # print('\nMessage:{}'.format(msg)) + print('......,.......................') + print('Message:{}'.format(msg)) # print('\nMessage TYPE:{}'.format(msg['type'])) # print('\nMessage body:{}'.format(msg['body'])) - # print('\nMessage OOB:{}'.format(msg['oob'])) - # print('\nMessage OOB URL:{}'.format(msg['oob']['url'])) + print('Message OOB:{}'.format(msg['oob'])) + print('Message OOB URL:{}'.format(msg['oob']['url'])) # print('\nMessage MUCK NICK:{}'.format(msg['mucnick'])) # Always check that a message is not the bot itself, otherwise you will create an infinite loop responding to your own messages. if msg['mucnick'] != self.nick: - - # Check if an OOB URL is included in the stanza (which is how an image is sent) - # (OOB object - https://xmpp.org/extensions/xep-0066.html#x-oob) - # if len(msg['oob']['url']) > 0: - # - # # Send a reply - # self.send_message(mto=msg['from'].bare, - # mbody="oke {}.".format(msg['mucnick']), - # mtype='groupchat') - # - # # Save the image to the output folder - # url = msg['oob']['url'] # grep the url in the message - # filename = os.path.basename(url) # grep the filename in the url - # output = self.output - # if not os.path.exists(output): - # os.mkdir(output) - # output_path = os.path.join(output, filename) - # - # u = urllib.request.urlopen(url) # read the image data - # f = open(output_path, 'wb') # open the output file - # f.write(u.read()) # write image to file - # f.close() # close the output file # - # # Add image to stream - # img = ''.format(filename) - # stream = 'stream.html' - # stream_path = os.path.join(output, stream) - # f = open(stream_path, 'a+') - # f.write(img+'\n') - # f.close() + #Check if an OOB URL is included in the stanza (which is how an image is sent) + #(OOB object - https://xmpp.org/extensions/xep-0066.html#x-oob) + print(len(msg['oob']['url'])) + if len(msg['oob']['url']) > 0: + + + + + # Save the image to the output folder + url = msg['oob']['url'] # grep the url in the message + self.tmp = url + + + #Send a reply + + self.send_message(mto=msg['from'].bare, + mbody="Please put hashtag!", + mtype='groupchat') + # message = '

{}

'.format(msg['body']) + # if not os.path.exists(word): + # os.mkdir(word) + + # # Send a reply + # self.send_message(mto=msg['from'].bare, + # mbody="oke {}.".format(msg['mucnick']), + # mtype='groupchat') + # + # output = self.output + # if not os.path.exists(output): + # os.mkdir(output) + # output_path = os.path.join(output, filename) + + # u = urllib.request.urlopen(url) # read the image data + # f = open(output_path, 'wb') # open the output file + # f.write(u.read()) # write image to file + # f.close() # close the output file + # + # # Add image to stream + # img = ''.format(filename) + # stream = 'stream.html' + # stream_path = os.path.join(output, stream) + # f = open(stream_path, 'a+') + # f.write(img+'\n') + # f.close() # Include messages in the stream (only when '#' is used in the message. creates a folder for each #) for word in msg['body'].split(): if word.startswith('#'): - self.send_message(mto=msg['from'].bare, - mbody="Here be dragons {} ! You are creating a hashtag called {}.".format(msg['mucnick'], word), - mtype='groupchat') - message = '

{}

'.format(msg['body']) - if not os.path.exists(word): - os.mkdir("{}".format(word)) - stream = 'stream.html' - stream_path = os.path.join(word, stream) - f = open(stream_path, 'a+') - f.write(message+'\n') - f.close() - images = [] - #when it sees an image it asks for a hashtag. hashtag input becomes the directory name. - for img in msg['body']: - self.send_message(mto=msg['from'].bare, - mbody="Put hashtag:", - mtype='groupchat') + if self.tmp: + url = self.tmp + print('URL:', url) + folder = word.replace('#', '') + filename = os.path.basename(url) # grep the filename in the url + if not os.path.exists(folder): + os.mkdir(folder) + output_path = os.path.join(folder, filename) + u = urllib.request.urlopen(url) # read the image data + f = open(output_path, 'wb') # open the output file + f.write(u.read()) # write image to file + f.close() # close the output file + # Add image to stream + img = ''.format(filename) + stream = 'index.html' + stream_path = os.path.join(folder, stream) + f = open(stream_path, 'a+') + f.write(img+'\n') + f.close() + else: + folder = word.replace('#', '') + self.send_message(mto=msg['from'].bare, + mbody="Be aware {} ! You are creating a hashtag called {}.".format(msg['mucnick'], folder), + mtype='groupchat') + message = '

{}

'.format(msg['body']) + if not os.path.exists(folder): + os.mkdir("{}".format(folder)) + stream = 'index.html' + stream_path = os.path.join(folder, stream) + f = open(stream_path, 'a+') + message = message.replace(word, '') + f.write(message+'\n') + f.close() + + + + #HOW TO? Save the image to the output folder - url = msg['oob']['url'] # grep the url in the message - filename = os.path.basename(url) # grep the filename in the url - #output = self.output - - #HERE CHANGE TO HASTAHG CREATED - if not os.path.exists(output): - os.mkdir("{}".format(word)) - output_path = os.path.join(output, filename) - - u = urllib.request.urlopen(url) # read the image data - f = open(output_path, 'wb') # open the output file - f.write(u.read()) # write image to file - f.close() # close the output file - - # Add image to stream - img = ''.format(filename) - stream = 'stream.html' - stream_path = os.path.join(output, stream) - f = open(stream_path, 'a+') - f.write(img+'\n') - f.close() + # url = msg['oob']['url'] # grep the url in the message + # filename = os.path.basename(url) # grep the filename in the url + # output = self.output + # + # #HERE CHANGE TO HASTAHG CREATED + # if not os.path.exists(output): + # os.mkdir("{}".format(word)) + # output_path = os.path.join(output, filename) + # + # u = urllib.request.urlopen(url) # read the image data + # f = open(output_path, 'wb') # open the output file + # f.write(u.read()) # write image to file + # f.close() # close the output file + # + # # Add image to stream + # img = ''.format(filename) + # stream = 'stream.html' + # stream_path = os.path.join(output, stream) + # f = open(stream_path, 'a+') + # f.write(img+'\n') + # f.close() #