broken
This commit is contained in:
1 parent
a8e5c26d55
commit
dbebf03250
7 files changed
+260
-82
No files matched your search
@@ -31,6 +31,8 @@ share/python-wheels/
|
||||
venv/
|
||||
env/
|
||||
ENV/
|
||||
.venv/
|
||||
# oversight of year
|
||||
|
||||
# IDEs and editors
|
||||
.vscode/
|
||||
|
||||
+5
-5
@@ -6,17 +6,17 @@ go dam
|
||||
import http.server as serverhttp
|
||||
|
||||
from the_server_handler import ServerLogic, connectionSettings, get_that_connection
|
||||
import mysql.connector as sqlcon
|
||||
|
||||
# import mysql.connector as sqlcon
|
||||
|
||||
import sys
|
||||
|
||||
if not (
|
||||
sys.version_info.major > 3
|
||||
or (sys.version_info.major == 3 and sys.version_info.minor >= 11)
|
||||
):
|
||||
if not (sys.version_info >= (3, 11)):
|
||||
raise Exception(f"python 3.11 up, u running {sys.version}")
|
||||
|
||||
PORT = 8088
|
||||
|
||||
|
||||
def runServer():
|
||||
# while True:
|
||||
# connectio,e = get_that_connection(**connectionSettings)
|
||||
|
||||
Regular → Executable
+100
-29
@@ -1,4 +1,6 @@
|
||||
import http.server as serverhttp
|
||||
|
||||
# import urllib.parse
|
||||
import warnings
|
||||
|
||||
# import chardet
|
||||
@@ -13,6 +15,8 @@ import mysql.connector as sqlcon
|
||||
# from mysql.connector import errorcode
|
||||
from dotenv import dotenv_values
|
||||
from urllib import parse as urlparse # lmao the normal person
|
||||
|
||||
# import urllib
|
||||
import json
|
||||
from functools import wraps
|
||||
from pathlib import Path
|
||||
@@ -24,14 +28,24 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler): ...
|
||||
|
||||
|
||||
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
|
||||
os.chdir(webrootdir) # move to safe part of world
|
||||
curdir = os.path.curdir or os.getcwd()
|
||||
print(os.path.curdir, os.getcwd())
|
||||
from things import (
|
||||
process_datetime_DICTS,
|
||||
process_datetime_tuples,
|
||||
funny_tuples_to_dicts_processor,
|
||||
# process_datetime_tuples,
|
||||
# funny_tuples_to_dicts_processor,
|
||||
getnewdicttranslate,
|
||||
)
|
||||
|
||||
@@ -252,39 +266,94 @@ def openFileManually(
|
||||
print(path)
|
||||
if not path.exists():
|
||||
theGuy.header_setup(rescode.NOT_FOUND)
|
||||
if path.is_dir():
|
||||
theGuy.wfile.write(notfound404)
|
||||
return
|
||||
elif path.is_dir():
|
||||
path /= defaultFile
|
||||
if not path.is_file():
|
||||
theGuy.header_setup(rescode.NOT_FOUND)
|
||||
theGuy.wfile.write(notfound404)
|
||||
return
|
||||
|
||||
print(path)
|
||||
fileMime, fileEncoding = mimetypes.guess_type(path)
|
||||
print(fileMime, fileEncoding)
|
||||
finalMime = fileMime
|
||||
a = {}
|
||||
if headers:
|
||||
gay = next(
|
||||
(i for i in reversed(headers) if i.casefold() == "content-type"), None
|
||||
)
|
||||
if gay:
|
||||
print(gay, headers[gay])
|
||||
headerMime = headers[gay]
|
||||
if headerMime not in mimetypes.types_map.values():
|
||||
warnings.warn(
|
||||
f"what is {headerMime}. mimetypes say {fileMime} basically uhh you uhh do this for me please: if you dont know what it is dont include it",
|
||||
UserWarning,
|
||||
)
|
||||
|
||||
finalMime = headerMime
|
||||
a["content-type"] = finalMime
|
||||
headers |= a
|
||||
theGuy.header_setup(headers=headers or a)
|
||||
headers = headers or dict()
|
||||
if gay := next(
|
||||
(i for i in reversed(headers) if i.casefold() == "content-type"), None
|
||||
):
|
||||
print(gay, headers[gay])
|
||||
headerMime = headers[gay]
|
||||
if headerMime not in mimetypes.types_map.values():
|
||||
warnings.warn(
|
||||
f"what is {headerMime}. mimetypes say {fileMime} basically uhh you uhh do this for me please: if you dont know what it is dont include it",
|
||||
UserWarning,
|
||||
)
|
||||
|
||||
finalMime = headerMime
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
### i surely dont know how
|
||||
|
||||
@@ -295,13 +364,14 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler):
|
||||
super().__init__(*a, **kw)
|
||||
|
||||
def reallyEveryTime(self) -> tuple:
|
||||
# print("all headers:\n", self.headers)
|
||||
print("all headers:\n", self.headers)
|
||||
print("the path is : ", self.path)
|
||||
print(
|
||||
"connected at: ",
|
||||
self.headers.get("X-Forwarded-For", "directly").split(", ")[0],
|
||||
)
|
||||
print(urlparse.urlparse(self.path))
|
||||
# openFileSemiAutomatically(self, self.path)
|
||||
|
||||
# table = 'tbale'
|
||||
# print("there is no" ,table,ifTableInDB(db_name, table))
|
||||
@@ -319,19 +389,20 @@ class ServerLogic(serverhttp.BaseHTTPRequestHandler):
|
||||
print("gato")
|
||||
raise SystemExit("truly the /close")
|
||||
|
||||
def header_setup(
|
||||
def header_setup( # please not be bad
|
||||
self,
|
||||
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)
|
||||
if headers is not None:
|
||||
for key, value in headers.items():
|
||||
self.send_header(key, value) # why!
|
||||
for key, value in headers.items():
|
||||
self.send_header(key, value) # why!
|
||||
else:
|
||||
pass
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
|
||||
@@ -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>
|
||||
+45
-36
@@ -80,11 +80,11 @@ const typingHandler = (f) => (e) => {
|
||||
// updateTimeout = undefined;
|
||||
// }
|
||||
if (
|
||||
// !justUpdated &&
|
||||
!updateTimeout) {
|
||||
// !justUpdated &&
|
||||
!updateTimeout
|
||||
) {
|
||||
// justUpdated = true;
|
||||
updateTimeout = setTimeout(() => {
|
||||
|
||||
try {
|
||||
f();
|
||||
document.getElementById("errorfrommd").textContent = null;
|
||||
@@ -93,11 +93,10 @@ const typingHandler = (f) => (e) => {
|
||||
}
|
||||
|
||||
// justUpdated = false;
|
||||
clearTimeout(updateTimeout)
|
||||
clearTimeout(updateTimeout);
|
||||
updateTimeout = undefined;
|
||||
}, updatingInterval);
|
||||
}
|
||||
|
||||
};
|
||||
const mdUpdatingHandler = typingHandler(updateMD); //why
|
||||
document.getElementById("auto_translate").addEventListener("change", (e) => {
|
||||
@@ -221,43 +220,53 @@ form.addEventListener("submit", (e) => {
|
||||
let htmlContent = "";
|
||||
const tableContent = document.getElementById("tbale");
|
||||
const actualTableContent = document.getElementById("updatedget");
|
||||
const cdc = document.createElement("div");
|
||||
cdc.textContent = "sdfasdfasdfsdfaasdfasdfasdfasdfasdfasfdasdfasdf";
|
||||
document.getElementsByTagName("main")[0].appendChild(cdc);
|
||||
|
||||
const GETendp = (_) =>
|
||||
fetch(address + "endp")
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
console.log(json);
|
||||
// htmlContent = "<tbody>";
|
||||
|
||||
for (let key in json) {
|
||||
const url = json[key]["one"];
|
||||
const responsecode = json[key]["three"];
|
||||
let responsecontent = "something else";
|
||||
switch (responsecode) {
|
||||
case 200:
|
||||
responsecontent = "text";
|
||||
break;
|
||||
// damn
|
||||
case 301:
|
||||
case 302:
|
||||
case 307:
|
||||
case 308: // DONT EVER stick with 302
|
||||
responsecontent = "redirect";
|
||||
break;
|
||||
}
|
||||
htmlContent += `<tr>
|
||||
const GETendp = (_) => {
|
||||
const response = fetch(address + "endp") // hmm ahsdflakhwfuisdgaf
|
||||
.then(
|
||||
(response) => response.json(), e => console.log(e)
|
||||
)
|
||||
.then(
|
||||
(json) => {
|
||||
console.log(json);
|
||||
// htmlContent = "<tbody>";
|
||||
|
||||
for (let key in json) {
|
||||
const url = json[key]["one"];
|
||||
const responsecode = json[key]["three"];
|
||||
let responsecontent = "something else";
|
||||
switch (responsecode) {
|
||||
case 200:
|
||||
responsecontent = "text";
|
||||
break;
|
||||
// damn
|
||||
case 301:
|
||||
case 302:
|
||||
case 307:
|
||||
case 308: // DONT EVER stick with 302
|
||||
responsecontent = "redirect";
|
||||
break;
|
||||
}
|
||||
htmlContent += `<tr>
|
||||
<th>${key}</th>
|
||||
<td><a href="${"./" + url}">${url}</a></td>
|
||||
<td>${responsecontent}</td>
|
||||
<td>${json[key]["four"] || "Never"}</td>
|
||||
</tr>`;
|
||||
}
|
||||
}
|
||||
|
||||
// htmlContent += "</tbody>";
|
||||
actualTableContent.innerHTML = htmlContent;
|
||||
htmlContent = ''
|
||||
})
|
||||
.catch((e) => console.error(e));
|
||||
// htmlContent += "</tbody>";
|
||||
actualTableContent.innerHTML = htmlContent;
|
||||
htmlContent = "";
|
||||
tableContent.parentElement.hidden = false; // lmaop
|
||||
},
|
||||
(what) => console.log(what)
|
||||
)
|
||||
}
|
||||
|
||||
await GETendp();
|
||||
|
||||
GETendp();
|
||||
tableContent.parentElement.hidden = false;
|
||||
+14
-12
@@ -1,8 +1,3 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
:root {
|
||||
--dark-enough: #303030;
|
||||
--color-1: #8bafed;
|
||||
@@ -11,7 +6,10 @@
|
||||
--color-4: #ff7100;
|
||||
--challenge: "use dem colors";
|
||||
}
|
||||
|
||||
*, *::before, *::after {
|
||||
box-sizing: border-box;
|
||||
overflow-wrap: break-word ;
|
||||
}
|
||||
body {
|
||||
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");
|
||||
@@ -24,12 +22,15 @@ body {
|
||||
grid-template-rows: 100px 1fr 300px;
|
||||
grid-template-areas: "head head" "nav main" "nav foot";
|
||||
max-width: 100%;
|
||||
}
|
||||
body,
|
||||
html {
|
||||
width: 100%;
|
||||
/* width: 100%; */
|
||||
}
|
||||
|
||||
/* do i know what im doing */
|
||||
|
||||
html {
|
||||
max-width: 100vw;
|
||||
max-height: 100vh;
|
||||
}
|
||||
body > * {
|
||||
margin-inline: auto;
|
||||
border-radius: 15px;
|
||||
@@ -112,7 +113,8 @@ footer {
|
||||
background-color: mistyrose;
|
||||
padding: 0.5em;
|
||||
border-radius: 6px;
|
||||
max-width: calc(100% - 1em);
|
||||
/* max-width: calc(100% - 1em); */
|
||||
/* why */
|
||||
margin-inline: auto;
|
||||
|
||||
display: flex;
|
||||
@@ -171,7 +173,7 @@ textarea::placeholder {
|
||||
overflow-wrap: break-word;
|
||||
resize: none;
|
||||
min-height: 16rem;
|
||||
height:max-content;
|
||||
height: max-content;
|
||||
}
|
||||
/* ????? */
|
||||
|
||||
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user