Last active
August 3, 2024 14:24
-
-
Save 3dgoose/761afe644d16a0fadcfa750b8ee58151 to your computer and use it in GitHub Desktop.
A Comic Library management system for Pico.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# serialcomic.py | |
import machine | |
import os | |
def add(): | |
title = input("Enter comic title: ") | |
uid = input("Enter UID: ") | |
issn = input("Enter ISSN: ") | |
release_date = input("Enter release date: ") | |
comic_info = f"{title},{uid},{issn},{release_date}\n" | |
try: | |
with open("comics.txt", "a") as file: | |
file.write(comic_info) | |
print("Comic added successfully!") | |
except OSError as e: | |
print(f"Error writing to file: {e}") | |
def rem(): | |
uid_to_remove = input("Enter the UID of the comic to remove: ") | |
with open("comics.txt", "r") as file: | |
lines = file.readlines() | |
with open("comics.txt", "w") as file: | |
removed = False | |
for line in lines: | |
if uid_to_remove not in line: | |
file.write(line) | |
else: | |
removed = True | |
if removed: | |
print(f"Comic with UID {uid_to_remove} has been removed.") | |
else: | |
print(f"Comic with UID {uid_to_remove} not found.") | |
def borrow(): | |
name = input("Enter borrower's name: ") | |
id_card = input("Enter borrower's ID card number: ") | |
uid = input("Enter comic's UID: ") | |
borrow_info = f"{name},{id_card},{uid}\n" | |
with open("borrow.txt", "a") as file: | |
file.write(borrow_info) | |
print("Comic borrowed successfully!") | |
def check_comics_file(): | |
try: | |
with open("comics.txt", "r") as file: | |
content = file.read() | |
print("Contents of comics.txt:") | |
print(content) | |
except OSError as e: | |
print(f"Error reading file: {e}") | |
print("Type \'help\' to get command list") | |
def main(): | |
usr_input = str(input(">> ")) | |
if usr_input == "help": | |
print("exit, add, rem, borrow") | |
elif usr_input == "exit": | |
machine.soft_reset() | |
elif usr_input == "add": | |
add() | |
elif usr_input == "rem": | |
rem() | |
elif usr_input == "borrow": | |
borrow() | |
elif usr_input == "check": | |
check_comics_file() | |
else: | |
print(usr_input, ": command not found") | |
while True: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment