-
Notifications
You must be signed in to change notification settings - Fork 0
/
magazine_authors_parser.py
39 lines (31 loc) · 1.07 KB
/
magazine_authors_parser.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
import csv
parsed_authors = []
with open("data/magazine_authors_uncleaned.csv") as authors_csv:
authors = csv.DictReader(authors_csv)
for author in authors:
original_name = author["drupal_full_name"]
author_split = original_name.split(sep=" ")
family_name = author_split.pop()
given_name = " ".join(author_split)
parsed_author = {
"given_name": given_name,
"family_name": family_name,
"drupal_full_name": original_name,
"drupal_author_id": author["drupal_author_id"],
"civicrm_id": author["civicrm_contact_id"],
}
parsed_authors.append(parsed_author)
with open("data/magazine_authors_parsed.csv", "w", newline="") as parsed_authors_csv:
writer = csv.DictWriter(
parsed_authors_csv,
fieldnames=[
"given_name",
"family_name",
"drupal_full_name",
"drupal_author_id",
"civicrm_id",
],
)
writer.writeheader()
for author in parsed_authors:
writer.writerow(author)