Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from urllib.parse import quote
- import webbrowser
- import random
- import Quartz # keyboardevents
- import time
- def mailto(recipients, subject, body):
- "recipients: string with comma-separated emails (no spaces!)"
- webbrowser.open("mailto:%s?subject=%s&body=%s" %
- (recipients, quote(subject), quote(body)))
- body_template = """Hallo %(name)s!
- Du wurdest ausgewählt um %(wichtel)s ein besonderes Bier zu schenken. SYNC!"""
- def gen(email, name, wichtel):
- mailto(email, "Stammtisch: Bierwichteln", body_template % locals())
- wichtler = ["Olli", "Sven", "Dirk", "Sebbi", "Jomana", "Alex"]
- wichtlerduplikat = wichtler[:]
- mails = {"Olli":"", "Sven":"Svensteininger1988@gmail.com", "Dirk":"Dpeters@3fish.org", "Sebbi":"sebastianebert94@yahoo.de", "Jomana":"", "Alex":"alexschott87@gmail.com"}
- wichtelpaar = {}
- # create random wichtelpairs
- for item in wichtler:
- choice = random.choice(wichtlerduplikat)
- while (choice == item):
- choice = random.choice(wichtlerduplikat)
- wichtelpaar[item] = choice
- wichtlerduplikat.remove(choice)
- # open mailapp with generated text
- for item in wichtler:
- gen(mails[item], item, wichtelpaar[item])
- # define keystroke to send the mail
- events = [Quartz.CGEventCreateKeyboardEvent(None, 36, True), #Press RETURN
- Quartz.CGEventCreateKeyboardEvent(None, 36, False)]
- Quartz.CGEventSetFlags(events[0], Quartz.kCGEventFlagMaskCommand); # press CMD
- # wait until mailapp and press keystrokes to send the mails
- time.sleep(5)
- for x in range(2):
- for event in events:
- Quartz.CGEventPost(0, event)
- time.sleep(1)
- for event in events:
- Quartz.CFRelease(event)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement