#!/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 = """
thing_to_replace |