From 4df21dd096b4d6fd25b11e0872c6329608204d62 Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Mon, 20 May 2024 22:32:00 -0600 Subject: User submitted blahajs working well --- cgi-bin/blahaj_list.cgi | 107 +++++++++++++++++++++++++++++++++++++++ cgi-bin/submit_blahaj_info.cgi | 112 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100755 cgi-bin/blahaj_list.cgi create mode 100755 cgi-bin/submit_blahaj_info.cgi (limited to 'cgi-bin') diff --git a/cgi-bin/blahaj_list.cgi b/cgi-bin/blahaj_list.cgi new file mode 100755 index 0000000..5342a98 --- /dev/null +++ b/cgi-bin/blahaj_list.cgi @@ -0,0 +1,107 @@ +#!/usr/bin/env python + +import cgi +import json + +# Worse code here. Prepare your eyes for this monster. +# Its almost as bad as programming anything in php or even worse javascript. + +print('Content-Type: text/html') + +def create_blahaj_tables(): + try: + tables_html = """ +

Blahaj list!!!!!

+ + + + +
+

Submit yours here if you haven't already!

+

Back to blahaj room

+
+
+ """ + + with open("blahaj_info.json", "r") as fp: + blahaj_list = json.load(fp) + + for blahaj in blahaj_list: + current_table = """ + + + + + + + + +
+ +

put_name_here

+

Date submitted: put_date_here

+
+

put_info_here

+
+ """ + + current_table = current_table.replace("put_name_here", blahaj["name"]) + current_table = current_table.replace("put_info_here", blahaj["info"]) + current_table = current_table.replace("put_date_here", blahaj["date"]) + + tables_html += current_table + + return tables_html + + except FileNotFoundError: # No blahaj's yet + return """ + + + + +
+

No blahaj's found ):

+

Yours could be first tho :3

+

Submit yours here

+
+ """ + +html_text = """ + + + + + hehehe + + + + + +
+ thing_to_replace +
+ + + +""" + +tables = create_blahaj_tables() +html_text = html_text.replace("thing_to_replace", tables) + +print(html_text) diff --git a/cgi-bin/submit_blahaj_info.cgi b/cgi-bin/submit_blahaj_info.cgi new file mode 100755 index 0000000..c0e5f78 --- /dev/null +++ b/cgi-bin/submit_blahaj_info.cgi @@ -0,0 +1,112 @@ +#!/usr/bin/env python + +import cgi +import json +import datetime + +# Get the information given and dump it into a file. +def handle_fields(): + form = cgi.FieldStorage() + + blahaj_name = form.getvalue("blahaj_name") + blahaj_info = form.getvalue("blahaj_info") + + if blahaj_name == None: + return "Blahaj name is required" + + if blahaj_info == None: + blahaj_info = "" + + blahaj_list = [] + + # Get existing data. + try: + with open("blahaj_info.json", "r") as fp: + blahaj_list = json.load(fp) + except FileNotFoundError: + pass + + date = datetime.datetime.now() + blahaj_entry = {"name": blahaj_name, "info": blahaj_info, "date": date.strftime("%B, %d %Y")} + + if blahaj_entry in blahaj_list: + return "Already exists" + + # Dump new data. + with open("blahaj_info.json", "w") as fp: + blahaj_list.append(blahaj_entry) + json.dump(blahaj_list, fp) + + return "submitted" + +def display_context(fields_reponse): + print('Content-Type: text/html') + + html_text = """ + + + + + hehehe + + + + + +
+ + + + +
+ thing_to_replace +
+
+ + + + """ + + # Place html tags in the "thing_to_replace" spot + replace_text = "" + + if fields_reponse == "Blahaj name is required": + replace_text = """ +

Blahaj name required

+

Go back

+ """ + elif fields_reponse == "Already exists": + replace_text = """ +

Blahaj already added

+

Go back

+ """ + elif fields_reponse == "submitted": + replace_text = """ +

Blahaj submitted!

+ yippee! +

See it in the list!

+ """ + + html_text = html_text.replace("thing_to_replace", replace_text) + + print(html_text) + + +fields_reponse = handle_fields() +display_context(fields_reponse) -- cgit v1.2.3