Advertisement
Guest User

Untitled

a guest
Nov 7th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from urllib.parse import quote
  4. import webbrowser
  5. import random
  6. import Quartz # keyboardevents
  7. import time
  8.  
  9. def mailto(recipients, subject, body):
  10. "recipients: string with comma-separated emails (no spaces!)"
  11. webbrowser.open("mailto:%s?subject=%s&body=%s" %
  12. (recipients, quote(subject), quote(body)))
  13.  
  14. body_template = """Hallo %(name)s!
  15. Du wurdest ausgewählt um %(wichtel)s ein besonderes Bier zu schenken. SYNC!"""
  16.  
  17. def gen(email, name, wichtel):
  18. mailto(email, "Stammtisch: Bierwichteln", body_template % locals())
  19.  
  20.  
  21. wichtler = ["Olli", "Sven", "Dirk", "Sebbi", "Jomana", "Alex"]
  22. wichtlerduplikat = wichtler[:]
  23. mails = {"Olli":"", "Sven":"Svensteininger1988@gmail.com", "Dirk":"Dpeters@3fish.org", "Sebbi":"sebastianebert94@yahoo.de", "Jomana":"", "Alex":"alexschott87@gmail.com"}
  24. wichtelpaar = {}
  25.  
  26. # create random wichtelpairs
  27. for item in wichtler:
  28. choice = random.choice(wichtlerduplikat)
  29. while (choice == item):
  30. choice = random.choice(wichtlerduplikat)
  31. wichtelpaar[item] = choice
  32. wichtlerduplikat.remove(choice)
  33.  
  34. # open mailapp with generated text
  35. for item in wichtler:
  36. gen(mails[item], item, wichtelpaar[item])
  37.  
  38. # define keystroke to send the mail
  39. events = [Quartz.CGEventCreateKeyboardEvent(None, 36, True), #Press RETURN
  40. Quartz.CGEventCreateKeyboardEvent(None, 36, False)]
  41.  
  42. Quartz.CGEventSetFlags(events[0], Quartz.kCGEventFlagMaskCommand); # press CMD
  43.  
  44. # wait until mailapp and press keystrokes to send the mails
  45. time.sleep(5)
  46. for x in range(2):
  47. for event in events:
  48. Quartz.CGEventPost(0, event)
  49. time.sleep(1)
  50.  
  51. for event in events:
  52. Quartz.CFRelease(event)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement