Whether it's Python or whatever, it's not interesting and won't continue unless you make something that works for the time being. Let's create a simple submission form on a rental server such as Sakura Internet where Python scripts run on CGI.
sendtext.cgi
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys, codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
from datetime import datetime
import cgi
import csv
print "Content-Type: text/html\n"
print """
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
"""
print """
</head>
<body>
"""
try:
form = cgi.FieldStorage()
words = form["word"].value
words = unicode(words,"utf-8")
today = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
f = open("date.txt", "ab")
writer = csv.writer(f, quoting=csv.QUOTE_ALL)
writer.writerow([words,today])
f.close()
print "<p>"+ words + ": " + today + "</p>"
except (TypeError, KeyError):
print "<p>"+u"There is an error in the input item"+"</p>"
print """
</body>
</html>
"""
Write a Python script with this image. The extension is .cgi because it is supposed to work with CGI. It is a simple script that receives the form sent from index.html, attaches the date and time it was sent to it, and saves it in CSV format in .txt.
HTML file
<form method="POST" action="cgi-bin/index.cgi">
<textarea name="word"></textarea>
<p><input type="submit" value="Send"></p>
</form>
Such an image would be OK.
Recommended Posts