[PYTHON] Zeitplantabelle

Ausführungsumgebung

Ubuntu Stdio 18.04LTS Python 3.6.9 Firefox 71.0 (64-Bit)

Referenzierte Site

Erstellen Sie Ihre eigene TODO-App mit Python https://news.mynavi.jp/article/zeropython-57/

Versuchen Sie es mit JavaScript. Beispiel 11: Erstellen eines Kalenders http://home.e02.itscom.net/shouji/pc/js/p-11.html

Andere

schedule.png

Ich suche nach einer Möglichkeit, die Größe der Schaltfläche "Hinzufügen" zu ändern, kann sie jedoch nicht finden.

Die Gelegenheit zu machen

Ich las den Artikel "Lassen Sie uns Ihre eigene TODO-App mit Python erstellen" und begann, sie zu verwenden, weil ich dachte, dass sie als Zeitplantabelle verwendet werden könnte. Net ist eine Kombination aus Beispielcode von Amateuren im Net. Selbst wenn ich mit zunehmendem Alter lerne, wird es in weniger als einer Woche aus meinem Gedächtnis gelöscht, sodass ich ein Anfänger für alle Altersgruppen bin.

Was ich getan habe, ist die Sortierfunktion von Amateuren im Beispielprogramm von "Lassen Sie uns Ihre eigene TODO-App mit Python erstellen" (Wenn Leerzeichen mit halber und voller Breite vorhanden sind, werden die Linien getrennt, sodass Sie eine Verbindung mit einem Unterstrich herstellen müssen. ) Ich habe es hinzugefügt, weil es bequemer ist, eine Uhr und einen Kalender zu haben. Die meisten Proben sind so, wie sie im Netz sind. (Vielen Dank)

Es gibt keinen Code auf der Website "Machen wir Ihre eigene TODO-App mit Python", aber es gibt einen Link, über den Sie ihn herunterladen können. Laden Sie daher "Das 57. Programm hier" von dort herunter. Ich werde.

Es hat nicht so funktioniert wie es war, also musste ich es ein wenig reparieren. 1.data.txt ist nicht enthalten. Wenn Sie damit vertraut sind, können Sie es leicht finden, indem Sie sich den Code ansehen, aber ich weiß es nicht. Deshalb habe ich eine data.txt-Datei mit einer geeigneten Liste von Zeichen erstellt, aber es hat gut funktioniert.

  1. Ich denke, es hängt vom Betriebssystem ab, aber ändern Sie es in #! / Usr / bin / python3 in der ersten Zeile von todo.py.

    1. Unter Python2 (wahrscheinlich ohne Bibliothek) hat es nicht funktioniert. Ändern Sie daher die zweite Zeile von start.sh von Python ... in Python3 ... Für Windows ist es start.bat.
  2. Geben Sie start.sh die Ausführungsberechtigung. Geben Sie todo.py die Ausführungsberechtigung.

Wenn Sie nun start.sh ausführen, wird der einfache Webserver gestartet. Wenn Sie dann mit einem Browser auf "http: // localhost: 8000 / cgi-bin / todo.py" zugreifen, wird das Beispielprogramm gestartet und "Compliment TODO" angezeigt.

Ich habe zum ersten Mal erfahren, dass HP mit einem Python-Skript (Programm) angezeigt werden kann. (Aber es ist mühsam)

Ich habe eine Sortierung, eine Uhr und einen Kalender hinzugefügt.

python


#!/usr/bin/python3
# coding: UTF-8

FILE_DATA = "./data.txt"

with open(FILE_DATA) as f:
    s = f.read()
    s1=s.split() #Konvertiere str in List
    s1.sort() #Sortieren
    s = '\n'.join(s1) #Liste in str konvertieren

with open(FILE_DATA, mode='w') as f: #Schreiben
    f.write(s)

#Einstellungen für Japanisch erforderlich
import os, sys, io, cgi, re
sys.stdin, sys.stdout, sys.etderr =  [
    open(sys.stdin.fileno(),  'r', encoding='UTF-8'),
    open(sys.stdout.fileno(), 'w', encoding='UTF-8'),
    open(sys.stderr.fileno(), 'w', encoding='UTF-8')]
out = lambda s: print(s, end="\n")

form = cgi.FieldStorage()

#Überprüfen Sie die Parameter und verzweigen Sie den Prozess
def check_param():
    m = get_form('m', 'show')
    if m == "show":
        mode_show()
    elif m == "add":
        mode_add()
    elif m == "rm":
        mode_remove()
    else:
        out_html("Falscher Parameter")

#Zeigen Sie eine Liste von TODO an
def mode_show():
    items = load_items()
    t = "<h1>Mein Kalender</h1>"

    t += '<div class="div_1">'
    t += '<div class="div_2">'
    t += "<div id='items'>"

    t += '<h2 id="time"></h2>' #von hier
    t += "<script>"
    t += "time();"
    t += "function time(){"
    t += "    var now = new Date();"
    t += '    document.getElementById("time").innerHTML = now.toLocaleString();'
    t += "}"
    t += "setInterval('time()',1000);"
    t += "</script>"  #Uhr so weit

    t += "<form><p class='frm'>Pläne: "  #von hier
    t += input_tag('text', 'todo', '')
    t += input_tag('hidden', 'm', 'add')
    t += input_tag('submit', '', 'hinzufügen')
    t += "</p></form></div>"  #Bisher geplantes zusätzliches Teil

    for no, it in enumerate(items):  #Zeitplan
        k = "todo.py?m=rm&no="+str(no)
        a = "<a href='" + k + "'>❎️</a> "
        t += "<p>" + a + it + "</p>"

    t += "</div>"
    t += '<div class="div_2">'   #Kalender
    t += ' <script type="text/javascript"><!--\n'
    t += 'var now = new Date();'
    t += 'var year = now.getFullYear();'
    t += 'var month = now.getMonth() + 1;'
    t += 'var today = now.getDate();'
    t += 'now.setDate(1);'
    t += 'var startDay = now.getDay();'
    t += 'var monthdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);'
    t += 'var dateMax = monthdays[month - 1];'
    t += 'if (month == 2 && ((year%4 == 0 && year%100 != 0) || year%400 == 0)) dateMax = 29;'
    t += 'var holidays = new Array();'
    t += 'for (var i = 0; i <= dateMax; i++) holidays[i] = 0;'
    t += 'var Holidays1 = new Array(1,1, 2,11, 2,23, 3,21, 4,29, 5,3, 5,4, 5,5, 9,23, 11,3, 11,23);'
    t += 'var firstSunday = (startDay == 0) ? 1: 8 - startDay;'
    t += 'for (i = 0; i < Holidays1.length; i += 2) {'
    t += 'if (Holidays1[i] == month) {'
    t += 'holidays[Holidays1[i+1]] = 1;'
    t += 'for (var j = firstSunday; j < dateMax; j += 7)'
    t += 'if (Holidays1[i+1] == j ) { holidays[j+1] = 1; break; } '
    t += '}'
    t += '}'
    t += 'var Holidays2 = new Array(1,2, 7,3, 9,3, 10,2);'
    t += 'var firstMonday = (startDay < 2) ? 2 - startDay: 9 - startDay;'
    t += 'for (i = 0; i < Holidays2.length; i += 2)'
    t += 'if (Holidays2[i] == month) holidays[(Holidays2[i+1] - 1) * 7 + firstMonday] = 1;'
    t += 'var days = new Array("Tag", "Mond", "Feuer", "Wasser", "Holz", "Geld", "Boden");'
    t += '''document.write("<table class='calen'>\\n<tr class='bg1'><th colspan=7>" + year + "Jahr" + month + "Mond</th></tr>\\n");'''
    t += '''document.write("<tr class='bg2'><th class='sun'>" + days[0] + "</th>");'''
    t += 'for (i = 1; i < 6; i++) document.write("<th>" + days[i] + "</th>");'
    t += '''document.write("<th class='sat'>" + days[6] + "</th></tr>\\n");'''
    t += 'var col = 0, s1;'
    t += 'if (startDay > 0) {'
    t += 'document.write("<tr>");'
    t += 'for ( ; col < startDay; col++) document.write("<td>&nbsp;</td>");'
    t += '}'
    t += 'for (i = 1; i <= dateMax; i++) {'
    t += 'if (col == 0) document.write("<tr>");'
    t += 'if (i == today) {'
    t += '''if (holidays[i] == 1 || col == 0) s1 = "<td class='today sun'>";'''
    t += '''else if (col == 6) s1 = "<td class='today sat'>";'''
    t += '''else s1 = "<td class='today'>";'''
    t += '}'
    t += '''else if (holidays[i] == 1 || col == 0) s1 = "<td class='sun'>";'''
    t += '''else if (col == 6) s1 = "<td class='sat'>";'''
    t += 'else s1 = "<td>";'
    t += 'document.write(s1 + i + "</td>");'
    t += 'if (col == 6) { document.write("</tr>\\n"); col = 0; } else col++;'
    t += '}'
    t += 'if (col != 0) {'
    t += 'for ( ; col < 7; col++) document.write("<td>&nbsp;</td>");'
    t += 'document.write("</tr>");'
    t += '}'
    t += 'document.write("</table>");'
    t += '//-->'
    t += '</script>'
    t += '</div>'
    t += '</div>'

    out_html(t)

#Fügen Sie ein neues TODO hinzu
def mode_add():
    todo = get_form('todo', '')
    if todo == '':
        out_html('Kein Text zum Hinzufügen')
        return
    items = load_items()
    items.append(todo)
    save_items(items)
    s = "<div id='items'><p>Geschrieben.<br/>"
    s += "Toll! Ich gebe immer mein Bestes!</p>"
    s += "<a href='todo.py'>Rückkehr</a></div>"
    out_html(s)

#Element löschen
def mode_remove():
    no = int(get_form('no', '-1'))
    if no < 0:
        out_html('Falsche Nummer')
        return
    items = load_items()
    del items[no]
    save_items(items)
    out_html('Es wurde gelöscht.<a href="todo.py">Rückkehr</a>')

#Element laden
def load_items():
    text = "test1\ntest2\ntest3\n"
    if os.path.exists(FILE_DATA):
        with open(FILE_DATA, 'rt', encoding="utf-8") as f:
            text = f.read()
    items = text.strip().split("\n")
    return items

#Artikel speichern
def save_items(items):
    text = "\n".join(items)
    with open(FILE_DATA, 'wt', encoding="utf-8") as f:
        f.write(text)

#HTML ausgeben
def out_html(html):
    out("Content-type: text/html; charset=utf-8")
    out("")
    out("<html><head>")
    out("<title>Mein Kalender</title>")
    out('<link href="/style.css" rel="stylesheet">')
    out("</head><body>" + html)
    out("</body></html>")

# <input>Gibt ein Tag zurück
def input_tag(type, name, value):
    s = '<input type="{}" name="{}" value="{}">'
    return s.format(type, name, value)

#Ruft den Wert des Formulars ab und gibt ihn zurück
def get_form(name, defvalue):
    if name in form:
        return form[name].value
    return defvalue

if __name__ == '__main__':
    check_param()

style.css

h1 {
    font-size: 24px;
    background-color: #f05090;
    padding: 8px;
    color: white;
}

#items {
	margin: 12px;
}

#items p {
	font-size: 16px;
	border-bottom: 4px solid #f09090;
	border-right: 6px solid #f09090;
	padding: 12px;
	margin: 12px;
	background-color: #fff0f0;
}
#items a {
	padding: 8px;
	text-decoration: none;
}
#items input[type=text] {
	width: 300px;
	font-size: 16px;
	padding: 8px;
}
#items input[type=submit] {
	font-size: 24px;
	padding: 8px;
	width: 60px;
	margin: 8px;
}

#items p.frm {
	background-color: #fff0ff;
}

.div_1 {
    padding:  10px;             /*Randspezifikation*/
    display: flex;              /*Machen Sie es zu einer Flexbox*/
}
 
.div_2 {
    padding: 10px;
    margin:  10px;              /*Äußerer Rand*/
    border-radius:  5px;        /*Abgerundete Ecken*/
    font-size: 30px;            /*Geben Sie die Schriftgröße an*/

}
 
.div_2:nth-child(1) {
    flex-basis:  1100px;         /*Breitenspezifikation*/

}
 
.div_2:nth-child(2) {
    flex-basis:  200px;         /*Breitenspezifikation*/
    text-align:  center;        /*Zeichenzentrierung*/
}

/*Kalender*/
table.calen { border-collapse:collapse; font-size:11pt; background-color:#fffafa; color:black; }
table.calen th { border:1px solid #a57d6b; height:30px; }
table.calen td { border:1px solid #a57d6b; text-align:center; height:30px; width:30px; }
table.calen .sat { color:blue; }
table.calen .sun { color:red; }
table.calen .today { background-color:#ffe4ce; font-weight:bold; color:black; }
table.calen tr.bg1 { background-color:#f5f5dc; color:black; }
table.calen tr.bg2 { background-color:#eeeeee; color:black; }

Recommended Posts

Zeitplantabelle