-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprofile_class.py
56 lines (50 loc) · 1.87 KB
/
profile_class.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
import json
class Profile:
def __init__(self, username=None, title=None, major=None, university=None, about=None, jobs=None, education=None):
self.username = username
self.title = title
self.major = major
self.university = university
self.about = about
self.jobs = jobs
self.education = education
def get_profile_list(self):
with open("profiles.json", "r") as f:
content = json.loads(f.read())
return content
def get_profile_info(self, username):
content = self.get_profile_list()
for profile in content:
if username == profile['username']:
return profile
return None
def write_profile_info(self):
content = self.get_profile_list()
pro_count = -1
for i, profile in enumerate(content):
if self.username == profile['username']:
pro_count = i
break
if pro_count == -1:
new_profile = {
"username": self.username,
"title": self.title,
"major": self.major,
"university": self.university,
"about": self.about,
"jobs": self.jobs,
"education": self.education
}
content.append(new_profile)
with open("profiles.json", 'w') as f:
json.dump(content, f)
else:
e_profile = content[pro_count]
e_profile['title'] = self.title
e_profile['major'] = self.major
e_profile['university'] = self.university
e_profile['about'] = self.about
e_profile['jobs'] = self.jobs
e_profile['education'] = self.education
with open("profiles.json", "w") as f:
f.write(json.dumps(content))