This commit is contained in:
lda committed 2024-10-20 01:59:59 +07:00
1 parent a8e5c26d55
commit dbebf03250
7 files changed
+225 -47

No files matched your search

+2
View File
@@ -31,6 +31,8 @@ share/python-wheels/
venv/ venv/
env/ env/
ENV/ ENV/
.venv/
# oversight of year
# IDEs and editors # IDEs and editors
.vscode/ .vscode/
+5 -5
View File
@@ -6,17 +6,17 @@ go dam
import http.server as serverhttp import http.server as serverhttp
from the_server_handler import ServerLogic, connectionSettings, get_that_connection from the_server_handler import ServerLogic, connectionSettings, get_that_connection
import mysql.connector as sqlcon
# import mysql.connector as sqlcon
import sys import sys
if not ( if not (sys.version_info >= (3, 11)):
sys.version_info.major > 3
or (sys.version_info.major == 3 and sys.version_info.minor >= 11)
):
raise Exception(f"python 3.11 up, u running {sys.version}") raise Exception(f"python 3.11 up, u running {sys.version}")
PORT = 8088 PORT = 8088
def runServer(): def runServer():
# while True: # while True:
# connectio,e = get_that_connection(**connectionSettings) # connectio,e = get_that_connection(**connectionSettings)
Regular → Executable
+89 -18
View File
@@ -1,4 +1,6 @@
import http.server as serverhttp import http.server as serverhttp
# import urllib.parse
import warnings import warnings
# import chardet # import chardet
@@ -13,6 +15,8 @@ import mysql.connector as sqlcon
# from mysql.connector import errorcode # from mysql.connector import errorcode
from dotenv import dotenv_values from dotenv import dotenv_values
from urllib import parse as urlparse # lmao the normal person from urllib import parse as urlparse # lmao the normal person
# import urllib
import json import json
from functools import wraps from functools import wraps
from pathlib import Path from pathlib import Path
@@ -24,14 +28,24 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler): ...
webrootdir = "webRoot" webrootdir = "webRoot"
curdir = "/home/opc/Desktop/pythonprac"
if (morecurdir := os.getcwd()) != curdir:
print(
"wrning, not ran from",
curdir,
"dont do that! ( curdir was",
morecurdir,
"now it is uh)",
)
os.chdir(curdir)
if os.path.isdir(webrootdir): # unfuckable if os.path.isdir(webrootdir): # unfuckable
os.chdir(webrootdir) # move to safe part of world os.chdir(webrootdir) # move to safe part of world
curdir = os.path.curdir or os.getcwd() curdir = os.path.curdir or os.getcwd()
print(os.path.curdir, os.getcwd()) print(os.path.curdir, os.getcwd())
from things import ( from things import (
process_datetime_DICTS, process_datetime_DICTS,
process_datetime_tuples, # process_datetime_tuples,
funny_tuples_to_dicts_processor, # funny_tuples_to_dicts_processor,
getnewdicttranslate, getnewdicttranslate,
) )
@@ -252,21 +266,23 @@ def openFileManually(
print(path) print(path)
if not path.exists(): if not path.exists():
theGuy.header_setup(rescode.NOT_FOUND) theGuy.header_setup(rescode.NOT_FOUND)
if path.is_dir(): theGuy.wfile.write(notfound404)
return
elif path.is_dir():
path /= defaultFile path /= defaultFile
if not path.is_file(): if not path.is_file():
theGuy.header_setup(rescode.NOT_FOUND) theGuy.header_setup(rescode.NOT_FOUND)
theGuy.wfile.write(notfound404) theGuy.wfile.write(notfound404)
return
print(path) print(path)
fileMime, fileEncoding = mimetypes.guess_type(path) fileMime, fileEncoding = mimetypes.guess_type(path)
print(fileMime, fileEncoding) print(fileMime, fileEncoding)
finalMime = fileMime finalMime = fileMime
a = {} headers = headers or dict()
if headers: if gay := next(
gay = next(
(i for i in reversed(headers) if i.casefold() == "content-type"), None (i for i in reversed(headers) if i.casefold() == "content-type"), None
) ):
if gay:
print(gay, headers[gay]) print(gay, headers[gay])
headerMime = headers[gay] headerMime = headers[gay]
if headerMime not in mimetypes.types_map.values(): if headerMime not in mimetypes.types_map.values():
@@ -276,15 +292,68 @@ def openFileManually(
) )
finalMime = headerMime finalMime = headerMime
a["content-type"] = finalMime
headers |= a
theGuy.header_setup(headers=headers or a)
with open(path, "rb") as file: with open(path, "rb") as file:
theGuy.wfile.write(file.read()) asfd = file.read()
headers |= {(gay or "content-type"): finalMime,
"content-length": str(len(asfd))
}
theGuy.header_setup(headers=headers)
return return
def openFileSemiAutomatically(
theGuy: ServerLogic,
webDir: str,
defaultFile: str | list[str] | tuple[str] | None = "index.html",
dir: str | None = None,
headers: dict | None = None,
rootDir: str | None = curdir,
):
c = bytes()
pf = Path()
a = Path(dir) if dir else Path(webDir.lstrip("/"))
if not a.exists():
c = notfound404
elif a.is_dir():
if type(defaultFile) == str:
p = a / defaultFile
if p.is_file():
with open(p, "rb") as f:
c = f.read()
pf = p
elif type(defaultFile) in (list, tuple):
for i in defaultFile:
p = a / i
if p.is_file():
with open(p, "rb") as f:
c = f.read()
pf = p
break
else:
c = notfound404
elif a.is_file():
with open(a, "rb") as f:
c = f.read()
else:
c = notfound404
mt, enct = mimetypes.guess_type(pf)
if not headers:
headers = {}
if mt.split("/")[0] == "text":
fg = mt + "; charset=utf-8"
theGuy.header_setup(
200,
headers
| {
"content-type": fg or mt,
# "content-length": str(len(c))
},
)
theGuy.wfile.write(c)
## USE THE @ if you know how ## USE THE @ if you know how
### i surely dont know how ### i surely dont know how
@@ -295,13 +364,14 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler):
super().__init__(*a, **kw) super().__init__(*a, **kw)
def reallyEveryTime(self) -> tuple: def reallyEveryTime(self) -> tuple:
# print("all headers:\n", self.headers) print("all headers:\n", self.headers)
print("the path is : ", self.path) print("the path is : ", self.path)
print( print(
"connected at: ", "connected at: ",
self.headers.get("X-Forwarded-For", "directly").split(", ")[0], self.headers.get("X-Forwarded-For", "directly").split(", ")[0],
) )
print(urlparse.urlparse(self.path)) print(urlparse.urlparse(self.path))
# openFileSemiAutomatically(self, self.path)
# table = 'tbale' # table = 'tbale'
# print("there is no" ,table,ifTableInDB(db_name, table)) # print("there is no" ,table,ifTableInDB(db_name, table))
@@ -319,19 +389,20 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler):
print("gato") print("gato")
raise SystemExit("truly the /close") raise SystemExit("truly the /close")
def header_setup( def header_setup( # please not be bad
self, self,
code: int | rescode = rescode.OK, code: int | rescode = rescode.OK,
headers: dict = {"Content-type": "text/html"}, headers: dict[str, str] = {"Content-type": "text/html"},
): ):
""" """
code as int and headers as keyvalue pairs. code as int and headers as keyvalue pairs (of strings btw)
""" """
self.send_response(code) self.send_response(code)
if headers is not None:
for key, value in headers.items(): for key, value in headers.items():
self.send_header(key, value) # why! self.send_header(key, value) # why!
else:
pass
self.end_headers() self.end_headers()
def do_GET(self): def do_GET(self):
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>lđa testing</title>
<link type="text/css" rel="stylesheet" href="./index/style.css" />
<!-- huh? what? -->
<script type="module" src="./index/script.js" defer></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" />
<!-- real -->
</head>
<body>
<header>
<h1>front end design:</h1>
</header>
<nav>
<ul>
<li>
<a href="/about.html">about</a>
</li>
<li>
<a href="/browse.html">view</a>
</li>
<li>
<a href="/view.html">read</a>
</li>
<li>
<a href = "/">write</a>
</li>
</ul>
</nav>
<main>
<h1>real!</h1>
<section>
<p>bad made by lda</p>
</section>
</main>
<footer>
<h1>by <a href="//ldlda.com">lđa</a></h1>
<p>very fragile</p>
</footer>
</body>
</html>
+22 -13
View File
@@ -81,10 +81,10 @@ const typingHandler = (f) => (e) => {
// } // }
if ( if (
// !justUpdated && // !justUpdated &&
!updateTimeout) { !updateTimeout
) {
// justUpdated = true; // justUpdated = true;
updateTimeout = setTimeout(() => { updateTimeout = setTimeout(() => {
try { try {
f(); f();
document.getElementById("errorfrommd").textContent = null; document.getElementById("errorfrommd").textContent = null;
@@ -93,11 +93,10 @@ const typingHandler = (f) => (e) => {
} }
// justUpdated = false; // justUpdated = false;
clearTimeout(updateTimeout) clearTimeout(updateTimeout);
updateTimeout = undefined; updateTimeout = undefined;
}, updatingInterval); }, updatingInterval);
} }
}; };
const mdUpdatingHandler = typingHandler(updateMD); //why const mdUpdatingHandler = typingHandler(updateMD); //why
document.getElementById("auto_translate").addEventListener("change", (e) => { document.getElementById("auto_translate").addEventListener("change", (e) => {
@@ -221,11 +220,18 @@ form.addEventListener("submit", (e) => {
let htmlContent = ""; let htmlContent = "";
const tableContent = document.getElementById("tbale"); const tableContent = document.getElementById("tbale");
const actualTableContent = document.getElementById("updatedget"); const actualTableContent = document.getElementById("updatedget");
const cdc = document.createElement("div");
cdc.textContent = "sdfasdfasdfsdfaasdfasdfasdfasdfasdfasfdasdfasdf";
document.getElementsByTagName("main")[0].appendChild(cdc);
const GETendp = (_) =>
fetch(address + "endp") const GETendp = (_) => {
.then((response) => response.json()) const response = fetch(address + "endp") // hmm ahsdflakhwfuisdgaf
.then((json) => { .then(
(response) => response.json(), e => console.log(e)
)
.then(
(json) => {
console.log(json); console.log(json);
// htmlContent = "<tbody>"; // htmlContent = "<tbody>";
@@ -255,9 +261,12 @@ const GETendp = (_) =>
// htmlContent += "</tbody>"; // htmlContent += "</tbody>";
actualTableContent.innerHTML = htmlContent; actualTableContent.innerHTML = htmlContent;
htmlContent = '' htmlContent = "";
}) tableContent.parentElement.hidden = false; // lmaop
.catch((e) => console.error(e)); },
(what) => console.log(what)
)
}
await GETendp();
GETendp();
tableContent.parentElement.hidden = false;
+13 -11
View File
@@ -1,8 +1,3 @@
* {
box-sizing: border-box;
overflow-wrap: break-word;
}
:root { :root {
--dark-enough: #303030; --dark-enough: #303030;
--color-1: #8bafed; --color-1: #8bafed;
@@ -11,7 +6,10 @@
--color-4: #ff7100; --color-4: #ff7100;
--challenge: "use dem colors"; --challenge: "use dem colors";
} }
*, *::before, *::after {
box-sizing: border-box;
overflow-wrap: break-word ;
}
body { body {
background-color: white; background-color: white;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='215' height='215' viewBox='0 0 200 200'%3E%3Cpolygon fill='%23FAF7F5' fill-opacity='0.58' points='100 0 0 100 100 100 100 200 200 100 200 0'/%3E%3C/svg%3E"); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='215' height='215' viewBox='0 0 200 200'%3E%3Cpolygon fill='%23FAF7F5' fill-opacity='0.58' points='100 0 0 100 100 100 100 200 200 100 200 0'/%3E%3C/svg%3E");
@@ -24,12 +22,15 @@ body {
grid-template-rows: 100px 1fr 300px; grid-template-rows: 100px 1fr 300px;
grid-template-areas: "head head" "nav main" "nav foot"; grid-template-areas: "head head" "nav main" "nav foot";
max-width: 100%; max-width: 100%;
} /* width: 100%; */
body,
html {
width: 100%;
} }
/* do i know what im doing */
html {
max-width: 100vw;
max-height: 100vh;
}
body > * { body > * {
margin-inline: auto; margin-inline: auto;
border-radius: 15px; border-radius: 15px;
@@ -112,7 +113,8 @@ footer {
background-color: mistyrose; background-color: mistyrose;
padding: 0.5em; padding: 0.5em;
border-radius: 6px; border-radius: 6px;
max-width: calc(100% - 1em); /* max-width: calc(100% - 1em); */
/* why */
margin-inline: auto; margin-inline: auto;
display: flex; display: flex;
+47
View File
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>lđa testing</title>
<link type="text/css" rel="stylesheet" href="./index/style.css" />
<!-- huh? what? -->
<script type="module" src="./index/script.js" defer></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" />
<!-- real -->
</head>
<body>
<header>
<h1>front end design:</h1>
</header>
<nav>
<ul>
<li>
<a href="/about.html">about</a>
</li>
<li>
<a href="/browse.html">view</a>
</li>
<li>
<a href="/view.html">read</a>
</li>
<li>
<a href = "/">write</a>
</li>
</ul>
</nav>
<main>
<h1>real!</h1>
<section>
<p>bad made by lda</p>
</section>
</main>
<footer>
<h1>by <a href="//ldlda.com">lđa</a></h1>
<p>very fragile</p>
</footer>
</body>
</html>