-
Notifications
You must be signed in to change notification settings - Fork 2
/
process.py
106 lines (87 loc) · 3.95 KB
/
process.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
# -*- coding: utf-8 -*-
import csv
def normalize(v):
return v.strip('-')
def image(v):
table = str.maketrans("áčďéěíňóřšťúůýžÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ",
"acdeeinorstuuyzACDEEINORSTUUYZ")
if v == "":
return ""
return "img/{}.png".format(
v.replace(' ', '_').replace(',', '')
.replace('.', '').lower().translate(table))
def main():
result = []
images = set()
with open('data_from_tito.csv', encoding="utf-8") as csvfile:
reader = csv.DictReader(csvfile)
for r in reader:
# from headers
# odict_keys(
# ['Number', 'Ticket Created Date', 'Ticket Last Updated Date',
# 'Ticket', 'Ticket Full Name', 'Ticket First Name',
# 'Ticket Last Name', 'Ticket Email', 'Ticket Company Name',
# 'Ticket Phone Number', 'Event', 'Void Status', 'Price',
# 'Discount Status', 'Ticket Reference', 'Tags',
# 'Unique Ticket URL', 'Unique Order URL', 'Order Reference',
# 'Order Name', 'Order Email', 'Order Company Name',
# 'Order Phone Number', 'Order Discount Code', 'Order IP',
# 'Order Created Date', 'Order Completed Date',
# 'Payment Reference', 'Company/Organization', 'Job Title',
# 'Where do you live?', 'Do you have any dietary restrictions?',
# 'Gender', 'Interests', 'Twitter nickname', 'Conference'])
# result headers
# "Type,Name,Company,Company Logo,Job Title,Interest 1,Interest 2,Interest 3,Twitter"
interests = list(map(lambda x: x.strip(),
r["Interests"].split(',')))
t = ""
if r["Ticket"].startswith("Partner ticket"):
t = "Partner"
if r["Ticket"].startswith("Speaker ticket"):
t = "Speaker"
if r["Ticket"].startswith("ORG ticket"):
t = "Organizer"
company = normalize(r["Company/Organization"])
company_logo = ""
if r["Ticket"].startswith("Company-funded") or \
r["Ticket"].startswith("Partner ticket"):
company_logo = company
company = ""
if not company_logo:
company_logo = normalize(r["Ticket Company Name"])
company_logo = image(company_logo)
images.add(company_logo)
twitter = normalize(r["Twitter nickname"])
twitter = twitter.replace("https://twitter.com/", "")
if twitter and not twitter.startswith('@'):
twitter = '@' + twitter
name = normalize(r["Ticket Full Name"])
if not name:
name = normalize(r["Order Name"])
job = normalize(r["Job Title"])
ticket = {
"Type": t,
"Name": "{:.21}…".format(name) if len(name) > 22 else name,
"Company": "{:.37}…".format(company) if len(
company) > 38 else company,
"Company Logo": company_logo,
"Job Title": "{:.26}…".format(job) if len(job) > 27 else job,
"Interest 1":
normalize(interests[0] if len(interests) > 0 else ""),
"Interest 2":
normalize(interests[1] if len(interests) > 1 else ""),
"Interest 3":
normalize(interests[2] if len(interests) > 2 else ""),
"Twitter": twitter,
}
# print(ticket)
result.append(ticket)
with open('data_for_badges.csv', 'w', encoding="utf-8") as f:
dw = csv.DictWriter(f, fieldnames=result[0].keys())
dw.writeheader()
dw.writerows(result)
with open("logos.txt", "w") as f:
for i in images:
f.write(i + '\n')
if __name__ == "__main__":
main()