-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.py
79 lines (63 loc) · 2.02 KB
/
parse.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
import csv
file_name = "tnpedia-2016.csv"
output_file = "output-with-subjective.md"
final_text = ""
DEPARTMENT = 0
COURSE = 1
COMPANY = 2
PLACEMENT_DAY = 3
SOURCE_INFO = 5
PACKAGE = 6
POSTING = 7
P1_DESC = 18
P1_QUES = 20
with open(file_name, 'rb') as csvfile:
data = csv.reader(csvfile, delimiter=',', quotechar='"')
header = 1
header_row = [ ]
count = 0
deps_obj = { }
for row in data:
if header:
header = 0
continue
dept = row[DEPARTMENT]
if not dept in deps_obj.keys():
deps_obj[dept] = [ ]
deps_obj[dept].append(row)
print deps_obj
for department, responses in sorted(deps_obj.iteritems()):
final_text += "\n***\n## %s" % department
for response in responses:
company = response[COMPANY]
day = response[PLACEMENT_DAY]
source = response[SOURCE_INFO]
package = response[PACKAGE]
posting = response[POSTING]
p1_desc = response[P1_DESC]
p1_ques = response[P1_QUES]
final_text += "\n\n### %s" % company + \
"\n\n**%s**" % day + \
"\n\n**Source of information:** %s" % source + \
"\n\n**Package:** %s" % package + \
"\n\n**Posting:** %s" % posting + \
"\n\n**Phase 1 Desc:** %s" % p1_desc + \
"\n\n**Phase 1 Questions:** %s" % p1_ques
text_file = open(output_file, "w")
text_file.write(final_text)
text_file.close()
'''
for row in data:
if header:
header_row = row
header = 0
continue
print 'Department: %s' % row[DEPARTMENT]
template = "%s\n" % row[PLACEMENT_DAY] + \
"**Source of information:** %s" % row[SOURCE_INFO]
final_text += template
final_text += "\n\n***\n\n"
count += 1
print "Read %d responses" % count
print final_text
'''