Start CLI implementation

This commit is contained in:
Lucas Mathews
2024-05-30 11:03:17 +02:00
parent 558d818aac
commit 60114d6ef2
6 changed files with 63 additions and 26 deletions

View File

@@ -1 +1 @@
{"session_cookie": {"session": "m4rjEuzC595awmTv39qVOhjiiQYDcq3PT7ObB1_S6Bs"}, "client_id": "9ce7d233"}
{"session_cookie": {"session": "m-RSGMraIhk3P9RQ5oN5CSbgUBYlFpe9P2aOxm6ayU8"}, "client_id": "9ce7d233"}

25
cli.py
View File

@@ -1,25 +0,0 @@
# Lucas Mathews - Fontys Student ID: 5023572
# Banking System CLI Utility
import requests
import argparse
import sys
from config import CONFIG
SERVER_URL = "http://127.0.0.1:81"
def main():
username = "john"
password = "doe"
print(f"Login with {username} and {password}:")
response = requests.get( f"{SERVER_URL}/login?username={username}&password={password}")
print(f"{response}, {response.content}")
print(f"Logout:")
response = requests.get( f"{SERVER_URL}/logout")
print(f"{response}, {response.content}")
print(f"Closing")
main()
if __name__ == "__main__":
sys.exit( main() )

8
cli/cli.ini Normal file
View File

@@ -0,0 +1,8 @@
[server]
ip = 0.0.0.0
port = 81
url = http://127.0.0.1:81
[client]
default_id = 9ce7d233
default_password = Happymeal1

33
cli/cli.py Normal file
View File

@@ -0,0 +1,33 @@
# Lucas Mathews - Fontys Student ID: 5023572
# Banking System CLI Utility
import argparse
import sys
from connection import login, logout
def main():
parser = argparse.ArgumentParser(description='Banking System CLI Utility')
parser.add_argument('-u', '--username', type=str, help='Username for login')
parser.add_argument('-p', '--password', type=str, help='Password for login')
subparsers = parser.add_subparsers(dest='command')
login_parser = subparsers.add_parser('login', help='Login to the system')
logout_parser = subparsers.add_parser('logout', help='Logout from the system')
args = parser.parse_args()
if args.command == 'login':
if not args.username or not args.password:
print("Username and password are required for login.")
sys.exit(1)
response = login(args.username, args.password)
print(f"{response.status_code}: {response.content}")
elif args.command == 'logout':
response = logout()
print(f"{response.status_code}: {response.content}")
else:
print("Invalid command. Use 'login' or 'logout'.")
if __name__ == "__main__":
main()

7
cli/config.py Normal file
View File

@@ -0,0 +1,7 @@
# Lucas Mathews - Fontys Student ID: 5023572
# Banking System Config Parser
import configparser
CONFIG = configparser.ConfigParser()
CONFIG.read("cli/cli.ini")

14
cli/connection.py Normal file
View File

@@ -0,0 +1,14 @@
# api_client.py
import requests
from config import CONFIG
def login(username, password):
url = f"{CONFIG['server']['url']}/login"
payload = {'username': username, 'password': password}
response = requests.get(url, params=payload)
return response
def logout():
url = f"{CONFIG['server']['url']}/logout"
response = requests.get(url)
return response