now with image resizingand index

master
Rita Graça 5 years ago
parent 47a19ea863
commit afca511958

Binary file not shown.

@ -22,13 +22,11 @@ from argparse import ArgumentParser
import slixmpp
import ssl, os, requests, urllib
import os, sys
from PIL import Image
#idea of class is important: like creating your own concepts, names, etc. like a library
class MUCBot(slixmpp.ClientXMPP):
"""
A simple Slixmpp bot that will save images
and messages that are marked with #publish to a folder.
"""
def __init__(self, jid, password, room, nick, output, outputparanodal):
slixmpp.ClientXMPP.__init__(self, jid, password)
@ -105,6 +103,7 @@ class MUCBot(slixmpp.ClientXMPP):
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:
#
@ -113,45 +112,16 @@ class MUCBot(slixmpp.ClientXMPP):
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 = '<p class="message">{}</p>'.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 = '<img class="image" src="{}">'.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 = '<img class="image" src="{}">'.format(filename)
# Add image to stream and resizes it
img = '<img class="image" src="{}" width="400">'.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 = """<html>
<head></head>
<body>
<p>The archive</p>
<p> See the categories: </p>
"""
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 = """
<a href="./{}/index.html">{}</a>
""".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 = '<img class="image" src="{}">'.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 = '<p class="message">{}</p>'.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 = '<p class="message">{}</p>'.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()

Loading…
Cancel
Save