-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmember_loader.py
41 lines (29 loc) · 891 Bytes
/
member_loader.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
#!/usr/bin/env python
"""Bulk loader for loading members into datastore."""
import datetime
from google.appengine.ext import db
from google.appengine.tools import bulkloader
import freesidemodels
import random_util
def str_to_bool(s):
"""Casts a string like "TRUE" or "FALSE" into a bool.
Args:
s: str, boolean string--either "TRUE" or "FALSE"
Returns:
bool
"""
return s == 'TRUE'
class MemberLoader(bulkloader.Loader):
"""Parse CSV of members and upload it to datastore."""
def __init__(self):
bulkloader.Loader.__init__(
self,
'Member',
[('username', str),
('email', db.Email),
('active', str_to_bool),
('starving', str_to_bool),
('joined', lambda x: datetime.datetime.strptime(x, '%m/%d/%Y').date()),
('rfid', int),
('password', lambda x: random_util.Password())])
loaders = [MemberLoader]