kinda works now huh

This commit is contained in:
lda committed 2024-07-15 18:58:20 +07:00
1 parent 81ead9bb32
commit b0e4a8c496
2 files changed
+109 -49

No files matched your search

+48 -32
View File
@@ -1,12 +1,12 @@
"""
go dam
???????? code
"""
import http.server as qqq
import mysql.connector as ee2
import http.server as serverhttp
import mysql.connector as sqlcon
import json
import sql
# import datetime
# import os
@@ -21,6 +21,7 @@ from things import (
) # no way its the funny trycatch wrapper
dotenv_values1 = dotenv_values()
db_name = dotenv_values1["db_name"]
# he really did that
# from mysql.connector import errorcode
comectomKeys = ["user", "password", "host", "database"]
@@ -54,25 +55,28 @@ connectionSettings = {
}
quer = "insert into tbale (kewod, id) values (%s, %s);" # do not support custom key Only if
vals = (
r"faf",
r"24",
)
# quer = "insert into tbale (kewod, id) values (%s, %s);" # do not support custom key Only if
# vals = (
# r"faf",
# r"24",
# )
tablesql = sql.Table(name="tbale", database=db_name)
tablesql.select()
def get_that_connection(
connectionSettings: dict,
) -> tuple[any, BaseException | None]: # the giving up is real
) -> tuple: # the giving up is real
try:
connectio = ee2.connect(**connectionSettings)
except ee2.Error as e:
connectio = sqlcon.connect(**connectionSettings)
except sqlcon.Error as e:
return (None, e)
else:
return (connectio, None)
class ServerLogic(qqq.BaseHTTPRequestHandler):
class ServerLogic(serverhttp.BaseHTTPRequestHandler):
# def __do_POST2(self):
# if self.path == "/close":
# return self.close()
@@ -89,9 +93,9 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
# except Exception as e:
# print(e)
# try:
# connectio = ee2.connect(**connectionSettings)
# connectio = sqlcon.connect(**connectionSettings)
# connectio.autocommit = True # EUYOEYOEYOEYOEYO
# except ee2.Error as e:
# except sqlcon.Error as e:
# print(e.errno, e.msg)
# else:
# with connectio.cursor(buffered=True) as cur:
@@ -123,8 +127,8 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
# self.header_setup()
# try:
# connectio = ee2.connect(**connectionSettings)
# except ee2.Error as e:
# connectio = sqlcon.connect(**connectionSettings)
# except sqlcon.Error as e:
# print(e)
# else:
# with connectio.cursor(buffered=True, raw=True) as cur:
@@ -147,7 +151,10 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
# raise SystemExit("truly the /close")
def youJustHaveToDoTheseStuff(self):
print(self.headers, "hd")
# print(self.headers)
print("the path is : ", self.path)
print("the entire headers:\n", self.headers.as_string())
# print(self.headers.get(""))
def close(self):
funny_trycatch_wrapper(
@@ -192,25 +199,18 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
except Exception as e:
print(e)
return # return ealy no else
c = process_tuples(w)
efg = funny_tuples_to_dicts_processor(anotherone2, c)
if self.path == "/endp":
self.header_setup(headers={"Content-type": "application/json"})
c = process_tuples(w)
# print(w, c, sep="\n")
# self.wfile.write(str(c).encode())
# self.wfile.write(str(anotherone2).encode())
efg = funny_tuples_to_dicts_processor(anotherone2, c)
self.wfile.write(str(efg).encode())
return
else:
with connectio.cursor(buffered=True) as cur:
try:
res = cur.execute("select neme, kewod, cod from tbale")
wd = cur.fetchall()
except Exception as e:
print(e)
return # return ealy no else
wd = [(a["neme"], a["kewod"], a["cod"]) for a in efg]
# print(wd)
for a, v, c in wd:
# print(a,v)
@@ -272,6 +272,7 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
+ str(eror).encode()
)
return
connectio.autocommit = True
print((*data_dict.keys(), *data_dict.values()))
with connectio.cursor(buffered=True) as cur:
try:
@@ -287,11 +288,23 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
# for key in data_dict:
# if key in this_list_of_colnaes:
# tehwe.append(key)
if data_dict.get("from") == "ldlda":
ogdata_dict = data_dict.copy()
hehedata_dict = ogdata_dict["data"]
data_dict = getnewdicttranslate(
hehedata_dict,
{
"one": "neme",
"two": "kewod",
"three": "cod",
"four": "expi",
},
)
print(data_dict)
wwwww = tuple(
key for key in data_dict if key in this_list_of_colnaes
)
#hmmm
# hmmm
# repated cod? huh?
# updated_Verybreakablequery_insert_into = (
@@ -302,6 +315,7 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
).format(*wwwww, *("?",) * len(wwwww))
)
print(
wwwww,
tuple(data_dict[w] for w in wwwww),
updated_Verybreakablequery_insert_into,
sep="\n",
@@ -313,8 +327,9 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
tuple(data_dict[w] for w in wwwww),
multi=True,
)
print("insert into qure: ", cur.fetchall())
another = cur.execute("select * from tbale")
w2f = cur.fetchall()
print(res)
except Exception as e:
print("execute err: ", e)
self.wfile.write(
@@ -326,7 +341,7 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
# aq142 = cur.fetchall()
self.wfile.write(b"\n We have this in the this: ")
# self.do_GET()
self.wfile.write(str(w2f).encode())
self.wfile.write(str(process_tuples(w2f)).encode())
## WHAT THE FUCK IS THIS PART
else:
self.wfile.write(b"\nits of the type: ")
@@ -344,7 +359,8 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
def runServer():
server = qqq.HTTPServer(("", 8088), ServerLogic)
server = serverhttp.HTTPServer(("", 8088), ServerLogic)
try:
server.serve_forever()
except KeyboardInterrupt:
+61 -17
View File
@@ -1,19 +1,63 @@
<form action="/endp" method="post">
<style>
@scope {
:not(style) {
display: block;
}
<!DOCTYPE html>
<html lang="en">
p {
font-size: larger;
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>lđa testing</title>
</head>
<body>
<form action="/endp" method="post" id="only_form">
<style>
@scope {
*:not(style, script) {
display: block;
}
p {
font-size: larger;
}
}
}
</style>
<label for="oneid">thing:<input type="text" name="one" id="oneid" /></label>
<label for="twoid">other:<textarea rows="7" cols="40" name="two" id="twoid"></textarea>
</label>
<label for="threeid">number:<input type="number" name="three" id="threeid" /></label>
<label for="fourid">probably will check with js idfk<input type="number" name="four" id="fourid" /></label>
<input type="submit" value="Sumit ur font assfuck" />
</form>
</style>
<label for="oneid">url (anything after the first /):<input type="text" name="one" id="oneid"
placeholder="url" /></label>
<label for="twoid">content (as html cuz mime my ass):<textarea rows="7" cols="40" name="two" id="twoid"
placeholder="content"></textarea>
</label>
<label for="threeid">response code if path visited. Default 200<input type="number" name="three" id="threeid"
placeholder="http res code" min="0" /></label>
<label for="fourid">expiration time for anything (todo idk how to do )<input type="number" name="four"
id="fourid" placeholder="expiration in days" min="0" /></label>
<p>if bugs tell me how to solve cuz im bad</p>
<input type="submit" value="Sumit rn" />
<script>
const form = document.getElementById("only_form");
// const what = form.querySelector("input[type=submit]");
console.log(form);
form.addEventListener("submit", (e) => {
// somewhere there has been code
e.preventDefault();
const data = new FormData(form);
const jsData = Object.fromEntries(data);
Object.entries(jsData).forEach(
([k, v]) => (jsData[k] = v ? v : undefined)
); // important here as we are dealing with Strings true/false kinda works how it is.
const jsonified_data = JSON.stringify(jsData);
const jsonified_custom_data = `{"from":"ldlda","data":${jsonified_data}}`; // haxxor
const xhr = new XMLHttpRequest(); // this is going to be used. a lot.
xhr.open("POST", form.getAttribute("action"));
xhr.setRequestHeader("Content-type", "application/json");
xhr.send(jsonified_custom_data);
xhr.addEventListener(
"load",
(_) => (document.getElementById("what").innerText = xhr.response)
);
return false;
});
</script>
</form>
<div id="what"></div>
</body>
</html>