import json import os FILE_NAME = "quotes.json" def load_user_quotes(): """Load user-submitted quotes from a local file.""" if not os.path.exists(FILE_NAME): return [] with open(FILE_NAME, "r") as f: return json.load(f) def save_user_quote(quote, author): """Save a new user quote in the local file.""" data = load_user_quotes() data.append({"quote": quote, "author": author, "upvotes": 0}) with open(FILE_NAME, "w") as f: json.dump(data, f) def upvote_quote(index): """Increment upvote count for a quote.""" data = load_user_quotes() if 0 <= index < len(data): data[index]["upvotes"] += 1 with open(FILE_NAME, "w") as f: json.dump(data, f)