Various Mastodon Bots

archive.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/python3
  2. from base64 import b64encode, b64decode
  3. from logger import Logger
  4. from util import getAbsolutePath
  5. from sendgrid.helpers.mail import Email, Mail, Content, Attachment, Personalization
  6. import sendgrid
  7. import os
  8. def sendlog():
  9. sg = sendgrid.SendGridAPIClient(apikey=os.environ['SENDGRID_API_KEY'])
  10. contentString = "bi-weekly refactoring roundup"
  11. attachment = Attachment()
  12. attachment.content = encodefile('log/out.txt')
  13. attachment.type = 'text/plain'
  14. attachment.filename = 'log/out.txt'
  15. attachment.disposition = 'attachment'
  16. attachment.content_id = 'log'
  17. from_email = Email('zach@refactorcamp.org')
  18. to_email = Email('vgururao@gmail.com')
  19. subject = 'refactoring roundup'
  20. content = Content('text/plain', contentString)
  21. mail = Mail(from_email, subject, to_email, content)
  22. mail.add_attachment(attachment)
  23. mail.personalizations[0].add_cc(Email('zach@zfadd.is'))
  24. response = sg.client.mail.send.post(request_body=mail.get())
  25. print(response.status_code)
  26. print(response.body)
  27. print(response.headers)
  28. def encodefile(filePath):
  29. with open(filePath, 'rb') as file:
  30. fileString = file.read()
  31. encoded_fileString = b64encode(fileString)
  32. return encoded_fileString.decode()
  33. if __name__ == '__main__':
  34. logDir = getAbsolutePath(__file__, 'log/')
  35. logfile = 'out.txt'
  36. logger = Logger(logDir, logfile)
  37. sendlog()
  38. logger.archive()