-
Notifications
You must be signed in to change notification settings - Fork 5
/
parse_json.py
145 lines (116 loc) · 3.38 KB
/
parse_json.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import json
def parse(json_str, template_str):
print("json:")
print(json_str)
parsed_json = json.loads(json_str)
nonrequired_items = ("Mobile", "Email", "Branch", "Skills", "Achievements", "Area of Interest", "Ques1", "Ques2", "Ques3", "Ques4")
details = {}
for item in nonrequired_items:
if item in parsed_json and parsed_json[item] != "":
details[item] = parsed_json[item]
else:
details[item] = "Not Entered"
# parsed_json = json.loads(json_str)
details["name"] = parsed_json["Name"]
# mobile = str(parsed_json["Mobile"])
# email = parsed_json["Email"]
# branch = parsed_json["Branch"]
details["roll"] = parsed_json["rollno"]
# skills = parsed_json["Skills"]
# achievements = parsed_json["Achievements"]
# areasInt = parsed_json["Area of Interest"]
# answer1 = parsed_json["Ques1"]
# answer2 = parsed_json["Ques2"]
# answer3 = parsed_json["Ques3"]
# answer4 = parsed_json["Ques4"]
skills_list = details["Skills"].split(',')
skills_str = ""
for item in skills_list:
skills_str += "\item "+item
achievement_list = details["Achievements"].split('\n')
achievements_str = ""
for item in achievement_list:
achievements_str += "\item "+item
interest = details["Area of Interest"].split(',')
interest_str = ""
for item in interest:
interest_str += "\item "+item
InterestAreas = "Areas of Interest"
Question1 = "Why should we select you?"
Question2 = "What will you do for our club?"
Question3 = "What are your expectations from us?"
Question4 = "Do you prefer working independently or in a team?"
x = r"""
\cvsection{About Myself}
\begin{cventries}
\cventry
{}{Skills}{}{}
{
\begin{cvitems}
[skills]
\end{cvitems}
}
\cventry
{}{Achievements}{}{}
{
\begin{cvitems}
[achievements]
\end{cvitems}
}
\cventry
{}{AreasOfInt}{}{}
{
\begin{cvitems}
[interest]
\end{cvitems}
}
\cventry
{}{Question1}{}{}
{
\begin{cvitems}
[Answer1]
\end{cvitems}
}
\cventry
{}{Question2}{}{}
{
\begin{cvitems}
[Answer2]
\end{cvitems}
}
\cventry
{}{Question3}{}{}
{
\begin{cvitems}
[Answer3]
\end{cvitems}
}
\cventry
{}{Question4}{}{}
{
\begin{cvitems}
[Answer4]
\end{cvitems}
}
\end{cventries}
"""
template_str = template_str.replace("[content]",x)
template_str = template_str.replace("[skills]",skills_str)
template_str = template_str.replace("AreasOfInt",InterestAreas)
template_str = template_str.replace("[interest]",interest_str)
template_str = template_str.replace("Question1", Question1)
template_str = template_str.replace("[Answer1]",details["Ques1"])
template_str = template_str.replace("Question2", Question2)
template_str = template_str.replace("[Answer2]",details["Ques2"])
template_str = template_str.replace("Question3", Question3)
template_str = template_str.replace("[Answer3]",details["Ques3"])
template_str = template_str.replace("Question4", Question4)
template_str = template_str.replace("[Answer4]",details["Ques4"])
template_str = template_str.replace("[achievements]",achievements_str)
template_str = template_str.replace("[firstname]",details["name"])
template_str = template_str.replace("[lastname]", "")
template_str = template_str.replace("[mobile]", str(details["Mobile"]))
template_str = template_str.replace("[email]", details["Email"])
template_str = template_str.replace("[branch]", details["Branch"])
template_str = template_str.replace("[rollnum]", details["roll"])
return template_str