kinda works now huh
This commit is contained in:
1 parent
81ead9bb32
commit
b0e4a8c496
2 files changed
+113
-53
No files matched your search
+52
-36
@@ -1,12 +1,12 @@
|
|||||||
"""
|
"""
|
||||||
go dam
|
go dam
|
||||||
???????? code
|
???????? code
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import http.server as qqq
|
import http.server as serverhttp
|
||||||
import mysql.connector as ee2
|
import mysql.connector as sqlcon
|
||||||
import json
|
import json
|
||||||
|
import sql
|
||||||
|
|
||||||
# import datetime
|
# import datetime
|
||||||
# import os
|
# import os
|
||||||
@@ -21,6 +21,7 @@ from things import (
|
|||||||
) # no way its the funny trycatch wrapper
|
) # no way its the funny trycatch wrapper
|
||||||
|
|
||||||
dotenv_values1 = dotenv_values()
|
dotenv_values1 = dotenv_values()
|
||||||
|
db_name = dotenv_values1["db_name"]
|
||||||
# he really did that
|
# he really did that
|
||||||
# from mysql.connector import errorcode
|
# from mysql.connector import errorcode
|
||||||
comectomKeys = ["user", "password", "host", "database"]
|
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
|
# quer = "insert into tbale (kewod, id) values (%s, %s);" # do not support custom key Only if
|
||||||
vals = (
|
# vals = (
|
||||||
r"faf",
|
# r"faf",
|
||||||
r"24",
|
# r"24",
|
||||||
)
|
# )
|
||||||
|
tablesql = sql.Table(name="tbale", database=db_name)
|
||||||
|
|
||||||
|
tablesql.select()
|
||||||
|
|
||||||
|
|
||||||
def get_that_connection(
|
def get_that_connection(
|
||||||
connectionSettings: dict,
|
connectionSettings: dict,
|
||||||
) -> tuple[any, BaseException | None]: # the giving up is real
|
) -> tuple: # the giving up is real
|
||||||
try:
|
try:
|
||||||
connectio = ee2.connect(**connectionSettings)
|
connectio = sqlcon.connect(**connectionSettings)
|
||||||
except ee2.Error as e:
|
except sqlcon.Error as e:
|
||||||
return (None, e)
|
return (None, e)
|
||||||
else:
|
else:
|
||||||
return (connectio, None)
|
return (connectio, None)
|
||||||
|
|
||||||
|
|
||||||
class ServerLogic(qqq.BaseHTTPRequestHandler):
|
class ServerLogic(serverhttp.BaseHTTPRequestHandler):
|
||||||
# def __do_POST2(self):
|
# def __do_POST2(self):
|
||||||
# if self.path == "/close":
|
# if self.path == "/close":
|
||||||
# return self.close()
|
# return self.close()
|
||||||
@@ -89,9 +93,9 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
# except Exception as e:
|
# except Exception as e:
|
||||||
# print(e)
|
# print(e)
|
||||||
# try:
|
# try:
|
||||||
# connectio = ee2.connect(**connectionSettings)
|
# connectio = sqlcon.connect(**connectionSettings)
|
||||||
# connectio.autocommit = True # EUYOEYOEYOEYOEYO
|
# connectio.autocommit = True # EUYOEYOEYOEYOEYO
|
||||||
# except ee2.Error as e:
|
# except sqlcon.Error as e:
|
||||||
# print(e.errno, e.msg)
|
# print(e.errno, e.msg)
|
||||||
# else:
|
# else:
|
||||||
# with connectio.cursor(buffered=True) as cur:
|
# with connectio.cursor(buffered=True) as cur:
|
||||||
@@ -123,8 +127,8 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
# self.header_setup()
|
# self.header_setup()
|
||||||
# try:
|
# try:
|
||||||
# connectio = ee2.connect(**connectionSettings)
|
# connectio = sqlcon.connect(**connectionSettings)
|
||||||
# except ee2.Error as e:
|
# except sqlcon.Error as e:
|
||||||
# print(e)
|
# print(e)
|
||||||
# else:
|
# else:
|
||||||
# with connectio.cursor(buffered=True, raw=True) as cur:
|
# with connectio.cursor(buffered=True, raw=True) as cur:
|
||||||
@@ -147,7 +151,10 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
# raise SystemExit("truly the /close")
|
# raise SystemExit("truly the /close")
|
||||||
|
|
||||||
def youJustHaveToDoTheseStuff(self):
|
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):
|
def close(self):
|
||||||
funny_trycatch_wrapper(
|
funny_trycatch_wrapper(
|
||||||
@@ -169,13 +176,13 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
if self.path == "/close":
|
if self.path == "/close":
|
||||||
return self.close()
|
return self.close()
|
||||||
|
|
||||||
if self.path == "/":
|
if self.path == "/":
|
||||||
self.header_setup()
|
self.header_setup()
|
||||||
with open("index.html", "rb") as file:
|
with open("index.html", "rb") as file:
|
||||||
self.wfile.write(file.read())
|
self.wfile.write(file.read())
|
||||||
return
|
return
|
||||||
|
|
||||||
(connectio, eror) = get_that_connection(connectionSettings)
|
(connectio, eror) = get_that_connection(connectionSettings)
|
||||||
if eror:
|
if eror:
|
||||||
print("coneti eror: ", eror)
|
print("coneti eror: ", eror)
|
||||||
@@ -192,25 +199,18 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
return # return ealy no else
|
return # return ealy no else
|
||||||
|
c = process_tuples(w)
|
||||||
|
efg = funny_tuples_to_dicts_processor(anotherone2, c)
|
||||||
|
|
||||||
if self.path == "/endp":
|
if self.path == "/endp":
|
||||||
self.header_setup(headers={"Content-type": "application/json"})
|
self.header_setup(headers={"Content-type": "application/json"})
|
||||||
c = process_tuples(w)
|
|
||||||
# print(w, c, sep="\n")
|
# print(w, c, sep="\n")
|
||||||
# self.wfile.write(str(c).encode())
|
# self.wfile.write(str(c).encode())
|
||||||
# self.wfile.write(str(anotherone2).encode())
|
# self.wfile.write(str(anotherone2).encode())
|
||||||
|
|
||||||
efg = funny_tuples_to_dicts_processor(anotherone2, c)
|
|
||||||
self.wfile.write(str(efg).encode())
|
self.wfile.write(str(efg).encode())
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
with connectio.cursor(buffered=True) as cur:
|
wd = [(a["neme"], a["kewod"], a["cod"]) for a in efg]
|
||||||
try:
|
|
||||||
res = cur.execute("select neme, kewod, cod from tbale")
|
|
||||||
wd = cur.fetchall()
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
return # return ealy no else
|
|
||||||
# print(wd)
|
# print(wd)
|
||||||
for a, v, c in wd:
|
for a, v, c in wd:
|
||||||
# print(a,v)
|
# print(a,v)
|
||||||
@@ -272,6 +272,7 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
+ str(eror).encode()
|
+ str(eror).encode()
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
connectio.autocommit = True
|
||||||
print((*data_dict.keys(), *data_dict.values()))
|
print((*data_dict.keys(), *data_dict.values()))
|
||||||
with connectio.cursor(buffered=True) as cur:
|
with connectio.cursor(buffered=True) as cur:
|
||||||
try:
|
try:
|
||||||
@@ -287,13 +288,25 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
# for key in data_dict:
|
# for key in data_dict:
|
||||||
# if key in this_list_of_colnaes:
|
# if key in this_list_of_colnaes:
|
||||||
# tehwe.append(key)
|
# 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(
|
wwwww = tuple(
|
||||||
key for key in data_dict if key in this_list_of_colnaes
|
key for key in data_dict if key in this_list_of_colnaes
|
||||||
)
|
)
|
||||||
#hmmm
|
# hmmm
|
||||||
# repated cod? huh?
|
# repated cod? huh?
|
||||||
|
|
||||||
# updated_Verybreakablequery_insert_into = (
|
# updated_Verybreakablequery_insert_into = (
|
||||||
# f"insert into tbale {wwwww} values {tuple('?'* len(wwwww))}"
|
# f"insert into tbale {wwwww} values {tuple('?'* len(wwwww))}"
|
||||||
updated_Verybreakablequery_insert_into = (
|
updated_Verybreakablequery_insert_into = (
|
||||||
@@ -302,6 +315,7 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
).format(*wwwww, *("?",) * len(wwwww))
|
).format(*wwwww, *("?",) * len(wwwww))
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
|
wwwww,
|
||||||
tuple(data_dict[w] for w in wwwww),
|
tuple(data_dict[w] for w in wwwww),
|
||||||
updated_Verybreakablequery_insert_into,
|
updated_Verybreakablequery_insert_into,
|
||||||
sep="\n",
|
sep="\n",
|
||||||
@@ -313,8 +327,9 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
tuple(data_dict[w] for w in wwwww),
|
tuple(data_dict[w] for w in wwwww),
|
||||||
multi=True,
|
multi=True,
|
||||||
)
|
)
|
||||||
|
print("insert into qure: ", cur.fetchall())
|
||||||
|
another = cur.execute("select * from tbale")
|
||||||
w2f = cur.fetchall()
|
w2f = cur.fetchall()
|
||||||
print(res)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("execute err: ", e)
|
print("execute err: ", e)
|
||||||
self.wfile.write(
|
self.wfile.write(
|
||||||
@@ -326,7 +341,7 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
# aq142 = cur.fetchall()
|
# aq142 = cur.fetchall()
|
||||||
self.wfile.write(b"\n We have this in the this: ")
|
self.wfile.write(b"\n We have this in the this: ")
|
||||||
# self.do_GET()
|
# self.do_GET()
|
||||||
self.wfile.write(str(w2f).encode())
|
self.wfile.write(str(process_tuples(w2f)).encode())
|
||||||
## WHAT THE FUCK IS THIS PART
|
## WHAT THE FUCK IS THIS PART
|
||||||
else:
|
else:
|
||||||
self.wfile.write(b"\nits of the type: ")
|
self.wfile.write(b"\nits of the type: ")
|
||||||
@@ -344,7 +359,8 @@ class ServerLogic(qqq.BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
|
|
||||||
def runServer():
|
def runServer():
|
||||||
server = qqq.HTTPServer(("", 8088), ServerLogic)
|
|
||||||
|
server = serverhttp.HTTPServer(("", 8088), ServerLogic)
|
||||||
try:
|
try:
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
+61
-17
@@ -1,19 +1,63 @@
|
|||||||
<form action="/endp" method="post">
|
<!DOCTYPE html>
|
||||||
<style>
|
<html lang="en">
|
||||||
@scope {
|
|
||||||
:not(style) {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
<head>
|
||||||
font-size: larger;
|
<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>
|
||||||
</style>
|
<label for="oneid">url (anything after the first /):<input type="text" name="one" id="oneid"
|
||||||
<label for="oneid">thing:<input type="text" name="one" id="oneid" /></label>
|
placeholder="url" /></label>
|
||||||
<label for="twoid">other:<textarea rows="7" cols="40" name="two" id="twoid"></textarea>
|
<label for="twoid">content (as html cuz mime my ass):<textarea rows="7" cols="40" name="two" id="twoid"
|
||||||
</label>
|
placeholder="content"></textarea>
|
||||||
<label for="threeid">number:<input type="number" name="three" id="threeid" /></label>
|
</label>
|
||||||
<label for="fourid">probably will check with js idfk<input type="number" name="four" id="fourid" /></label>
|
<label for="threeid">response code if path visited. Default 200<input type="number" name="three" id="threeid"
|
||||||
<input type="submit" value="Sumit ur font assfuck" />
|
placeholder="http res code" min="0" /></label>
|
||||||
</form>
|
<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>
|
||||||
Reference in new issue
Block a user