-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
115 lines (88 loc) · 2.71 KB
/
model.py
File metadata and controls
115 lines (88 loc) · 2.71 KB
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
import web, os, datetime, sqlite3
import globals
class contact_data:
def __init__(self, id='', name='', tel1='', tel2='',loc='',industry='',lastupdate=''):
self.id = id
self.name = name
self.telephone1 = tel1
self.telephone2 = tel2
self.location = loc
self.industry = industry
if lastupdate == '':
self.lastupdate = str(datetime.datetime.now())
else:
self.lastupdate = lastupdate
def totuple(self):
return (self.name,self.telephone1,self.telephone2,self.location,self.industry,self.lastupdate)
def toVcard(self):
s = '''BEGIN:VCARD
FN;CHARSET=UTF-8:{0}
TEL;TYPE=cell:{1}
'''.format(self.name, self.telephone1)
if (self.telephone2 is not None) and (self.telephone2 != ''):
s = s + 'TEL;TYPE=WORK:{0}\r\n'.format(self.telephone2)
s = s + 'ORG;CHARSET=UTF-8:' + self.industry + '\r\n'
s = s + 'ADR;TYPE=home;CHARSET=UTF-8' + self.location + '\r\n'
s = s + 'END:VCARD\r\n'
return s
def get_all_contact():
conn = sqlite3.connect(os.path.join(globals.app_root, 'contact.db'))
conn.text_factory = str
cursor = conn.cursor()
data = []
try:
cursor.execute("select id, name, telephone1, telephone2, location, industry, lastupdate from contact")
results = cursor.fetchall()
for r in results:
data.append(contact_data(r[0],r[1],r[2],r[3],r[4],r[5],r[6]))
except Exception as e:
print e
conn.close()
return data
def get_contact(id):
if (id is None) or (id==''):
return None
conn = sqlite3.connect(os.path.join(globals.app_root, 'contact.db'))
conn.text_factory = str
cursor = conn.cursor()
data = None
try:
cursor.execute("select id, name, telephone1, telephone2, location, industry, lastupdate from contact where id=?", (id,))
r = cursor.fetchone()
if r:
data = contact_data(r[0],r[1],r[2],r[3],r[4],r[5],r[6])
except Exception as e:
print e
conn.close()
return data
def new_contact(data):
if data is None:
return
conn = sqlite3.connect(os.path.join(globals.app_root, 'contact.db'))
conn.text_factory = str
cursor = conn.cursor()
result = False
try:
cursor.execute("insert into contact(name, telephone1, telephone2, location, industry, lastupdate) values(?,?,?,?,?,?)", (data.name, data.telephone1, data.telephone2, data.location, data.industry, data.lastupdate))
conn.commit()
result = True
except Exception as e:
print e
conn.close()
return result
def del_contact(contact_id):
if (contact_id is None) or (contact_id == ''):
return
conn = sqlite3.connect(os.path.join(globals.app_root, 'contact.db'))
conn.text_factory = str
cursor = conn.cursor()
result = False
try:
cursor.execute("delete from contact where id = ?", (contact_id,))
conn.commit()
result = True
except Exception as e:
raise e
print e
conn.close()
return result