]> code.communitydata.science - social-media-chapter.git/blob - code/data_processing/01_cited_by_to_edgelist.py
Fixing danah boyd reference
[social-media-chapter.git] / code / data_processing / 01_cited_by_to_edgelist.py
1 from datetime import datetime
2 import json
3 import argparse
4 import csv
5
6
7 def main():
8
9     parser = argparse.ArgumentParser(description='Make a citation network from the cited_by json')
10     parser.add_argument('-i', help='Cited_by file')
11     parser.add_argument('-o', help='TSV output file')
12     args = parser.parse_args()
13
14     with open(args.i, 'r') as i:
15         with open(args.o, 'w') as o:
16             output = csv.writer(o, delimiter = '\t')
17             output.writerow(['to','from', 'date'])
18             for line in i:
19                 line = json.loads(line)
20                 output.writerow([line['parent_eid'], line['eid'], line['prism:coverDate']])
21
22
23 if __name__ == '__main__':
24     main()
25

Community Data Science Collective || Want to submit a patch?