From afca51195831cceb548deda94ea909ce1810ee3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rita=20Gra=C3=A7a?= Date: Sat, 2 Mar 2019 17:47:18 +0100 Subject: [PATCH] now with image resizingand index --- archive-bot/.DS_Store | Bin 6148 -> 8196 bytes archive-bot/archive_bot.py | 134 ++++++++++--------------------------- 2 files changed, 34 insertions(+), 100 deletions(-) diff --git a/archive-bot/.DS_Store b/archive-bot/.DS_Store index 5e3a412786d7aaccea10e51e80f46baed2a1a4f6..cfbb97711878b78d7b281e5f8a034cc4b44a63ca 100644 GIT binary patch literal 8196 zcmeI1Pj1sd6vp2)X>o#pAR#qNZ;)72B~gp3E-FQ#EV@H7f(4+|ZUV97dLqZEDIv%k z?f~3?qi_Q5!3E%(KLp2VR#YfTW~7;KGV?u0^V5v&mk<$akGf5wIuTi@LTfkCTv5cl zsB>jQkKBba#1jQ{K|Sh_Pkhd81`Gj1zz{G53;{!683^E+EsC|^xvyqTYX}$uYe_)d zA8b^iEv=bSdFwzUQvhfg!?K`{JV3_ST3cE(r7{%PRM`X5p-iV3Ooe0K7ItV$Yo=6% z6I0>D^fxn|p)mRFh_j`gSWBsC4FN-7o`A^RZ<9wcol$=#e@|$a26TB6@-si=K78V6 z9is03k_A1YEqa4oKcp`5{&?2QwlV*Ck=IX$1AX1^{vZs7Nu%+DZIsHJTQ@ALYE^Gl zU%P#tx`~&JhHWo?DLy^*lD@C|&o~dKeb0X$^wLi4-eVpmUJ&(S860$bu)KN^L|vY? z`6%iR<#k*&VObTc(y7(QW5;Ri*n3WMvSW`A4$$A;9KONOSo?_jqbKKkd~rXdv2Y*Gp|u{f4j?3_HFoO8(# zUE6`oEwO;9Brz2Z7yE?6l}DsqONQqfcaYdCX#ouwn6l~wN@{_1k^etg{QLi^V=(J8 z1lF1WD<8YZZ6NsbUR$Iga%~&+6jc=A%aqCxG%_8B%5)q${lgG_8&(n1(wZs72+Du| WA>i-pxOx7AzlLC*|8h63PxBkdF8)9O delta 104 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGqg`E6q~50$jCS`z?zY9GLL}$#xfiB#q1m$ rg3KU!pfYYC;R?j<8w 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(): @@ -168,8 +138,9 @@ class MUCBot(slixmpp.ClientXMPP): 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) + + # Add image to stream and resizes it + img = ''.format(filename) stream = 'index.html' stream_path = os.path.join(folder, stream) f = open(stream_path, 'a+') @@ -190,72 +161,35 @@ class MUCBot(slixmpp.ClientXMPP): f.write(message+'\n') f.close() + #adds content to index.htm + path = "." + with os.scandir(path) as it: + for entry in it: + if not entry.name.startswith('.') and not entry.is_file(): + a = entry.name + print(a) + #note that the 'w' writes, the 'a' appends + f = open('index.htm','w') + message = """ + + +

The archive

+

See the categories:

+ """ + f.write(message) + f.close() + + #appends the name of the folder and link to index + for a in os.listdir('.'): + if os.path.isdir(a): + f = open('index.htm','a') + message = """ + {} + """.format(a, a) + f.write(message) + 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() - - - # - # if '#paranodalactivity' in msg['body']: - # - # # reply from the bot - # self.send_message(mto=msg['from'].bare, - # mbody="I sense some Paranodal Activity, {}.".format(msg['mucnick']), - # mtype='groupchat') - # - # # Add message to stream - # message = '

{}

'.format(msg['body']) - # outputparanodal = self.outputparanodal - # if not os.path.exists(outputparanodal): - # os.mkdir(outputparanodal) - # stream = 'stream.html' - # stream_path = os.path.join(outputparanodal, stream) - # f = open(stream_path, 'a+') - # f.write(message+'\n') - # f.close() - # - # # Include messages in the stream (only when '#paranodalactivity' is used in the message) - # if '#physical' in msg['body']: - # - # # reply from the bot - # self.send_message(mto=msg['from'].bare, - # mbody="Let's get physical, {}.".format(msg['mucnick']), - # mtype='groupchat') - # - # # Add message to stream - # message = '

{}

'.format(msg['body']) - # output = self.output - # if not os.path.exists(output): - # os.mkdir(output) - # stream = 'stream.html' - # stream_path = os.path.join(output, stream) - # f = open(stream_path, 'a+') - # f.write(message+'\n') - # f.close() - if __name__ == '__main__': # Setup the command line arguments. parser = ArgumentParser()