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
+98 -38

No files matched your search

+47 -31
View File
@@ -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(
@@ -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,7 +288,19 @@ 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
) )
@@ -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:
+51 -7
View File
@@ -1,7 +1,17 @@
<form action="/endp" method="post"> <!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>
</head>
<body>
<form action="/endp" method="post" id="only_form">
<style> <style>
@scope { @scope {
:not(style) { *:not(style, script) {
display: block; display: block;
} }
@@ -10,10 +20,44 @@
} }
} }
</style> </style>
<label for="oneid">thing:<input type="text" name="one" id="oneid" /></label> <label for="oneid">url (anything after the first /):<input type="text" name="one" id="oneid"
<label for="twoid">other:<textarea rows="7" cols="40" name="two" id="twoid"></textarea> 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>
<label for="threeid">number:<input type="number" name="three" id="threeid" /></label> <label for="threeid">response code if path visited. Default 200<input type="number" name="three" id="threeid"
<label for="fourid">probably will check with js idfk<input type="number" name="four" id="fourid" /></label> placeholder="http res code" min="0" /></label>
<input type="submit" value="Sumit ur font assfuck" /> <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> </form>
<div id="what"></div>
</body>
</html>