Skip to content

Commit c04f6fb

Browse files
changes to RMC Library
1 parent 579b406 commit c04f6fb

13 files changed

Lines changed: 2550 additions & 226 deletions

File tree

RMCLakewoodPy/LibraryBooks.csv

Lines changed: 278 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import tkinter as tk
2+
from tkinter import messagebox, ttk
3+
import csv
4+
import os
5+
6+
# Load books from CSV file
7+
def load_books():
8+
books = []
9+
try:
10+
# Debugging: Print the current working directory
11+
print("Current working directory:", os.getcwd())
12+
13+
# Attempt to open the CSV file
14+
with open("LibraryBooks.csv", mode="r", encoding="utf-8") as file:
15+
reader = csv.DictReader(file)
16+
17+
# Debugging: Print the headers of the CSV file
18+
print("CSV Headers:", reader.fieldnames)
19+
20+
for row in reader:
21+
books.append({
22+
"Book_Title": row.get("Book_Title", "").strip(),
23+
"Author": row.get("Author", "").strip(),
24+
"Barcode": row.get("Barcode", "").strip(),
25+
"Status": row.get("Status", "").strip(),
26+
"User": row.get("User", "").strip()
27+
})
28+
29+
# Debugging: Print the loaded books
30+
print("Books loaded:", books)
31+
32+
except FileNotFoundError:
33+
messagebox.showerror("Error", "LibraryBooks.csv file not found.")
34+
except Exception as e:
35+
messagebox.showerror("Error", f"An error occurred while loading books: {e}")
36+
return books
37+
38+
# Save books to CSV file
39+
def save_books(books):
40+
try:
41+
with open("LibraryBooks.csv", mode="w", encoding="utf-8", newline="") as file:
42+
fieldnames = ["Book_Title", "Author", "Barcode", "Status", "User"]
43+
writer = csv.DictWriter(file, fieldnames=fieldnames)
44+
writer.writeheader()
45+
writer.writerows(books)
46+
except Exception as e:
47+
messagebox.showerror("Error", f"An error occurred while saving books: {e}")
48+
49+
# Search books
50+
def search_books():
51+
query = search_entry.get().strip().lower()
52+
search_by = search_by_var.get()
53+
results = []
54+
for book in books:
55+
if query in book[search_by].lower():
56+
results.append(book)
57+
update_treeview(results)
58+
59+
# Check out a book
60+
def check_out_book():
61+
barcode = barcode_entry.get().strip()
62+
user = user_entry.get().strip()
63+
if not barcode or not user:
64+
messagebox.showerror("Error", "Please enter both barcode and user name.")
65+
return
66+
for book in books:
67+
if book["Barcode"] == barcode:
68+
if book["Status"] == "Available":
69+
book["Status"] = "Checked Out"
70+
book["User"] = user
71+
save_books(books)
72+
update_treeview(books)
73+
messagebox.showinfo("Success", f'Book "{book["Book_Title"]}" checked out by {user}.')
74+
return
75+
else:
76+
messagebox.showerror("Error", f'Book "{book["Book_Title"]}" is already checked out.')
77+
return
78+
messagebox.showerror("Error", "Barcode not found.")
79+
80+
# Check in a book
81+
def check_in_book():
82+
barcode = barcode_entry.get().strip()
83+
if not barcode:
84+
messagebox.showerror("Error", "Please enter the barcode.")
85+
return
86+
for book in books:
87+
if book["Barcode"] == barcode:
88+
if book["Status"] == "Checked Out":
89+
book["Status"] = "Available"
90+
book["User"] = ""
91+
save_books(books)
92+
update_treeview(books)
93+
messagebox.showinfo("Success", f'Book "{book["Book_Title"]}" checked in.')
94+
return
95+
else:
96+
messagebox.showerror("Error", f'Book "{book["Book_Title"]}" is already available.')
97+
return
98+
messagebox.showerror("Error", "Barcode not found.")
99+
100+
# Update treeview with books
101+
def update_treeview(data):
102+
for item in tree.get_children():
103+
tree.delete(item)
104+
for book in data:
105+
tree.insert("", "end", values=(book["Book_Title"], book["Author"], book["Barcode"], book["Status"], book["User"]))
106+
107+
# Load books
108+
books = load_books()
109+
110+
# Debugging: Check if books list is empty
111+
if not books:
112+
print("No books loaded. Please check the CSV file.")
113+
114+
# Create GUI
115+
root = tk.Tk()
116+
root.title("Library Management System")
117+
118+
# Search Section
119+
search_frame = tk.Frame(root)
120+
search_frame.pack(pady=10)
121+
search_label = tk.Label(search_frame, text="Search:")
122+
search_label.pack(side="left", padx=5)
123+
search_entry = tk.Entry(search_frame)
124+
search_entry.pack(side="left", padx=5)
125+
search_by_var = tk.StringVar(value="Book_Title")
126+
search_by_menu = ttk.Combobox(search_frame, textvariable=search_by_var, values=["Book_Title", "Author", "User"], state="readonly")
127+
search_by_menu.pack(side="left", padx=5)
128+
search_button = tk.Button(search_frame, text="Search", command=search_books)
129+
search_button.pack(side="left", padx=5)
130+
131+
# Treeview for displaying books
132+
tree = ttk.Treeview(root, columns=("Book_Title", "Author", "Barcode", "Status", "User"), show="headings")
133+
tree.heading("Book_Title", text="Book Title")
134+
tree.heading("Author", text="Author")
135+
tree.heading("Barcode", text="Barcode")
136+
tree.heading("Status", text="Status")
137+
tree.heading("User", text="User")
138+
tree.pack(pady=10, fill="both", expand=True)
139+
update_treeview(books)
140+
141+
# Check Out/In Section
142+
action_frame = tk.Frame(root)
143+
action_frame.pack(pady=10)
144+
barcode_label = tk.Label(action_frame, text="Barcode:")
145+
barcode_label.pack(side="left", padx=5)
146+
barcode_entry = tk.Entry(action_frame)
147+
barcode_entry.pack(side="left", padx=5)
148+
user_label = tk.Label(action_frame, text="User:")
149+
user_label.pack(side="left", padx=5)
150+
user_entry = tk.Entry(action_frame)
151+
user_entry.pack(side="left", padx=5)
152+
check_out_button = tk.Button(action_frame, text="Check Out", command=check_out_book)
153+
check_out_button.pack(side="left", padx=5)
154+
check_in_button = tk.Button(action_frame, text="Check In", command=check_in_book)
155+
check_in_button.pack(side="left", padx=5)
156+
157+
# Run the application
158+
root.mainloop()

actions/update_library.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import json
2+
import csv
3+
import os
4+
5+
issue_body = os.environ["ISSUE_BODY"]
6+
data = json.loads(issue_body)
7+
8+
barcode = data["barcode"]
9+
user = data["user"]
10+
action = data["action"]
11+
12+
with open("data/library.json", "r") as f:
13+
books = json.load(f)
14+
15+
for book in books:
16+
if book["Barcode"] == barcode:
17+
if action == "checkout":
18+
book["Status"] = "Checked Out"
19+
book["User"] = user
20+
elif action == "checkin":
21+
book["Status"] = "Available"
22+
book["User"] = ""
23+
24+
with open("data/library.json", "w") as f:
25+
json.dump(books, f, indent=2)
26+
27+
with open("data/library.csv", "w", newline="") as f:
28+
writer = csv.DictWriter(f, fieldnames=["Book_Title","Author","Barcode","Status","User"])
29+
writer.writeheader()
30+
writer.writerows(books)
31+

actions/workflow.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Update Library
2+
on:
3+
issues:
4+
types: [opened]
5+
jobs:
6+
update:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Run Python script
11+
run: |
12+
ISSUE_BODY='${{ github.event.issue.body }}' python update_library.py
13+
- name: Commit changes
14+
run: |
15+
git config --global user.name "github-actions"
16+
git config --global user.email "actions@github.com"
17+
git add library.json library.csv
18+
git commit -m "Update library data"
19+
git push

data/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 📚 Library Management System
2+
3+
A simple library book management system hosted on GitHub Pages with GitHub Actions.
4+
5+
## Features
6+
- Check out / check in books
7+
- Search by Title, Author, or User
8+
- Data stored in `library.json` and `library.csv`
9+
- GitHub Actions automatically update data when users submit
10+
11+
## Setup
12+
1. Fork/clone this repo.
13+
2. Replace `USERNAME/REPO` in `frontend/script.js` with your repo details.
14+
3. Add a GitHub token with `repo` scope.
15+
4. Enable GitHub Pages (serve `/frontend`).
16+
5. Commit and push — you’re live!

data/library.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Book_Title,Author,Barcode,Status,User

0 commit comments

Comments
 (0)