-
Notifications
You must be signed in to change notification settings - Fork 4
/
eventbrite2mediawiki.py
executable file
·116 lines (91 loc) · 3.59 KB
/
eventbrite2mediawiki.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python
# Convert eventbrite registrations into mediawiki user accounts
# Args:
# 1: event name
# We read a config file at ~/.eventbrite2mediawiki_%(eventname)s, which looks
# something like this:
#
#mikal@dell:~/src/rcbau/hacks$ cat ~/.eventbrite2mediawiki_technical_topics
#{
# "eventbrite": {
# "event_id": "27377136753",
# "token": "...token..."
# },
# "mediawiki": {
# "password": "...password...",
# "url": "https://wiki.madebymikal.com/api.php",
# "username": "...sysop_username..."
# },
# "email": {
# "subject": "Your Technical Topics wiki account",
# "from": "[email protected]",
# "body": "Thanks for registering for Technical Topics. As part of that\nregistration I've created a wiki account for you. That account\ncan be used to edit the event wiki page as much as you'd like.\nThe hope is that requiring people to be registered for the\nevent before being able to edit the wiki will mean that we\nhave less spam problems.\n\nYour account details are:\n Username: %(username)s\n Password: %(password)s\n\nThe wiki is at https://wiki.madebymikal.com/index.php?title=Technical_Topics:December_2016\n\nEnjoy!\n\nMichael"
# }
#}
import json
import mimetypes
import os
import random
import re
import requests
import smtplib
import string
import sys
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import wiki
with open(os.path.expanduser('~/.eventbrite2mediawiki_%s' % sys.argv[1]),
'r') as f:
conf = json.loads(f.read())
base_url = ('https://www.eventbriteapi.com/v3/events/%s'
% conf['eventbrite']['event_id'])
password_chars = string.ascii_letters + string.digits + '!@#$%^&*()'
username_chars = string.ascii_letters + string.digits + '-'
random.seed(os.urandom(1024))
w = wiki.Wiki(conf['mediawiki']['url'],
conf['mediawiki']['username'],
conf['mediawiki']['password'])
def send_email(email, username, password):
body = conf['email']['body'] % {'username': username,
'password': password}
print '-' * 40
print body
print '-' * 40
msg = MIMEMultipart()
msg['Subject'] = conf['email']['subject']
msg['From'] = conf['email']['from']
msg['To'] = email
msg.preamble = body
txt = MIMEText(body, 'plain')
msg.attach(txt)
s = smtplib.SMTP('192.168.1.14')
s.sendmail(conf['email']['from'], [email], msg.as_string())
s.quit()
def make_wiki_name(proposed):
return re.sub('[^%s]' % username_chars, '', proposed)
def process_attendee(profile):
# Generate a random password
password = ''.join(random.choice(password_chars) for i in range(13))
username = '%s%s' %(profile['first_name'], profile['last_name'])
success = w.create_account(
username,
password,
profile['email'],
'%s %s' %(profile['first_name'], profile['last_name']))
if success:
send_email(profile['email'], username, password)
if __name__ == '__main__':
response = requests.get(
'%s/attendees/' % base_url,
headers = {'Authorization': ('Bearer %s'
% conf['eventbrite']['token'])},
verify = True,
)
for attendee in response.json()['attendees']:
attendee['profile']['first_name'] = make_wiki_name(
attendee['profile']['first_name'])
attendee['profile']['last_name'] = make_wiki_name(
attendee['profile']['last_name'])
process_attendee(attendee['profile'])