def usertoday(username, day): basepath = 'days/' files = [] for entry in os.listdir(basepath): if os.path.isfile(os.path.join(basepath, entry)): files.append(entry) for file in files: if str(day) == str(file).split(".")[0]: datefile = open(f"days/{file}") data = json.load(datefile) for user in data: response = getuserid(username) if response.get('message'): return render_template("error.html", alert="This user doesn't exist! Click here to go back to the home page.", type="bad") if user['Username'] == str(response['id']): if str(request.headers['X-Replit-User-Id']) == user['Username']: commentfile = open("comments.json") comments = json.load(commentfile) realcomments = [] for comment in comments: if str(comment['TodayOwner']) == str(getuserid(username)['id']) and str(comment['Date']) == str(day): realcomments.append(comment) return render_template("usertoday.html", user=username, day=day, today=markdown.markdown(user['Do']), ismod=ismod(str(request.headers['X-Replit-User-Id'])), owner=True, comments=realcomments, your=request.headers['X-Replit-User-Name']) else: commentfile = open("comments.json") comments = json.load(commentfile) realcomments = [] for comment in comments: if str(comment['TodayOwner']) == str(getuserid(username)['id']) and str(comment['Date']) == str(day): realcomments.append(comment) return render_template("usertoday.html", user=username, day=day, today=markdown.markdown(user['Do']), ismod=ismod(str(request.headers['X-Replit-User-Id'])), owner=False, comments=realcomments, your=request.headers['X-Replit-User-Name'])
def edittodayfunc(username, date): if request.method == "POST": if not request.headers['X-Replit-User-Name']: return render_template("error.html", alert="You are not logged in. Click here to log in!", type="bad") try: datefile = open(f"days/{date}.json") datefile.close() except: return render_template("error.html", alert="This is not a date file. Click here to go back to the home page!", type="bad") if getuserid(username).get('message'): return render_template("error.html", alert="This user doesn't exist! Click here to go back to the home page.", type="bad") datefile = open(f"days/{date}.json") data = json.load(datefile) data2 = data for user in data: if str(user['Username']) == str(getuserid(username)['id']): if str(request.headers['X-Replit-User-Id']) == str(user['Username']): index = data2.index(user) del data2[index] data2.append({"Username": str(getuserid(username)['id']), "Do": request.form['do']}) datefile.close() with open(f"days/{date}.json", 'w+') as fp: json.dump(data2, fp) return render_template("error.html", alert=f"Edited {username}'s today of {date}. Click here to go back to the home page!", type="good") else: return render_template("error.html", alert="You are not the owner of this today!", type="bad")
def edittoday(username, date): if not request.headers['X-Replit-User-Name']: return render_template("error.html", alert="You are not logged in. Click here to log in!", type="bad") try: datefile = open(f"days/{date}.json") datefile.close() except: return render_template("error.html", alert="This is not a date file. Click here to go back to the home page!", type="bad") if getuserid(username).get('message'): return render_template("error.html", alert="This user doesn't exist! Click here to go back to the home page.", type="bad") datefile = open(f"days/{date}.json") data = json.load(datefile) for user in data: if str(user['Username']) == str(getuserid(username)['id']): if str(request.headers['X-Replit-User-Id']) == str(user['Username']): return render_template("edittoday.html", text=user['Do'], username=username, date=date) else: return render_template("error.html", alert="You are not the owner of this today!", type="bad")
def comment(username, date): if request.method == "POST": comment = request.form['comment'] if not request.headers['X-Replit-User-Name']: return render_template("error.html", alert="You are not logged in. Click here to log in!", type="bad") try: datefile = open(f"days/{date}.json") datefile.close() except: return render_template("error.html", alert="This is not a date file. Click here to go back to the home page!", type="bad") if getuserid(username).get('message'): return render_template("error.html", alert="This user doesn't exist! Click here to go back to the home page.", type="bad") datefile = open(f"days/{date}.json") data = json.load(datefile) for user in data: if str(user['Username']) == str(getuserid(username)['id']): commentfile = open("comments.json") comments = json.load(commentfile) commentdict = {"Comment": comment, "Date": date, "TodayOwner": str(getuserid(username)['id']), "Username": request.headers['X-Replit-User-Name'], "Id": str(uuid4())} comments.append(commentdict) with open("comments.json", 'w+') as fp: json.dump(comments, fp) return render_template("error.html", alert=f"Commented on {username}'s today of {date}. Click here to go back to the home page!", type="good")
def showuser(username): basepath = 'days/' files = [] todays = {} for entry in os.listdir(basepath): if os.path.isfile(os.path.join(basepath, entry)): files.append(entry) for file in files: datefile = open(f"days/{file}") data = json.load(datefile) for user in data: response = getuserid(username) if response.get('message'): return render_template("error.html", alert="This user doesn't exist! Click here to go back to the home page.", type="bad") if user['Username'] == str(response['id']): todays[file.split(".")[0]] = user['Do'] return render_template("user.html", user=username, todays=dict(reversed(list(todays.items()))))