-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccountdb.py
182 lines (146 loc) · 4.7 KB
/
accountdb.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import database
import sys
import time
import datetime
def showDueBills():
currentTime = time.time()
for user in database.getUserList:
due = database.getUserDue(user)
username = database.getUserName(user)
if (currentTime > due):
print(username + " is due.")
def showUserContact(user):
uid = database.getUserId(user)
if (uid == -1):
print "No such user."
return 1
print("Contact details for user: " + user)
contacts = database.getContactList(uid)
for contact in contacts:
contactDetail = database.getContactById(uid, contact)
contactType = database.getContactType(uid, contact)
print(contactType + ": " + contactDetail)
def showUser(user):
uid = database.getUserId(user)
if (uid == -1):
print "No such user."
return 1
timestamp = database.getUserDue(uid)
datestamp = datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
print("User " + user + " due " + datestamp + ".")
showUserContact(user)
def addUser(user):
date_entry = input('Enter a due date in YYYY-MM-DD format: ')
year, month, day = map(int, date_entry.split('-'))
due = datetime.date(year, month, day)
email = input('Enter an email address: ')
service = input('Enter service type: ')
duestamp = due.timestamp()
database.addUser(user, due, service)
database.addContact(user, "email", email)
def addUserContact(user):
ctype = input('Contact type: ')
detail = input('Contact detail: ')
if (not ctype):
print("You must specify a contact type.")
return
if (not detail):
print("You must specify a contact detail.")
return
database.addContact(user, ctype, detail)
print("Contact detail added to database.")
def renameUser(user):
print("Renaming user.")
newname = input('New username: "')
if (not newname):
print("You must specify a new username.")
return
changeUser(user, 0, "", newname)
def searchContact():
ctype = input('Contact type: ')
detail = input('Contact detail: ')
uid = database.searchContact(ctype, detail)
user = database.getContactById(uid)
if (uid == -1):
print("No such contact")
else:
print("Contact belongs to " + user + ".")
showUser(user)
def modifyContact(user):
print("Modifying contact detail.")
showUser(user)
ctype = input('Contact type to change: ')
detail = input('New contact detail: ')
if (database.changeContact(user, ctype, detail, "")):
print("User modified")
else
print("User modification failed")
if (argv.length == 1):
print("You didn't specify any command line arguments.")
sys.exit()
def modifyUserDue(user):
print("Modifying user due date.")
newdate = input("Specify a date YYYY-MM-DD or an duration, eg: D1, W1, M1: ")
if (not newdate):
print ("You must specify a date or duration")
return
due = database.getUserDue(user)
x = 0
days = False
weeks = False
months = False
doDuration = False
durationString = ""
for c in newdate:
if (x == 0):
if (newdate[0] == "D"):
days = True
doDuration = True
if (newdate[0] == "W"):
weeks = True
doDuration = True
if (newdate[0] == "M"):
months = True
doDuration = True
if (x >= 1):
if (doDuration):
durationString = durationString + c
if (doDuration):
durationInt = int(durationString)
if (days):
seconds = durationInt * 24 * 60 * 60
if (weeks)
seconds = durationInt * 7 * 24 * 60 * 60
if (months)
seconds = durationInt * 31 * 24 * 60 * 60
due = due + seconds
else:
year, month, day = map(int, date_entry.split('-'))
due = datetime.date(year, month, day)
database.changeUser(user, due, "", "")
print("Database updated!")
def changeUserType(user):
print("Changing customer type.")
newtype = input("New type: ")
if (not newtype):
print("You must specify a new type.")
return
database.changeUser(user, 0, newtype, "")
#argument handler
success = False
if (argv[1] == "show"):
if (argv.length != 4):
print("Invalid number of arguments.")
sys.exit()
if (argv[2] == "user"):
showUser(argv[3])
success = True
if (not success):
print("Invalid arguments")
sys.exit()
sys.exit()
if (argv[1] == "edit"):
if (argv[1] == "add"):
if (argv[1] == "remove"):
if (argv[1] == "bill"):
showDueBills()