diff options
author | nathansmith <nathansmith@posteo.com> | 2025-05-14 07:30:29 -0600 |
---|---|---|
committer | nathansmith <nathansmith@posteo.com> | 2025-05-14 07:30:29 -0600 |
commit | b1b9df6726332f1d2b635fe63019df10029e6c77 (patch) | |
tree | 6e01b24a3ce020136d70dff74933fdc71b699b76 | |
parent | 32af1db1f3fdb1a98b767fc6200386f2130de798 (diff) |
Finished up scheme cgi
-rwxr-xr-x | cgi-bin/guest_book.cgi | 49 | ||||
-rwxr-xr-x | cgi-bin/guest_book.py | 164 | ||||
-rw-r--r-- | images/getimiskon.png | bin | 0 -> 2899 bytes | |||
-rw-r--r-- | index.html | 7 |
4 files changed, 34 insertions, 186 deletions
diff --git a/cgi-bin/guest_book.cgi b/cgi-bin/guest_book.cgi index d527d2d..f8caccf 100755 --- a/cgi-bin/guest_book.cgi +++ b/cgi-bin/guest_book.cgi @@ -62,7 +62,9 @@ (guest `(("name" . ,name) ("url" . ,url) ("message" . ,message) - ("date" . ,(date->string (current-date) "~B, ~d ~Y"))))) + ("date" . ,(date->string (current-date) "~B, ~d ~Y")))) + (not-already-added #t)) + (if (file-exists? guest-book-json-file) (call-with-input-file guest-book-json-file (lambda (fp) @@ -76,28 +78,35 @@ (letrec ((check-if-already-added (lambda (guests) (unless (eq? guests '()) - (unless (letrec ((guest-item-compare - (lambda (index) - (if (< index (- (length guest) 1)) - (and (cdr (list-ref (car guests) - index)) - (cdr (list-ref guest index)) - (guest-item-compare - (+ index 1))) ;; Unholyness - - (check-if-already-added (cdr guests)))))) + (cond ((compare-guests 0 (car guests) guest) + (set! not-already-added #f)) + (else + (check-if-already-added (cdr guests))))))) + (compare-guests + (lambda (index guest1 guest2) + (and (string= (cdr (list-ref guest1 index)) + (cdr (list-ref guest2 index))) + (cond ((< index 3) + (compare-guests (+ index 1) guest1 guest2)) + (else #t)))))) (check-if-already-added guest-book)) ;; Add guest to guest-book - (cond ((eq? guest-book '()) - (set! guest-book (list guest))) - (else - (append! guest-book (list guest)))) - - ;; Write guest book to json - (call-with-output-file guest-book-json-file - (lambda (fp) - (scm->json (list->vector guest-book) fp))))) + (cond (not-already-added + (cond ((eq? guest-book '()) + (set! guest-book (list guest))) + (else + (append! guest-book (list guest)))) + + ;; Write guest book to json + (call-with-output-file guest-book-json-file + (lambda (fp) + (scm->json (list->vector guest-book) fp))) + + (display "<p>You been added to the guest book yippe (:</p>\ +<img src=\"../images/yippee.gif\" alt=\"yippee!\"/>\n")) + (else + (display "You already been added\n"))))) (define (handle-fields) (let ((form (get-form))) diff --git a/cgi-bin/guest_book.py b/cgi-bin/guest_book.py deleted file mode 100755 index 97a7403..0000000 --- a/cgi-bin/guest_book.py +++ /dev/null @@ -1,164 +0,0 @@ -#! /usr/bin/env python3 - -import cgi -import json -import datetime -import html - -def handle_fields(): - form = cgi.FieldStorage() - - name = form.getvalue("name") - url = form.getvalue("url") - message = form.getvalue("message") - - # Nothign was submitted. - if name is None and url is None and message is None: - return "" - - if name is None: - return "<p>name is required</p>" - elif message is None: - return "<p>please write a silly something (:</p>" - - url = "" if url is None else url - - # Make the names safe. - name = html.escape(name) - url = html.escape(url) - message = html.escape(message) - - guest_book = [] - - # Open data if already there. - try: - with open("guest_book.json", "r") as fp: - guest_book = json.load(fp) - except FileNotFoundError: - pass - - # Already in list. - for guest in guest_book: - if guest["name"] == name and guest["url"] == url and guest["message"] == message: - return "<p>You already been added</p>" - - date = datetime.datetime.now() - guest_entry = {"name": name, "url": url, "message": message, "date": date.strftime("%B, %d %Y")} - - # Dump guest to file. - with open("guest_book.json", "w") as fp: - guest_book.append(guest_entry) - json.dump(guest_book, fp, indent=4) - - return "<p>You been added to the guest book yippe (:</p><img src=\"../images/yippee.gif\" alt=\"yippee!\"/>" - -def get_guest_html_from_list(): - guest_html = "" - - try: - with open("guest_book.json", "r") as fp: - for guest in json.load(fp)[::-1]: - guest_table = """ - <table border="1" width="60%"> - <tr> - <td> - <b>{name}</b> <a href="{url}" target="_blank">{url}</a> --- signed {date} - </td> - </tr> - - <tr> - <td><p>{message}</p></td> - </tr> - </table> - """ - - guest_table = guest_table.format(name=guest["name"], url=guest["url"], - date=guest["date"], message=guest["message"]) - guest_html += guest_table - except FileNotFoundError: - guest_html = """ - <table border="1" width="60%"> - <tr> - <td> - <p>No guest have been added ): But you can be the first!</p> - </td> - </tr> - </table> - """ - - return guest_html - -def display_html(fields_reponse): - print("Content-Type: text/html") - - html_text = """ - <!DOCTYPE html> - <html> - - <head> - <title>Guest Book</title> - - <style> - - body {{ - color: black; - background-image: url('../images/guest_book_background.png'); - }} - - table {{ - color: black; - background-color: #bebebe; - margin-top: 10px; - margin-bottom: 10px; - margin-left: 10px; - margin-right: 10px; - }} - - </style> - </head> - - <body> - <a href="../index.html"><img src="../images/back_home.png" alt="Back to home page"/></a> - - <center> - <table border="1" width="60%"> - <tr> - <td> - <h3>Sign my fucking guest book</h3> - <form action = "guest_book.cgi" method = "get"> - <lable for = "name" maxlength="100">Name</lable> - <input type = "text" name = "name"/> - <br/> - <lable for = "url" maxlength="256">Website (Optional)</lable> - <input type = "text" name = "url"/> - <br/><br/> - <lable for = "message">Write a little silly something</lable> - <br/> - <textarea type = "text" name = "message" rows = "4" cols = "40" maxlength="512"></textarea> - <br/> - <input type = "submit" value = "Fucking submit"> <b>You can't delete/edit it afterwards</b> - </form> - <p> - <b>Be nice! Dont be a fucking ass.</b> - </p> - {fields_reponse} - </td> - </tr> - </table> - - {guest_html} - </center> - </body> - </html> - """ - - html_text = html_text.format( - fields_reponse=fields_reponse, - guest_html=get_guest_html_from_list() - ) - - print(html_text) - -fields_reponse = handle_fields() -display_html(fields_reponse) - diff --git a/images/getimiskon.png b/images/getimiskon.png Binary files differnew file mode 100644 index 0000000..e2b5ddc --- /dev/null +++ b/images/getimiskon.png @@ -13,7 +13,7 @@ color: black; background-color: #bebebe; margin-top: 10px; - margin-bottom: 10px; + margin-bottom: 10px; margin-left: 10px; margin-right: 10px; } @@ -184,7 +184,10 @@ "images/small_dog3.png" alt="Another small dog"> </td> </tr> - </table><a href="https://yesterweb.org/no-to-web3" target= + </table> + <a href="https://getimiskon.xyz" target="_blank"> + <img src="images/getimiskon.png" alt="getimiskon's space"/></a> + <a href="https://yesterweb.org/no-to-web3" target= "_blank"><img src="images/roly-saynotoweb3.gif" alt= "keep the web free"></a> <a href="http://wiby.org/" target= "_blank"><img src="images/wiby.gif" alt="wiby"></a> <a href= |