Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Final-Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ys554
Final-Project
Commits
966cf867
Commit
966cf867
authored
6 years ago
by
ys554
Browse files
Options
Downloads
Patches
Plain Diff
assn3
parent
9aa3ce85
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
assn3/README.MD
+5
-0
5 additions, 0 deletions
assn3/README.MD
assn3/accounts
+188
-0
188 additions, 0 deletions
assn3/accounts
assn3/makefile
+15
-0
15 additions, 0 deletions
assn3/makefile
assn3/sample.db
+7
-0
7 additions, 0 deletions
assn3/sample.db
with
215 additions
and
0 deletions
assn3/README.MD
0 → 100644
+
5
−
0
View file @
966cf867
Written in python 3
I used sample.db to test my codes. My code currentlt reads in exported environment variable, so I export sample.db as environment variable.
Thank you!
This diff is collapsed.
Click to expand it.
assn3/accounts
0 → 100755
+
188
−
0
View file @
966cf867
#!/usr/bin/env python3
#Yegeon Seo
#Assignment 3
import
sys
,
time
,
os
,
math
,
random
def
display
(
data
):
arg
=
sys
.
argv
[
1
]
while
True
:
if
arg
==
"
-i
"
:
print
(
"
\n
Info
"
)
elif
arg
==
"
-h
"
:
print
(
"
\n
History
"
)
elif
arg
==
"
-t
"
:
print
(
"
\n
Transaction
"
)
print
(
"
-------
"
)
count
=
1
isValid
=
[]
for
line
in
data
:
accData
=
line
.
split
(
"
:
"
)
accID
=
int
(
accData
[
0
])
accName
=
accData
[
1
]
accInfo
=
[
accName
,
accID
]
if
accInfo
not
in
isValid
:
isValid
.
append
(
accInfo
)
for
person
in
isValid
:
print
(
"
%s) %s %s
"
%
(
count
,
person
[
0
],
person
[
1
]))
count
+=
1
if
arg
==
"
-t
"
:
print
(
"
(c)reate new account
"
)
print
(
"
(q)uit
\n
"
)
choice
=
input
(
"
Enter choice :
"
)
if
choice
==
"
q
"
:
return
False
elif
choice
==
"
c
"
and
arg
==
"
-t
"
:
createAccount
(
isValid
)
else
:
try
:
idNum
=
isValid
[
int
(
choice
)
-
1
][
1
]
except
(
IndexError
,
ValueError
):
print
(
"
Invalid Choice: Exiting
"
)
exit
()
personInfo
=
getPersonal
(
idNum
,
data
)
if
arg
==
"
-i
"
:
info
(
personInfo
,
idNum
)
elif
arg
==
"
-h
"
:
history
(
personInfo
,
idNum
)
elif
arg
==
"
-t
"
:
transaction
(
personInfo
,
idNum
)
def
createAccount
(
isValid
):
random
.
seed
(
time
.
time
())
name
=
input
(
"
\n\t
Enter Name:
"
)
date
=
(
time
.
strftime
(
"
%y.%m.%d
"
))
ids
=
[]
newID
=
random
.
randint
(
1000
,
9999
)
for
person
in
isValid
:
ids
.
append
(
person
[
1
])
while
newID
in
ids
:
newID
=
random
.
randint
(
1000
,
9999
)
print
(
"
=t%s %s: created
"
%
(
name
,
newID
))
temp
=
open
(
"
temp.db
"
,
"
a
"
)
temp
.
write
(
"
{}:{}:{}:{}:{}
\n
"
.
format
(
newID
,
name
,
date
,
"
D
"
,
0
))
temp
.
close
()
def
getPersonal
(
idNum
,
data
):
personInfo
=
[]
for
line
in
data
:
accInfo
=
line
.
split
(
"
:
"
)
accountID
=
int
(
accInfo
[
0
])
if
idNum
==
accountID
:
personInfo
.
append
(
line
)
return
personInfo
def
info
(
personInfo
,
idNum
):
balance
=
0
for
log
in
personInfo
:
accInfo
=
log
.
split
(
"
:
"
)
name
=
accInfo
[
1
]
if
accInfo
[
3
]
==
"
D
"
or
accInfo
[
3
]
==
"
d
"
:
balance
+=
float
(
accInfo
[
4
])
else
:
balance
-=
float
(
accInfo
[
4
])
print
(
"
\n\t
Account#: %s
"
%
idNum
)
print
(
"
\t
Name: %s
"
%
name
)
if
balance
>=
0
:
print
(
"
\t
Balance: $%0.2f
\n
"
%
balance
)
else
:
print
(
"
\t
Balance: -$%0.2f
\n
"
%
math
.
fabs
(
balance
))
def
history
(
personInfo
,
idNum
):
print
(
""
)
for
log
in
personInfo
:
accInfo
=
log
.
split
(
"
:
"
)
if
accInfo
[
3
]
==
"
D
"
:
print
(
'
\t
%sDeposit $%0.2f
'
%
(
accInfo
[
2
],
float
(
accInfo
[
4
])))
else
:
print
(
'
\t
%sWthdrawl $%0.2f
'
%
(
accInfo
[
2
],
float
(
accInfo
[
4
])))
print
(
""
)
def
transaction
(
personInfo
,
idNum
):
date
=
(
time
.
strftime
(
"
%y.%m.%d
"
))
trans
=
input
(
"
\n\t
(W)ithdraw or (D)eposit:
"
)
amount
=
input
(
"
\t
Amount:
"
)
for
log
in
personInfo
:
accInfo
=
log
.
split
(
"
:
"
)
name
=
accInfo
[
1
]
temp
=
open
(
"
temp.db
"
,
"
a
"
)
temp
.
write
(
"
{}:{}:{}:{}:{}
\n
"
.
format
(
idNum
,
name
,
date
,
trans
,
amount
))
temp
.
close
()
print
(
"
\n\t
Transaction Confirmed.
"
)
def
testArg
():
if
len
(
sys
.
argv
)
<
2
:
print
(
"
No arguments passed. Exiting
"
)
exit
()
valid
=
[
"
-i
"
,
"
-h
"
,
"
-t
"
]
if
sys
.
argv
[
1
]
==
"
-?
"
:
print
(
'
usage: accounts [-iht] ...
'
)
exit
()
if
sys
.
argv
[
1
]
not
in
valid
:
print
(
"
Accounts: illegal option {}
"
.
format
(
sys
.
argv
[
1
]))
print
(
'
usage: accounts [-iht] ...
'
)
exit
()
if
__name__
==
'
__main__
'
:
testArg
()
accFile
=
open
(
os
.
environ
[
"
ACCT_LIST
"
],
"
r
"
)
data
=
accFile
.
read
().
splitlines
()
accFile
.
close
()
display
(
data
)
try
:
tempFile
=
open
(
"
temp.db
"
,
"
r
"
)
dataFile
=
open
(
os
.
environ
[
"
ACCT_LIST
"
],
"
a
"
)
exportData
=
tempFile
.
readlines
()
for
line
in
exportData
:
dataFile
.
write
(
line
)
tempFile
.
close
()
dataFile
.
close
()
os
.
remove
(
"
temp.db
"
)
except
IOError
:
pass
This diff is collapsed.
Click to expand it.
assn3/makefile
0 → 100644
+
15
−
0
View file @
966cf867
###### Python ######
#Yegeon Seo
#Assn 3 makefile
.PHONY
:
build view clean
build
:
@
# "Python Makefile"
chmod
+x accounts
view
:
@
\l
ess accounts
clean
:
@
\r
m
$.
pyc
This diff is collapsed.
Click to expand it.
assn3/sample.db
0 → 100644
+
7
−
0
View file @
966cf867
8273:Rocky Raccoon:08.10.17:D:520.00
1902:Nancy Magill:08.10.29:D:770
8273:Rocky Raccoon:08.11.01:W:20.00
1902:Nancy Magill:08.11.14:W:51
8273:Rocky Raccoon:08.11.17:W:60.00
5883:Rocky Raccoon:08.11.17:D:60.00
4224:Penny Lane:08.11.28:W:20.00
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment