initial project state, working and waiting for some more elaborated text
This commit is contained in:
194
pin.run
Executable file
194
pin.run
Executable file
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
print("Content-type: text/html\n")
|
||||
print("")
|
||||
import os
|
||||
import cgi
|
||||
from datetime import datetime
|
||||
#import locale
|
||||
#locale.setlocale(locale.LC_TIME, "de_DE")
|
||||
|
||||
origin_url = "https://augustiner-kantorei.de/pinnwand"
|
||||
database = "db.txt"
|
||||
|
||||
def get_arguments():
|
||||
"""Wrapper for cgi-environment.
|
||||
Takes no options, return dict of arguments
|
||||
"""
|
||||
rawargs = cgi.FieldStorage()
|
||||
args = {}
|
||||
|
||||
for i in rawargs:
|
||||
args[i] = rawargs.getvalue(i)
|
||||
|
||||
return args
|
||||
|
||||
args = get_arguments()
|
||||
|
||||
oversize=False
|
||||
if os.path.getsize(database) < 100 * 1024 * 1024:
|
||||
# only add entries if file size does not exceed 100 MiB
|
||||
|
||||
if "ort" in args and "name" in args and "comment" in args:
|
||||
# add entry
|
||||
try:
|
||||
zeit = datetime.timestamp(datetime(int(args["year"]), int(args["month"]), int(args["day"]), int(args["hour"]), int(args["minute"])))
|
||||
except:
|
||||
exit()
|
||||
try:
|
||||
with open(database, "a") as f:
|
||||
f.write("\t".join(
|
||||
[
|
||||
str(zeit),
|
||||
args["ort"].replace("\t", ""),
|
||||
args["name"].replace("\t", ""),
|
||||
args["comment"].replace("\t", "").replace("\n", " ").replace("\r", " "),
|
||||
datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
]
|
||||
))
|
||||
f.write("\n")
|
||||
except Exception as e:
|
||||
exit()
|
||||
else:
|
||||
oversize = True
|
||||
|
||||
# display current entries
|
||||
now = datetime.timestamp(datetime.now())
|
||||
with open(database, "r") as f:
|
||||
content = f.readlines()
|
||||
|
||||
table = ""
|
||||
for line in content:
|
||||
tstamp, ort, name, comment, timestamp = line.split("\t")
|
||||
if float(tstamp) < now:
|
||||
continue
|
||||
zeit = datetime.fromtimestamp(float(tstamp))
|
||||
hzeit = datetime.strftime(zeit, "%a, %d.%m.%Y %H:%M")
|
||||
table += f"<tr><td>{hzeit}</td><td>{ort}</td><td>{name}</td><td>{comment}</td></tr>"
|
||||
|
||||
print(f"""
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h2>Überschrift</h2>
|
||||
<div class="box">
|
||||
<h2>Terminangebote</h2>
|
||||
<table border="1" style="color:#cecece">
|
||||
<tr><th>Zeit</th><th>Ort</th><th>Name</th><th>Bemerkung</th></tr>
|
||||
{table}
|
||||
</table>
|
||||
|
||||
<br><br>
|
||||
|
||||
<h2>Neuer Eintrag</h2>
|
||||
""")
|
||||
if oversize:
|
||||
print("neuer Eintrag derzeit nicht möglich, Datei voll.")
|
||||
else:
|
||||
print("""
|
||||
<form action="pin.run" method="post" enctype="multipart/form-data">
|
||||
<select name="hour" size=1>
|
||||
<option>0</option>
|
||||
<option>1</option>
|
||||
<option>2</option>
|
||||
<option>3</option>
|
||||
<option>4</option>
|
||||
<option>5</option>
|
||||
<option>6</option>
|
||||
<option>7</option>
|
||||
<option>8</option>
|
||||
<option>9</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
<option>13</option>
|
||||
<option>14</option>
|
||||
<option>15</option>
|
||||
<option>16</option>
|
||||
<option>17</option>
|
||||
<option>18</option>
|
||||
<option>19</option>
|
||||
<option>20</option>
|
||||
<option>21</option>
|
||||
<option>22</option>
|
||||
<option>23</option>
|
||||
</select>
|
||||
:
|
||||
<select name="minute" size=1>
|
||||
<option>00</option>
|
||||
<option>05</option>
|
||||
<option>10</option>
|
||||
<option>15</option>
|
||||
<option>20</option>
|
||||
<option>25</option>
|
||||
<option>30</option>
|
||||
<option>35</option>
|
||||
<option>40</option>
|
||||
<option>45</option>
|
||||
<option>50</option>
|
||||
<option>55</option>
|
||||
</select>
|
||||
|
||||
<select name="day" size=1>
|
||||
<option>1</option>
|
||||
<option>2</option>
|
||||
<option>3</option>
|
||||
<option>4</option>
|
||||
<option>5</option>
|
||||
<option>6</option>
|
||||
<option>7</option>
|
||||
<option>8</option>
|
||||
<option>9</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
<option>13</option>
|
||||
<option>14</option>
|
||||
<option>15</option>
|
||||
<option>16</option>
|
||||
<option>17</option>
|
||||
<option>18</option>
|
||||
<option>19</option>
|
||||
<option>20</option>
|
||||
<option>21</option>
|
||||
<option>22</option>
|
||||
<option>23</option>
|
||||
<option>24</option>
|
||||
<option>25</option>
|
||||
<option>26</option>
|
||||
<option>27</option>
|
||||
<option>28</option>
|
||||
<option>29</option>
|
||||
<option>30</option>
|
||||
<option>31</option>
|
||||
</select>
|
||||
.
|
||||
<select name="month" size=1>
|
||||
<option>1</option>
|
||||
<option>2</option>
|
||||
<option>3</option>
|
||||
<option>4</option>
|
||||
<option>5</option>
|
||||
<option>6</option>
|
||||
<option>7</option>
|
||||
<option>8</option>
|
||||
<option>9</option>
|
||||
<option>10</option>
|
||||
<option>11</option>
|
||||
<option>12</option>
|
||||
</select>
|
||||
.
|
||||
<select name="year" size=1>
|
||||
<option>2021</option>
|
||||
</select>
|
||||
Zeit (hh:mm DD.MM.YYYY) <br>
|
||||
<input type="text" name="ort" placeholder="Ort" /> Ort<br />
|
||||
<input type="text" name="name" placeholder="Name" /> Name<br />
|
||||
<input type="text" name="comment" placeholder="Bemerkung" /> Bemerkung<br />
|
||||
<input type="submit" name="Absenden" value="Absenden" />
|
||||
</form>
|
||||
""")
|
||||
print("</div><div class=foot>Augustiner-Pinnwand - ein Service von <a href=https://dukun.de>dukun.de</a><br><a href=mailto:pinnwandrueckmeldung@augustiner-kantorei.de>Rückmeldung</a></div></body> </html>")
|
||||
|
||||
Reference in New Issue
Block a user