Python learns day5 homework

Keywords: Python Mobile JSON git

title: Python learns day5 homework
tags: python
author: Chinge Yang
date: 2017-01-27
---

Python learns day5 homework

@ (Learning) [python]

[TOC]

ATM and Shopping Mall

Job requirement

ATM:

  1. Designated maximum overdraft
  2. Withdrawable
  3. Periodic repayment (monthly repayment on a specified date, e.g. No. 15)
  4. Deposit available
  5. Pay bills regularly
  6. Support multi-user login and inter-user transfer
  7. Supporting multiple users
  8. Administrators can add accounts, specify user quotas, freeze users, etc.

Shopping Cart:

  1. Commodity Information - Quantity, Unit Price, Name
  2. User Information - Account, Password, Balance
  3. User recharge
  4. Shopping history information
  5. Allow users to buy more than one item at a time
  6. Remind when the balance is insufficient
  7. When the user exits, he outputs the shopping information.
  8. Users can view shopping history next time they log in
  9. Hierarchical display of commodity list

1. Procedure description

The shopping mall has the following functions:

  • [x] blog
  • [x] Multi-user login
  • [x] commodities are displayed on a secondary menu
  • [x] recharge function
  • [x] multiple purchases, multiple purchases at a time
  • [x] insufficient balance prompts recharge
  • [x] Shopping history

The functions of ATM are as follows:

  • [x] designated maximum overdraft
  • [x] withdrawable
  • [] Periodic repayment (monthly payment on a specified date, e.g. No. 15)
  • [x] Depositable funds
  • [x] Pay bills regularly
  • [x] Support multi-user login and inter-user transfer
  • [x] Support multiple users
  • [x] Administrators can add accounts, specify user quotas, freeze users, etc.

The blog address of ygqygq2
Job Address: https://git.oschina.net/ygqygq2/python_homework/tree/master/day5 job

2. Basic flow chart

3. Program Test Account

User/password:
ATM Ordinary Users: 1000/abc, 1001/1001
ATM Management User: admin/abc
Shopping mall: test/test

4. Program structure:

.
├── Atm  # ATM Home Course Directory  
│   ├── __init__.py
│   ├── api  # ATM Program API Directory
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   └── pay1.cpython-35.pyc
│   │   └── pay.py # ATM payment api
│   ├── bin  # ATM Execution File Directory
│   │   ├── __init__.py
│   │   ├── atm.py  # ATM Execution Program, Ordinary User Login Entry
│   │   └── manager.py  # ATM Administrator Logon Entry
│   ├── conf  # ATM Configuration Directory
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   └── settings.cpython-35.pyc
│   │   └── settings.py  # ATM Profile
│   ├── core  # ATM Main Logic Program Directory
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   ├── accounts.cpython-35.pyc
│   │   │   ├── auth.cpython-35.pyc
│   │   │   ├── bill_date.cpython-35.pyc
│   │   │   ├── db_handler.cpython-35.pyc
│   │   │   ├── logger.cpython-35.pyc
│   │   │   ├── main.cpython-35.pyc
│   │   │   └── transaction.cpython-35.pyc
│   │   ├── accounts.py  # Used to load and store account data from files
│   │   ├── auth.py  # Used for account authentication and operation
│   │   ├── bill_date.py  # Generate billing start-stop time module based on year-month
│   │   ├── db_handler.py  # Database Connection Engine
│   │   ├── logger.py  # Logging module
│   │   ├── main.py  # Main Logic Program
│   │   └── transaction.py  # All operation modules related to account amount such as bookkeeping, repayment, withdrawal, etc.
│   ├── db  # User Data Storage Directory
│   │   ├── __init__.py
│   │   ├── account_sample.py  # Generate an initial account data, save the data into a file with the account id as the file name, and put it in the accounts directory. The program will find it here by itself.
│   │   └── accounts  # Save account data for each user, one user, one file
│   │       ├── 1000.json  # An Ordinary User Account File
│   │       └── admin.json  # An Administrator User Sample File
│   ├── docs  # Program Description Document Catalogue
│   │   └── __init__.py
│   └── log  # Log root directory
│       ├── __init__.py
│       ├── access.log  # Relevant logs of user access and operations
│       ├── accounts  # Store billing data for each user, one user, one file
│       │   └── 1000.bills  # An Ordinary User's Bill File
│       └── transactions.log  # All transaction repayment and other logs
├── README.md   # readme file
└── Shopping_mall  # Shopping mall program catalogue
    ├── bin  # Directory of Execution Documents in Shopping Mall
    │   ├── __init__.py
    │   └── shopping_mall.py  # Entrance Procedure of Shopping Mall
    ├── conf  # Shopping Mall Configuration Catalogue
    │   ├── __init__.py
    │   ├── __pycache__
    │   │   ├── __init__.cpython-35.pyc
    │   │   ├── goods.cpython-35.pyc
    │   │   └── settings.cpython-35.pyc
    │   ├── goods.py  # Shopping Mall Price List
    │   └── settings.py  # Shopping Mall Profile
    ├── core  # Main Logic Program Catalogue of Shopping Mall
    │   ├── __init__.py
    │   ├── __pycache__
    │   │   ├── __init__.cpython-35.pyc
    │   │   ├── accounts.cpython-35.pyc
    │   │   ├── auth.cpython-35.pyc
    │   │   ├── db_handler.cpython-35.pyc
    │   │   ├── logger.cpython-35.pyc
    │   │   ├── main.cpython-35.pyc
    │   │   └── shopping.cpython-35.pyc
    │   ├── accounts.py  # Used to load and store account data from files
    │   ├── auth.py  # Used for account authentication and operation
    │   ├── db_handler.py  # Database Connection Engine
    │   ├── logger.py  # Logging module
    │   └── main.py  # Main Logic Program
    ├── db  # User Data Storage Directory
    │   └── accounts  # Save account data for each user, one user, one file
    │       ├── __init__.py
    │       └── test.json  # An Ordinary User Account File
    └── log
        ├── access.log  # Relevant logs of user access and operations
        └── test_shopping.log  # User Shopping History Log

5. Program testing

  1. Administrator login failure
    python Atm/bin/manager.py
    ```

    ATM admin manager

    account:a
    password:a
    Account [a] does not exist!
    account:a
    password:a
    Account [a] does not exist!
    account:a
    password:a
    Account [a] does not exist!
    2017-01-27 01:47:07,377 - access - ERROR - account [a] too many login attempts

Process finished with exit code 0

2. Administrator login (normal user is not allowed to login)
`python Atm/bin/manager.py`

ATM admin manager

account:1000
password:abc
Permission denied

Process finished with exit code 0


ATM admin manager

account:admin
password:abc

------- Admin erea ---------
1.  Add account
2.  Query User Information
3.  User information modification (freezing accounts, credit card quotas, etc.)
4.  Generate all user bills
5.  Sign out

:1001
Option does not exist!

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:1
account id:1001
password:1001
Account [1001] is exist,try another account.
account id:1002
password:1002
account [1002] added sucessed

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:2
Please input your query account id:1002
pay_day :22
credit :15000
status :0
balance :15000
id :1002
enroll_date :2017-01-27
expire_date :2022-01-26

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:2
Please input your query account id:1001
pay_day :22
credit :15000
status :0
id :1001
balance :15000
enroll_date :2017-01-27
expire_date :2022-01-26

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:>>:3
account id:1001
You can choose the items like this:
{
"password": "abc",
"credit": 15000,
"status": 0,
"expire_date": "2021-01-01",
"pay_day": 22
}
Input modify items(json):{"credit":20000,"pay_day": 23}
Account infomation updated!

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:2
Please input your query account id:1001
pay_day :23
credit :20000
status :0
balance :15000
id :1001
enroll_date :2017-01-27
expire_date :2022-01-26

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:>>:2
Please input your query account id:0
Get account [0] info pemission denied!

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:2
Please input your query account id:0
Get account [0] info pemission denied!

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:2
Please input your query account id:0
Get account [0] info pemission denied!

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:4
------------------Account bill:-------------------
-----------------------End------------------------
------------------Account bill:-------------------
expire_date :2021-01-01
credit :15000
enroll_date :2016-01-02
status :0
balance :4265.0
pay_day :22
id :1000
Today is not the bill generation day!
Account [1000] need to repay [10735.0]
-----------------------End------------------------
------------------Account bill:-------------------
expire_date :2022-01-26
id :1001
pay_day :23
status :0
balance :15000
enroll_date :2017-01-27
credit :20000
Today is not the bill generation day!
Account [1001] need to repay [5000]
-----------------------End------------------------
------------------Account bill:-------------------
expire_date :2022-01-26
credit :15000
pay_day :22
status :0
balance :15000
enroll_date :2017-01-27
id :1002
Today is not the bill generation day!
Account [1002] needn't to repay.
-----------------------End------------------------
------------------Account bill:-------------------
-----------------------End------------------------

------- Admin erea ---------
1. Adding Accounts
 2. Query User Information
 3. User information modification (freezing accounts, credit card quotas, etc.)
4. Generate all user bills
 5. exit

:5

Bye,thanks!

3. Ordinary user login (administrator is not allowed to login)
`python Atm/bin/atm.py`

Welcome to ATM

account:1000
password:abc

------- Oldboy Bank ---------
1. Account information
 2. Reimbursement (example)
3. withdrawal (example)
4. transfers
 5. deposits
 6. bill
 7. exit

:1
status :0
pay_day :22
enroll_date :2016-01-02
balance :4265.0
expire_date :2021-01-01
credit :15000
id :1000

------- Oldboy Bank ---------
1. Account information
 2. Reimbursement (example)
3. withdrawal (example)
4. transfers
 5. deposits
 6. bill
 7. exit

:2
--------- BALANCE INFO --------
Credit : 15000
Balance: 4265.0
Tip: [b] to back
Input repay amount:200
2017-01-28 09:49:30,934 - transaction - INFO - account:1000 action:repay amount:200.0 interest:0.0
New Balance:4465.0
Tip: [b] to back
Input repay amount:b

------- Oldboy Bank ---------
1. Account information
 2. Reimbursement (example)
3. withdrawal (example)
4. transfers
 5. deposits
 6. bill
 7. exit

:3
--------- BALANCE INFO --------
Credit : 15000
Balance: 4465.0
Tip: [b] to back
Input withdraw amount:200
2017-01-28 09:49:44,162 - transaction - INFO - account:1000 action:withdraw amount:200.0 interest:10.0
New Balance:4255.0
Tip: [b] to back
Input withdraw amount:b

------- Oldboy Bank ---------
1. Account information
 2. Reimbursement (example)
3. withdrawal (example)
4. transfers
 5. deposits
 6. bill
 7. exit

:4
--------- BALANCE INFO --------
Credit : 15000
Balance: 4255.0

(Tip: input [b] to back)
Input receiver:1001
Input transfer amount:200
2017-01-28 09:50:06,723 - transaction - INFO - account:1000 action:transfer amount:200.0 interest:10.0
New Balance:4045.02017-01-28 09:50:06,723 - transaction - INFO - account:1001 action:receive amount:200.0 interest:0.0

Input receiver:b

------- Oldboy Bank ---------
1. Account information
 2. Reimbursement (example)
3. withdrawal (example)
4. transfers
 5. deposits
 6. bill
 7. exit

:5
--------- BALANCE INFO --------
Credit : 15000
Balance: 4045.0

(Tip: input [b] to back)
Input your save amount:400
2017-01-28 09:53:45,354 - transaction - INFO - account:1000 action:save amount:400.0 interest:0.0
New Balance:4445.0

------- Oldboy Bank ---------
1. Account information
 2. Reimbursement (example)
3. withdrawal (example)
4. transfers
 5. deposits
 6. bill
 7. exit

:6
Please input the date you will query like [2016-12]>>>2016-12
Account [1000] bills:
--------------------------------------------------
bill_date: 2017-1 account_id: 1000 need_repay: 10555

bill_date: 2017-1 account_id: 1000 need_repay: 10555

Account [1000] history log:

------- Oldboy Bank ---------
1. Account information
 2. Reimbursement (example)
3. withdrawal (example)
4. transfers
 5. deposits
 6. bill
 7. exit

:6
Please input the date you will query like [2016-12]>>>2017-01
Account [1000] bills:
--------------------------------------------------
bill_date: 2017-1 account_id: 1000 need_repay: 10555

bill_date: 2017-1 account_id: 1000 need_repay: 10555

Account [1000] history log:

2017-01-25 21:33:43,281 - transaction - INFO - account:1000 action:pay amount:10000.0 interest:0.0
2017-01-25 22:16:26,609 - transaction - INFO - account:1000 action:pay amount:100.0 interest:0.0
2017-01-25 22:16:52,347 - transaction - INFO - account:1000 action:pay amount:100.0 interest:0.0
2017-01-26 21:47:42,372 - transaction - INFO - account:1000 action:repay amount:100.0 interest:0.0
2017-01-26 21:51:13,819 - transaction - INFO - account:1000 action:repay amount:100.0 interest:0.0
2017-01-26 21:51:24,608 - transaction - INFO - account:1000 action:withdraw amount:500.0 interest:25.0
2017-01-26 21:53:16,352 - transaction - INFO - account:1000 action:withdraw amount:200.0 interest:10.0
2017-01-28 09:49:30,934 - transaction - INFO - account:1000 action:repay amount:200.0 interest:0.0
2017-01-28 09:49:44,162 - transaction - INFO - account:1000 action:withdraw amount:200.0 interest:10.0
2017-01-28 09:50:06,723 - transaction - INFO - account:1000 action:transfer amount:200.0 interest:10.0
2017-01-28 09:53:45,354 - transaction - INFO - account:1000 action:save amount:400.0 interest:0.0
--------------------------------------------------

------- Oldboy Bank ---------
1. Account information
 2. Reimbursement (example)
3. withdrawal (example)
4. transfers
 5. deposits
 6. bill
 7. exit

:7

Bye,thanks!

Process finished with exit code 1

4. Registered Users of Shopping Mall
`python Shopping_mall/bin/shopping_mall.py`

------------Welcome to shopping mall!-------------

1.  Login
2.  Sign up
3.  Logout

:1
Please input your user name and password!
user:test
password:test
Input [y|yes] to view your purchase history,[others] means not.
Please input:y
User test shopping history:
--------------------------------------------------
2017-01-17 17:15:39,199 - shopping - INFO - account:test action:shopping product_number:2 goods:Tea cost:29378
2017-01-17 17:22:13,163 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:29348
2017-01-24 21:55:50,796 - shopping - INFO - account:test action:shopping product_number:2 goods:Milk cost:29230
2017-01-25 00:05:46,534 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:29200
2017-01-25 00:06:07,089 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:29170
2017-01-25 00:36:53,038 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:29140
2017-01-25 21:33:07,174 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:30110
-------------------Species list-------------------
0 --> Mobile phone
1 --> Car
2 --> Drink
-----------------------End------------------------
[q|b] to quit;[c] to check;[t] to top up
Input your choice:t
Do you want to charge more money?[y|n|b]y
Please use your ATM account to pay.
Please input your top-up amount:1000
account:abc
password:a
Account [abc] does not exist!
account:1000
password:abc
2017-01-28 10:31:52,106 - transaction - INFO - account:1000 action:pay amount:1000.0 interest:0.0
Pay successed
Your balance is [41310]
-------------------Species list-------------------
0 --> Mobile phone
1 --> Car
2 --> Drink
-----------------------End------------------------
[q|b] to quit;[c] to check;[t] to top up
Input your choice:2
---->Enter Drink
-------------------Product list-------------------
0.Milk 59
1.Coffee 30
2.Tea 311
-----------------------End------------------------
[q|quit] to quit;[b|back] to back;[c|check] to check
Please choice the product:1
Please input the number of product:2
Added [2] [Coffee] into shopping cart,your balance is [40250]
2017-01-28 10:32:07,465 - shopping - INFO - account:test action:shopping product_number:2 goods:Coffee cost:40250
-------------------Product list-------------------
0.Milk 59
1.Coffee 30
2.Tea 311
-----------------------End------------------------
[q|quit] to quit;[b|back] to back;[c|check] to check
Please choice the product:b
-------------------Species list-------------------
0 --> Mobile phone
1 --> Car
2 --> Drink
-----------------------End------------------------
[q|b] to quit;[c] to check;[t] to top up
Input your choice:0
---->Enter Mobile phone
-------------------Product list-------------------
0.Iphone7 6188
1.Iphone7 plus 7888
2.Xiaomi5 2888
-----------------------End------------------------
[q|quit] to quit;[b|back] to back;[c|check] to check
Please choice the product:0
Please input the number of product:1
2017-01-28 10:32:20,656 - shopping - INFO - account:test action:shopping product_number:1 goods:Iphone7 cost:34062
Added [1] [Iphone7] into shopping cart,your balance is [34062]
-------------------Product list-------------------
0.Iphone7 6188
1.Iphone7 plus 7888
2.Xiaomi5 2888
-----------------------End------------------------
[q|quit] to quit;[b|back] to back;[c|check] to check
Please choice the product:c
*********You purchased products as below**********
Goods Price Number Cost
Iphone7 6188 1 6188
Coffee 30 2 60
***********************End************************
You total cost: 6248
Your balance is [34062]
-------------------Product list-------------------
0.Iphone7 6188
1.Iphone7 plus 7888
2.Xiaomi5 2888
-----------------------End------------------------
[q|quit] to quit;[b|back] to back;[c|check] to check
Please choice the product:b
-------------------Species list-------------------
0 --> Mobile phone
1 --> Car
2 --> Drink
-----------------------End------------------------
[q|b] to quit;[c] to check;[t] to top up
Input your choice:q
*********You purchased products as below**********
Goods Price Number Cost
Iphone7 6188 1 6188
Coffee 30 2 60
***********************End************************
You total cost: 6248
Your balance is [34062]

Bye,thanks!

Process finished with exit code 1

5. New registered users of shopping malls
`python Shopping_mall/bin/shopping_mall.py`

------------Welcome to shopping mall!-------------

1.  Login
2.  Sign up
3.  Logout

:2
user:test01
password:test01
-------------------Species list-------------------
0 --> Drink
1 --> Mobile phone
2 --> Car
-----------------------End------------------------
[q|b] to quit;[c] to check;[t] to top up
Input your choice:c
*********You purchased products as below**********
Goods Price Number Cost
***********************End************************
You total cost: 0
Your balance is [0]
-------------------Species list-------------------
0 --> Drink
1 --> Mobile phone
2 --> Car
-----------------------End------------------------
[q|b] to quit;[c] to check;[t] to top up
Input your choice:q
*********You purchased products as below**********
Goods Price Number Cost
***********************End************************
You total cost: 0
Your balance is [0]

Bye,thanks!

Process finished with exit code 1

```

Posted by peddel on Fri, 22 Mar 2019 02:15:53 -0700