-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcsv-parser.py
More file actions
111 lines (89 loc) · 2.88 KB
/
csv-parser.py
File metadata and controls
111 lines (89 loc) · 2.88 KB
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
#!/usr/bin/python2.7
"""
Custom HackUCI script that rips open an eventbrite CSV file
and extracts out the number of students attending based on
features of targeted students.
"""
import os
dirname = os.path.dirname(os.path.realpath(__file__))
filename = 'LATEST.csv'
csv_path = os.path.join(dirname, filename)
def get_email(csv_line):
"""
Extracts out an all lowercase email string from
a CSV line delimited by commas.
"""
chunks = csv_line.split(',')
email = chunks[2]
email = email.lower()
return email
def get_school(csv_line):
"""
Extracts out an all lowercase school string from
a CSV line delimited by commas.
"""
chunks = csv_line.split(',')
school = chunks[-1]
school = school.lower()
return school
def is_uci_student(csv_line):
"""
Inspects a CSV line and returns True if the
student attends UCI, else False
"""
school = get_school(csv_line)
pass_one = ('uci' in school)
pass_two = ('irvine' in school and 'valley' not in school)
pass_three = ('ics' in school)
pass_four = ('bren' in school)
return (pass_one or pass_two or pass_three or pass_four)
def is_highschool_or_cc_student(csv_Line):
"""
Inspects a CSV line and returns True if the
student attends a highschool or a community college,
otherwise it returns False
"""
school = get_school(csv_Line)
pass_one = ('high' in school)
pass_two = ('comm' in school or 'cc' in school)
pass_three = ('ivc' in school)
pass_four = ('college' in school)
return (pass_one or pass_two or pass_three or pass_four)
def is_socal_student(csv_Line):
"""
Inspects a CSV line and returns True if the
student attends any university/CC/HS in Southern
California, else False
"""
pass
def main():
with open(csv_path, 'r+') as f:
data = f.read()
raw_lines = data.split('\r\n')
lines = [line.strip() for line in raw_lines if line]
failed = []
count = 0
with open('/Users/lucas/Desktop/uci_emails.txt', 'w') as f:
for line in lines:
if is_uci_student(line):
print 'SUCCEED:', get_email(line), get_school(line), line
f.write(get_email(line) + '\r\n')
count += 1
else:
failed.append(line)
"""
buckets = {f:1 for f in failed}
for f in failed:
if f in buckets:
buckets[f] += 1
else :
buckets[f] = 1
list_buckets = [(k, v) for k, v in buckets.items()]
ordered_buckets = sorted(list_buckets, key=lambda x: x[0])
# failed = sorted(failed, key=lambda x: x)
for e in ordered_buckets:
print 'FAILED:', e[0], e[1]
"""
print 'We have', count, \
'total people registered from uci on eventbrite'
main()