webwriter.py 893 B

123456789101112131415161718192021222324
  1. import os
  2. class WebWriter:
  3. """
  4. Handles writing out to teh home folder of the running user.
  5. Creates a very simple web page that just lists all the images posted in a channel the bot's in.
  6. Probably in trouble for cp because of teh 4cdn links.
  7. """
  8. def __init__(self):
  9. self.path = '~/public_html/img/'
  10. def _generate(self, data):
  11. if data is None:
  12. return
  13. if not os.path.exists(os.path.expanduser(self.path)):
  14. os.makedirs(os.path.expanduser(self.path))
  15. with open(os.path.expanduser('~/public_html/img/index.html'),'w+') as f:
  16. f.write("<html><body>\n")
  17. f.write("<font size=7>ANYTHING AND EVERYTHING ON THIS PAGE MAY BE NSFW. YOU HAVE BEEN WARNED.</font><br />\n")
  18. for line in data:
  19. f.write(line[2] + " pasted link <a href=\"" + line[1] + "\">" + line[1] + "</a> at "+str(line[3])+" UTC<br>\n")
  20. f.write("</html></body>\n")