blob: 4c2e1b60c6ab68b89cc9602d4cd9fbaa53bd0a75 (
plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#!/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")}
# Already been added.
for blahaj in blahaj_list:
if blahaj["name"] == blahaj_entry["name"] and blahaj["info"] == blahaj_entry["info"]:
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 = """
<!DOCTYPE html>
<html>
<head>
<title>hehehe</title>
<style>
body {
color: black;
background-image: url('../images/blahaj_background.jpg');
}
table {
color: black;
background-color: #bebebe;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 10px;
margin-right: 10px;
}
</style>
</head>
<body>
<center>
<table border="1" width="40%">
<tr>
<td>
thing_to_replace
</td>
</tr>
</table>
</center>
</body>
</html>
"""
# Place html tags in the "thing_to_replace" spot
replace_text = ""
if fields_reponse == "Blahaj name is required":
replace_text = """
<h1>Blahaj name required</h1>
<h2><a href=\"../submit_blahaj_info.html\">Go back</a></h2>
"""
elif fields_reponse == "Already exists":
replace_text = """
<h1>Blahaj already added</h1>
<h2><a href=\"../submit_blahaj_info.html\">Go back</a></h2>
"""
elif fields_reponse == "submitted":
replace_text = """
<h1>Blahaj submitted!</h1>
<img src="https://media1.tenor.com/m/FKtdcMXKBhsAAAAC/yippee-happy.gif" alt="yippee!" width="90%">
<h2><a href=\"blahaj_list.cgi\">See it in the list!</a></h2>
"""
html_text = html_text.replace("thing_to_replace", replace_text)
print(html_text)
fields_reponse = handle_fields()
display_context(fields_reponse)
|