Spaces:
Sleeping
Sleeping
File size: 735 Bytes
43682c1 66e9050 43682c1 66e9050 43682c1 66e9050 43682c1 66e9050 43682c1 66e9050 43682c1 66e9050 43682c1 66e9050 43682c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
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)
|