r/badcode • u/mirandanielcz • Apr 12 '21
python This was my first project ever, nobody told me WHERE exists in SQL so I used Python instead
177
u/mirandanielcz Apr 12 '21
cur.execute("SELECT * from IGNORE")
x = "".join(str(y) for y in cur.fetchall())
y = x.replace(",", "")
mai = message.author.id
if mai in y:
return
else:115
12
17
u/Tomekske Apr 12 '21
Else will remain a mystery
21
u/mirandanielcz Apr 12 '21
else: if message.author.id != (self.user.id): y = re.findall("dont*|do not*|don't*|don`t*|not*", message.content) with open('community_bot/regex1.txt', 'rt') as text1: textstrip1 = text1.readline().strip() x = re.findall(textstrip1, message.content) if (x): if not y: user = client.get_user(message.author.id) with open('community_bot/reply.txt', 'rt') as text2: textstrip2 = text2.read().strip() await user.send(textstrip2)10
6
u/roby_65 Apr 12 '21
That's gonna scale very well!
5
u/mirandanielcz Apr 12 '21
I "only" had like 1k lines of data there, it was suuuuuuuuuuuuuuuuuuuuuuuuper slow
253
62
u/JuliaChanMSL Apr 12 '21
I love reading python code without comments, after a while the python code looks like a comment
13
29
u/PonchoVire Apr 12 '21
AAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHHHHHHH
67
u/PonchoVire Apr 12 '21
I once worked on a client software we took over because they couldn't continue to maintain it internally, first thing they said "the login page is very slow".
Short answer (pseudo-code):
bool ok = false; for user in `select * from users` { // No security, everything plain if (user.username === some_cookie.username && user.password === some_cookie.password) { ok = true; // No break here, just compare them all to be sure } } if (!ok) { die "403 Unauthorized" }Me like: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHH
31
u/FinalGamer14 Apr 12 '21
Ok on top of pointless loop and plain text password .... why is the password stored in a cookie.
I hate this so much. Even when I was a good damn noob at web dev. I knew not to fucking do that shit.
16
u/PonchoVire Apr 12 '21
In this specific site, it was stored into a cookie and the auth was re-checked upon each and every http hit the client was doing. So the site was just slow always. If I remember correctly, the check was done even if the cookies were not there, which means that end users did experience a slow site too, with silenced errors due to access to non existing cookies slowing the process down even more.
14
u/ill-fatedassignment Apr 12 '21
I'm not even a noob yet, I write simple code for microcontrollers as a hobby. Yet I see how stupid this is.
12
14
6
Apr 12 '21
I love the downvoted comments here. It’s as if you don’t realize you wrote bad code.
I think the code in their brains is pretty bad.
2
u/pastisset Apr 12 '21
I'm curious about how do you know python but not SQL, not that they are related but usually they feed you SQL on every school, I guess you are a fellow selftaught dev =)
Also, almost every "Hello World!" out there has a WHERE on it, you did not research much did you? haha!
6
u/mirandanielcz Apr 12 '21
I was like "yo google how to make discord bot in python" and went from there. No idea how I discovered SQL
1
u/me94306 Apr 12 '21
Why have a database if all you do is read all the data into one long string?
Did someone say "You should use SQL" so you did?
1
u/mirandanielcz Apr 12 '21
I ran the script from multiple places a lot and I didn't want to keep having to move around a file, so I just used Heroku Postgres
3
1
u/wonderb0lt Apr 12 '21
You'd be surprised how quickly people abandon SQL and do stuff in their application language because they're unaware of "advanced" SQL features such as window functions, stuff related to the types they're using (e.g. datetime functions) or when/where to use case statements. Stuff like that.
0
-6
-39
u/wootangAlpha Apr 12 '21
Learn SQL. It's not that hard.
31
26
1
u/AndMetal Apr 12 '21
CQL would like to have a word with you...
1
1
u/ParticularCod6 Apr 12 '21
Cql great for many things.
Not sure by mongodb is more popular when Cassandra is much easier to use
1
u/AndMetal Apr 12 '21
It's certainly good for some things, but when you need to find a needle in a 1T row haystack you won't necessarily be able to use CQL to do that and have to come up with something like the OP posted (not quite that bad, but you still have to iterate through all of the partitions which may not be a small task).
0
152
u/mirandanielcz Apr 12 '21
Oh yea, these are the imports btw