Advertisement
algore87

Bierwichteln

Nov 7th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from urllib.parse import quote
  4. import webbrowser # mailto
  5. import random
  6. import Quartz # keyboardevents
  7. import time # wait
  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":"Oliverkrebs87@gmail.com",
  24.          "Sven":"Svensteininger1988@gmail.com",
  25.          "Dirk":"Dpeters@3fish.org",
  26.          "Sebbi":"sebastianebert94@yahoo.de",
  27.          "Jomana":"amrojomana@gmail.com",
  28.          "Alex":"alexschott87@gmail.com"}
  29.  
  30. wichtelpaar = {}
  31.  
  32. # create random wichtelpairs
  33. for item in wichtler:
  34.     choice = random.choice(wichtlerduplikat)
  35.     while (choice == item):
  36.         choice = random.choice(wichtlerduplikat)
  37.     wichtelpaar[item] = choice
  38.     wichtlerduplikat.remove(choice)
  39.  
  40. # open mailapp with generated text
  41. for item in wichtler:
  42.     gen(mails[item], item, wichtelpaar[item])
  43.  
  44. # define keystroke to send the mail
  45. events = [Quartz.CGEventCreateKeyboardEvent(None, 36, True), #Press RETURN
  46.           Quartz.CGEventCreateKeyboardEvent(None, 36, False)]
  47.  
  48. Quartz.CGEventSetFlags(events[0], Quartz.kCGEventFlagMaskCommand); # press CMD
  49.  
  50. # wait until mailapp and press keystrokes to send the mails
  51. time.sleep(5)
  52. for x in range(len(wichtler)):
  53.     for event in events:
  54.         Quartz.CGEventPost(0, event)
  55.         time.sleep(1)
  56.        
  57. # destroy events
  58. for event in events:
  59.     Quartz.CFRelease(event)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement