#databases
1 messages · Page 45 of 1
i use a json file but i'm converting to some document database thing
Yeah, use a db bruh
There's no reason the database can't use JSON or BSON
I got a friend with a bot called Spykebot that runs on mongodb
Its in multiple thousand splatoon discords
my current json file is like 8632 lines long lmao
Mongo is infamous for being unreliable
unreliable?
My friend still does not know how the fuck it still is running
But it did get corrupted a month ago
idk y it makes u do whatever port and connection shit if ur connecting to a local db
And all data was lost
It does stuff like temporarily losing data during upgrades and not sharding correctly
It's also a bit unsafe because it doesn't warn you about system problems
For example, if you run out of disk space, it just silently drops any data you give it
damn lmao
mongodb
what a g
rethink db
one thing i'm confused about is whatever port and stuff
Why are there things related to hosts and shit
if i'm running the db locally?
Because it has to know that still?
Every database does, some of them just default to localhost
idk i'm just so uninformed about everything rn
No kidding :P
rethinkdb.errors.ReqlTimeoutError: Could not connect to localhost:28015, operation timed out.
woooooot
Install rethinkdb and run it?
i did
So then connect to it using the right port
uh
is it r.connect( "localhost", 8080).repl()?
rethinkdb.errors.ReqlTimeoutError: Could not connect to localhost:8080, operation timed out.
wooot
you still need to actually run the database software
it's just rethinkdb in a terminal
@viral crag mongodb is a lot better than it once was
you say that, but I use it
So?
so I know exactly what the problems I have with it are
Compared to a few years ago, it is a lot better
are you trying to say that because it has improved over the last few years, my issues are invalid?
they are current issues
"Mongo is infamous for being unreliable" isn't as true as it once was
well, it's still both infamous and unreliable, so
Whatever you say
sounds infamous enough to me
I tried running it but it didn’t let me exit out of it
Do I need to tmux or some shit?
No? You can ctrl+c it like anything else
It is, yes
try Ctrl+ Break
if you run that in Windows?
It works on windows for me too
uh
when i did ctrl+c....
**```fix
Server got SIGINT from pid 0, uid 0; shutting down...
Shutting down client connections...
All client connections closed.
Shutting down storage engine... (This may take a while if you had a lot of unflushed data in the writeback cache.)
Storage engine shut down.
doesn't that mean it disconnected?
sounds like it shut down, which is what you had in mind 🤔 or is it?
i was trying to do some python stuff
and it caused a localhost error
so iwas told to actually connect to it
"you still need to actually run the database software
it's just rethinkdb in a terminal"
so i ran rethinkdb
and then i wanted to stay connected to it so that i can test the db in python3
oh like, you want to run both rethinkdb and your bot?
Yeah
Either you run rethinkdb in background (but I have no idea how that works on Windows), or you just open a second console window
do I start another tmux session?
oh, is this on some remote system?
you can run rethinkdb in background without tmux
Yeah
ctrl+c closes 99% of things on the command line
do i just close out of my console and open another one?
check the article I linked
in short, you can use fg to bring rethinkdb back to foreground, then quit it, and then launch it again and redirect its output to something like /dev/null
how do i put it to the background so that i can run another command?
check the article i linked
uh
it says "You can start a background process by appending an ampersand character ("&") to the end of your commands. This tells the shell not to wait for the process to complete, but instead to begin execution and to immediately return the user to a prompt. The output of the command will still display in the terminal (unless redirected), but you can type additional commands as the background process continues."
oh shit
can I do the same with my discord bot?
you can do that with most processes i believe
Info on postgresql db
Im giving it another chance
Like what do i do to set everything up in it, like connecting to the db, ect.
Also info on commiting
Cause there are literally, no guides on how to do this with discord.py
Every single damn one is for .js
I'm gonna imagine there's lots of guides online for setting up postgres
and... committing?
gotcha
it looks like they have pretty clear docs https://magicstack.github.io/asyncpg/current/usage.html
everything worth using has docs
always Google the docs
Fetchall equivilant?
sure?
? @obtuse lance
Like, what is the Equivilant of sqlite3's fetchall in asyncpg
Ignoring exception in on_ready
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/client.py", line 224, in _run_event
yield from coro(*args, **kwargs)
File "./main.py", line 30, in on_ready
await connect()
File "./main.py", line 13, in connect
await conn.execute('''CREATE TABLE profile(UID, IGN, FC1, FC2, FC3, Weapon1, Weapon2, Weapon3, RM, SZ, TC, CB, XP)''')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/asyncpg/connection.py", line 238, in execute
return await self._protocol.query(query, timeout)
File "asyncpg/protocol/protocol.pyx", line 319, in query
asyncpg.exceptions.PostgresSyntaxError: syntax error at end of input
async def connect():
conn = await asyncpg.connect(**credentials)
await conn.execute('''CREATE TABLE profile(UID, IGN, FC1, FC2, FC3, Weapon1, Weapon2, Weapon3, RM, SZ, TC, CB, XP)''')
What am i doing wrong here also
🤔
can you guys help get me started on how dbs work?
i'm using rethinkdb
and i'm getting really confused following https://rethinkdb.com/docs/guide/python/
what exactly is confusing you
basically everything
idk what's the point of connecting to some server
the rethinkdb command
r.connect( "localhost", 28015).repl()
what does "localhost", 28015 mean and .repl()
y .run() is necessary
idk
there's a server running on your computer that manages the database for anything else that wants to communicate with it
"localhost" is your computer's local address
28015 is probably the port rethink is running on
.repl() I imagine starts a Read Evaluate Print Loop, based on its name
and im guessing .run() allows the connection to be running perpetually until its closed
no
It just means it's not SQL
As in there are not things like SELECT, DROP, WHERE, UPDATE etc.
there are tables, they work differently though
That's how some work, yes
Rethink, for example, works in that manner
Every document is a JSON object
i withdraw my last comment i guess .run() just executes the line you call it on
You have to specify a connection as well
You prepare a query by adding things to r.X().Y().Z()
once you are ready and you have your query ready you sent it off to the server using run
Ok, How do I prevent a blank input being added, such as when I try to insert and if a specific insertment is blank, then it does nothing
horribly worded, I'm very sorry
blank as in just space?
yea
or just submitted without any form of typing
like when I'm inserting it, it will prevent such from happening
looks like you may want str.isspace
and this does what?
>>> "hello".isspace()
False
>>> "hello world".isspace()
False
>>> " ".isspace()
True
>>> " ".isspace()
True
wait then how does create_table work if it's json?
@hollow tiger you can think of that as like a big array (the table) where the JSON objects (the documents) go
@glass bough Not for that, you'd need something like if input == "" or input.isspace(): # handle empty
No problems :D
@hollow tiger Rethink doesn't actually communicate via JSON, that's just the way things are stored, opposed to a row (like in SQL)
yep
thanks again
or if not date.strip():
that could be an issue
but theoretically
you could also remove 3000 of the same thing
yea, I made a while loop
amirite?
and that was the bad
ok, removed
alright
while not(date == '' or date.isspace()):
c.execute("INSERT INTO Runningtimesof2018(Date, Time, Place) VALUES(?, ?, ?)", (date, time, place))
break
would this make any sense
I'm almost certain the while statement is wrong
would I do if not
?
I still vote for while date.strip():
(although what you wrote does look correct)
and this would have the same functionality
that loop will only run once, so it's basically acting as an if statement
oh right the break
alright, I think I have it
🤔
returning exception database is locked
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiosqlite/core.py", line 136, in run
result = fn()
sqlite3.OperationalError: database is locked
Ignoring exception in message
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/discord/client.py", line 224, in _run_event
yield from coro(*args, **kwargs)
File "/Users/shanehawkins/Desktop/DiscordBot/cogs/member.py", line 182, in on_message
await self.bot.db.commit()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiosqlite/core.py", line 184, in commit
await self._execute(self._conn.commit)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiosqlite/core.py", line 159, in _execute
raise result
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/aiosqlite/core.py", line 136, in run
result = fn()
sqlite3.OperationalError: database is locked
Why is doing !profile locking the database
https://hastebin.com/oqoqusamol.swift
Oh yeah here is a event that might have something to do with it
https://hastebin.com/usofebiyuz.py
🤔
Wait i might know why
It is doing two things at once
!profile counts as a message, so it is adding 5 points to my message, and the bots message
but !profile is also grabbing info from the DB
What would i do to fix it then?
Also how do i not award points to any messages the bot says
Or maybe if two things are happening at once instead of locking the database it does one at a time
Yo @vestal apex Do you know the answer to this, also what Databases that are similar to SQlite can handle multiple things at once without locking
I'm afraid I don't know and don't have the resources to research at the moment
Ah
Ok, ima use aiosqlite in my member.py too
Also it is commiting on the parts where it needs to commit
async def on_message(self, message):
async with aiosqlite.connect('profiles.db') as self.bot.db:
await self.bot.db.execute('UPDATE Profile SET XP=XP+5 where UID = {}'.format(message.author.id,))
await self.bot.db.commit()
cursor = await self.bot.db.execute('Select XP from Profile where UID = {}'.format(message.author.id,))
row = await cursor.fetchone()
print('{} has received 5 XP {} / 100(LVL UP)'.format(message.author.id, row[0]))
if row[0] % 100 == 0:
await message.channel.send('{} has Leveled up! You can view what level you are with !profile'.format(message.author.name))
await self.bot.db.execute('UPDATE Profile SET Level=Level+1 where UID = {}'.format(message.author.id,))
await self.bot.db.commit()
It needs to commit to save the Data on this one
This does not need to commit
Cause it is just selecting info
And putting it into a Variable
@modest haven The DB Browser app i am using i quit though
And it is doing two things at once is probably why it is locking
It is grabbing the data from the Database and inserting it into variables and at the same time awarding points
@modest haven Oh yeah also message.startswith is not working on it
async def on_message(self, message):
async with aiosqlite.connect('profiles.db') as self.bot.db:
if message.startswith('!'):
return
else:
await self.bot.db.execute('UPDATE Profile SET XP=XP+5 where UID = {}'.format(message.author.id,))
await self.bot.db.commit()
cursor = await self.bot.db.execute('Select XP from Profile where UID = {}'.format(message.author.id,))
row = await cursor.fetchone()
print('{} has received 5 XP {} / 100(LVL UP)'.format(message.author.id, row[0]))
if row[0] % 100 == 0:
await message.channel.send('{} has Leveled up! You can view what level you are with !profile'.format(message.author.name))
await self.bot.db.execute('UPDATE Profile SET Level=Level+1 where UID = {}'.format(message.author.id,))
await self.bot.db.commit()
o
But all i gotta do is figure out how to make it do one thing at a time and this should be fixed
by the bot? or by people who are viewing it
Uh ok
Also do you know any other Databases that are similar to sqlite that can handle multiple things at once without locking
@modest haven
So mysql can handle multiple things at once? cool
Time to see if i like it
Yeah, i will probably recode my entire bot so i can use this
Can you order a table based on 3 columns after a bit of math? ((col 1 + col 2)//col3) postgresql btw
Or would i have to add another column with that value
async sqlite just sounds like things will break
i use peewee_async with postgres https://github.com/05bit/peewee-async
aysncpg is also for postgres, fastest of asyncio postgresql connectors and easy to use
https://hastebin.com/yugubaqipi.sql
https://hastebin.com/idijasoyot.py
This is a PostgreSQL error i am having, what do i do to fix?
iirc postgres is the system database for configuration and stuff by postgres
but I'm not sure
🤔
Cause i have been trying to migrate
And all of this bullshit has been happening
https://hastebin.com/eqilebupom.py
This command locks then closes my database, why?
https://hastebin.com/edorexopaj.sql
It might have something to do with it reopening connections alot
And if so how do i make it not do that XD
Wow i figured it out
And apparently the peeps who guided me through levels and shit were completely wrong
👍
Ok, so I want to be able to pull everything that has a specific value in a specific row, such as the row being named "Event", and the input of the specific value being a variable
such as a string
my attempt is "SELECT * FROM table WHERE Event = ?"
then I would execute it in a for statement
loop*
might've just solved it
new problem, or questions I guess, how could I go through a database and sort it by a row
like given 7, 5, 6. It will sort each row in the order of 5,6,7
and replace it in the file
you don't need to sort the database you can just sort when you query it
use ORDER BY
Hi everyone. Thanks for having me in this group. Completely new to python.... and programming in general. Trying to teach myself everything here. So please bear with me as I may ask some really simple questions here haha.
So first thing I wanted to ask is that in my data, I have dates currently in this format:
4/2/2018 (Mon)
What's the best way to go about cleaning this?
I want to remove the (Day) from that entry and put it in a different column. Is there a quick command for that or would I have to do this manually?
query the database for a row
a,b = date.split(" ")
now you have the date in a and the day in b
update the date value with a
update the empty day value with b
repeat
@runic tundra Thanks!
How would i create a new column in an existing database and update all rows with a value based on other columns?
ALTER TABLE table_name
ADD column_name datatype;```
that will add a column
and you will have to write a for loop for updating the values
postgresql
@runic tundra
after it is ordered, I would need to select from it to specific rows such as SELECT * FROM table WHERE row = ?
after I have it sorted with order by
You do the select and order by at the same time
After the where row = ? Put the order by
Thank you
@runic tundra for date.split(""), is there a library that needs to be imported?
No
How do I find all the column titles of a table
and print it out
well, maybe not
well, nvm
I got it
how would I put two inputs for a Query ex: sql = ("SELECT * FROM table WHERE ? = ?")
for row in c.execute(sql, (inp1, inp2,)):
is this how I would do it?
I think each ? is replaced by an argument in your args list (inp1, inp2,)
so is it formatted correctly?
So if you want multiple queries in one:
("SELECT * FROM table WHERE ? = ? AND ? = ?")
Well, does it run?
You could try hardcoding it a little for now, just to see whether it's the query or the args list that isn't working.
Instead of ?, write the word you're searching for. Does it exist in the database?
its all filling it in a believe, but as I go to a for loop trying to print a row in that select information, it doesn't work
Alternatively, try:
("SELECT * FROM table WHERE " + str(inp1) + " = " + str(inp2))
But you really should avoid this as it's open for SQL injection. The ? and args list should work as intended.
What worked?
using that above
cursor.execute("INSERT INTO table VALUES (?, ?, ?)", (var1, var2, var3))```
It is strange because this should be acceptable syntax.
cursor.execute("INSERT INTO table VALUES (%s, %s, %s)", (var1, var2, var3))```
Prettier way of doing the pure string.
Try both of these, see which one that works.
in the entering section of my code?
I guess~
("INSERT INTO Runningtimesof2018(Date, Time, Place, Event) VALUES(?, ?, ?, ?)", (date, time, place, event))
this is what I currently have
in that part tha tis
Hey, that looks nice.
but thats not the section I'm having trouble with
cursor.execute("SELECT * FROM table WHERE ?, ?", (var1, var2))```
wouldn't it be ? = ?
Oh whoops.
but now it returns operation parameter must be str
Ok, so it seems that it doesn't like that you pass arguments in a tuple as the second argument. It wants them individually.
cursor.execute("SELECT * FROM table WHERE ? = ?", var1, var2)
function takes at most 2 arguements (3 given)
Nevermind. Misread.
we could hop into a call
Can't talk.
I could send you the chunk of code I'm using
all I have is that there is a table where a column is named Date, and it has two parts with a value of 5.3
so as I input that, it takes those and fills them into the Query
Paste the line where you call execute.
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE ? = ?", (Whattime, Whattime2)):
Whattime = Date
Whattime2 = 5.3
below the for loop it prints out the row
I can assure you that the table has a column named Date and a value in that column with the value of 5.3
And this code works if you change it to..?
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE %s = %s" % (Whattime, Whattime2)):
Well, how important is it that it's have SQL injection safe? 😛
I don't know, its for personal use
I guess
do you have any idea of what could be wrong?
The only problem is if you have a friend who knows how to mess up your life and tries it out.
but its for my personal use to track my growth through my running seasons
Although you could actually make it a bit safer by checking the parameters first. Say, check that the first one is a string only, and the latter a valid number.
I should be ok
Wait.
what?
Go back to the ? one and change Whattime2 to str(Whattime2)
That can't possibly be it, but bah, who knows
It's just that if the string works, the ? should work, but there's something messing up
and it didn't work
I've used sqlite3 myself and I'm very sure the ? method works, so it's really strange.
!!!!!!!!!!!!!!!!!!1
conn.commit()
You have to commit to insert the args into the query.
cursor.execute("Insert into links (link,id) values (?,?)",(a,b))
conn.commit()
I have that
I know its in the db file because I have a viewer to check my work
just to make sure I'm doing it right
Blah, I don't like SQL.
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE Date = ?", (Whattime2)):
but the Date has to be changeable
to other things in the database columns
or do want me to just test with that?
I'm just not finding any examples of anyone using ? as the key. Just the value.
And since only the value is what's sensitive here, you might actually have to insert the key into the string, not as an argument.
and this means what?
The key is set in your code anyway so it's safe from injection, unless the user sends it.
ok
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE %s = ?" % (Whattime), (Whattime2)):```
It means tossing away readability.
wait
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE Date = ?", (str(Whattime2))):
as I runth si
this
I get sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 3 supplied.
Added some brackets.
where exactly
Around Whattime and Whattime2
That sounds like sqlite3 thought you had three ?
Mff.
it shouldn't right?
Who even knows.
Does SQL even have floats? Isn't it INT only?
What is your Date set as in your scheme?
maybe thats my issue
Is it a string?
Whattime2?
Date
how can I tell?
Do you have a SQL scheme?
its a TEXT
Or how do you create the table?
oh my
yes
And you're most likely inserting a 5.3 float via the ?
but would converting it to a string matter?
Although I suggested earlier you should insert str(Whattime2)
yea
Give it a go
change what exactly?
? = ?, (Whattime, str(Whattime2))
isn't that what I've been doing the entire time
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE Date = ?", (str(Whattime2))):
Oof.
I don't know what else it could be
Remove the args and change ? to 5.3
Just always select Date = 5.3
that works
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE Date = 5.3"):
that is
Now you change Date to a ?, and add the (Whattime) as the args
Still always testing 5.3
it sais there is 4 supplied
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE ? = 5.3", (Whattime)):
let me convert it to a string
still sais 4 supplied as I type in Date
Add a comma. (Whattime,)
I'd say that you cannot use ? for keys. Only values. Can't find a single example of a key injection
so I have to use %s?
Beautiful
just the Whattime part that doesn't work apparently
I am
>>> name = 'Fred'
>>> age = 42
>>> f'He said his name is {name} and he is {age} years old.'```
I learned about f-strings only today. It's like christmas 🎁
Give this a try.
wait what?
Instead of the ugly %s. No one likes those.
so my final result would be?
f"SELECT * FROM Runningtimesof2018 WHERE {Whattime} = ?"
f at start and {Whattime}
Should rename those variables to Whatkey and Whatvalue or something~
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 0 supplied.
I will
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 0 supplied.
Oh, that error has to do with the args
You NEED the comma at the end to make it a tuple
(Whattime2,)
Or you just change it to [Whattime2]
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE {} = ?".format(Whattime, Whattime2,)):
so like this?
No. The format has to do with the {} and Whattime. The (Whattime2,) goes at the end into execute
for row in c.execute("SELECT * FROM Runningtimesof2018 WHERE {} = ?".format(Whattime), [Whattime2]):
this worked
did we just do it?
query = "SELECT * FROM Runningtimesof2018 WHERE {} = ?".format(Whattime)
result = c.execute(query, [Whattime2])
for row in result:
what I did above got me the same answer
so is this immune to injection attacks
oh
so just re format it like yours?
or would that still have an issue
Only difference is that I split it into variables query/result
Anyway, it's injection safe as long as the Whattime key only comes from within your code. The user should definitely not request those.
Does it work?
anyways, none of my friends use my computer
yea, as I mentioned above, it works using my and your final products
thanks you so much for your patience
Hehe, no worries.
I'm sorry for the inconvenience
I honestly get stuck with issues like these all the time, and instead of just doing the cheap solution, I wanna know what's causing it.
Except it turns into hours of debugging.
well that payed out
👌
So I'm doing this course called Algorithmic problem solving, and it's all about a writing code for a small problem and sending it to an online judge.
And it takes maybe an hour to write the code, and 4 hours to debug it because the online judge says it's spitting out the wrong result.
If that didn't give me enough patience, guh.
In SQLite how would i make a leaderboard system
Where it grabs every user and then displays the top 10 users in XP
I got something that is sorta like it but it just auto creates a user account
async def check_all_members():
bot.c.execute('SELECT UID from Profile')
rows = bot.c.fetchall()
for member in bot.get_all_members():
if not any(row[0] == member.id for row in rows):
bot.c.execute('INSERT INTO Profile (UID, XP, LEVEL, SCROLLS) VALUES(?, ?, ?, ?)',(member.id, 0, 0, 0))
bot.conn.commit()
print('{} has no Account! Account Created.'.format(member.id))
I guess you can use keywords like ORDER BY
🤔
SQLBolt provides a set of interactive lessons and exercises to help you learn SQL
something like these
so in a way:
SELECT UID, xp (or *) from Profile
ORDER BY xp DESC
LIMIT 10 OFFSET 0;```
something like that
I'm still rather new on SQL itself so that's the best I can do
Or could i make it re organize The DB
huh?
async def on_message(self, message):
self.bot.c.execute('UPDATE Profile SET XP=XP+5 where UID = {}'.format(message.author.id,))
self.bot.conn.commit()
cursor = self.bot.c.execute('Select XP from Profile where UID = {}'.format(message.author.id,))
row = cursor.fetchone()
print('{} has received 5 XP {} / 100(LVL UP)'.format(message.author.id, row))
if row[0] % 100 == 0:
self.bot.c.execute('UPDATE Profile SET Level=Level+1 where UID = {}'.format(message.author.id,))
cursor2 = self.bot.c.execute('Select Level from Profile where UID = {}'.format(message.author.id,))
row2 = cursor2.fetchone()
if row2[0] % 10 == 0:
if not row2[0] >= 280:
self.bot.c.execute('Update Profile SET Scrolls=Scrolls+1 where UID = {}'.format(message.author.id,))
self.bot.conn.commit()
So this event is where whenever someone chats they gain 5 XP
But what if i could make it move their row up if their XP is higher than another user
well
there's no so called "move row up" in RDBSM (or w/e its acronym is) IIRC
you just do the filter by SQL
We could check and see what other DB services do
Cause they are usually all the same
Or similar
yeah I don't think any of those lets you change a position of a certain data physically
you can only achieve that via filtering
Ok well i am gonna need to add a UNAME cagetory to my bot
So this will probably be a full DB reset
why not just grab user by user ID?
also you don't really need to reset a DB in order to add a new column
like there's a reason guild.get_member() exists
So i could actually do it without needing a new column
yes
Cause in my bot if a user already has a Account in the DB it won't make another or implement anything new
It only puts in the stuff it needs to function
you can just grab the username the next time a new message go through
also it's useless since it's editable
What is
recording usernames in a database
an user ID is sufficient
oh right speaking of which
I'm considering writing a simple DSL to make my bot database-agnostic
is there any reason why I shouldn't combine create/update into one?
@woeful ivy ?
self.bot.c.execute('SELECT XP from Profile ORDER BY xp DESC Limit 10 OFFSET 0')
something like that ye
Would i need it to place into a variable the value?
or @light summit for the question above
Cause it currently only selects
self.bot.c.execute('SELECT Weapon1 from Profile where UID = ?', (ctx.message.author.id,))
result = self.bot.c.fetchone()
if(result != None):
WeaponID1 = result[0]
This is injecting the values it is taking into a Variable
¿Qué?
?
about why shouldn't I combine create/update into one for database
Also what do you mean by that ngb
nah that's for thane
Idk. I don't SQL
¯\_(õ.ô)_/¯
so not much good reasons to not combine create/update?
in terms of CRUD
@orchid charm also no, not really
I should ask DAPI
Man, I'm not super knowledgeable db wise
rip
I'm wanting to stop using Redis and start using either Rethink or something
do it already
If you seek answers ask god
Also I Spot A IFUNNY watermark
Keep it chill, dude.
@commands.command()
async def leaderboard():
self.bot.c.execute('SELECT XP from Profile ORDER BY xp DESC Limit 10 OFFSET 0')
lbresult = self.bot.c.fetchone()
print(lbresult)
So like that?
Ignoring exception in on_message
Traceback (most recent call last):
File "/Users/shanehawkins/Library/Python/3.6/lib/python/site-packages/discord/ext/commands/core.py", line 371, in _parse_arguments
next(iterator)
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/shanehawkins/Library/Python/3.6/lib/python/site-packages/discord/client.py", line 224, in _run_event
yield from coro(*args, **kwargs)
File "/Users/shanehawkins/Library/Python/3.6/lib/python/site-packages/discord/ext/commands/bot.py", line 920, in on_message
yield from self.process_commands(message)
File "/Users/shanehawkins/Library/Python/3.6/lib/python/site-packages/discord/ext/commands/bot.py", line 916, in process_commands
yield from self.invoke(ctx)
File "/Users/shanehawkins/Library/Python/3.6/lib/python/site-packages/discord/ext/commands/bot.py", line 886, in invoke
yield from ctx.command.invoke(ctx)
File "/Users/shanehawkins/Library/Python/3.6/lib/python/site-packages/discord/ext/commands/core.py", line 507, in invoke
yield from self.prepare(ctx)
File "/Users/shanehawkins/Library/Python/3.6/lib/python/site-packages/discord/ext/commands/core.py", line 471, in prepare
yield from self._parse_arguments(ctx)
File "/Users/shanehawkins/Library/Python/3.6/lib/python/site-packages/discord/ext/commands/core.py", line 374, in _parse_arguments
raise discord.ClientException(fmt.format(self))
discord.errors.ClientException: Callback for leaderboard command is missing "self" parameter.
@terse fable That is my error now that i use that command
Wait
I think i know what i forgot
I forgot to add self as a arg
Hmm
Still same error?
¯_(ツ)_/¯
Well if anyone knows how to make a Leaderboard in Sqlite let me know
@orchid charm What do you mean by "leaderboard"?
It lists the top 10 users with the most value in a specific column
Like this
Squint has 100000 XP
otheruser has 1243 XP
ect.
something like SELECT TOP 10 User, Experience...GROUP BY User ORDER BY Experience DESC?
not sqlite though
How can I make it to just print golds?
Because now it shows this
@bot.command(pass_context = True)
@owner_only()
async def mygolds(ctx):
for item in db:
await bot.say("You have {} golds.".format(item))```
this is more of a question about how dictionaries work, I imagine
are you familiar with how dictionaries work?
no
that would be the place to start, then. https://docs.python.org/3/tutorial/datastructures.html#dictionaries
take a look at that and let us know if you've got any questions
@bot.command(pass_context = True)
@owner_only()
async def mygolds(ctx):
for id, golds in db:
await bot.say("You have {} {} golds.".format(id, golds))```
The bot replies with You have id golds golds. lol
How can I get the vlaue
and not the name
what is db @torn sphinx ?
How can I make a reference to all the columns in a Query, like SELECT * FROM table Where column = {}
nvm, I feel idiotic
what even were you asking haha
idk anymore, I did select *, then I realized, wait, I don't need to select all
yeah that confused me :D
^^
@gusty spindle Database
@torn sphinx well.. yeah, obviously, but what was your variable?
@gusty spindle db = TinyDB('data.json')
@bot.command(pass_context = True)
@owner_only()
async def mygolds(ctx):
for asd in db:
player = asd["id"]
golds = asd["golds"]
await bot.say("Member id: {}".format(player))
await bot.say("Golds: {}".format(golds))```
How can I make it show only my golds that match my id? and not all peoples golds
@torn sphinx you're iterating over every row in the DB right? you need to get the specific one you're looking for
hey.. so with my bot, i have an xp system.. it's a code that my friend gave me.... it woks perfectly but what i want is to store the data on my database.. but i dont know much about database's. (I am using CouchDB) so far, the bot creates a document but i want the bot to see whether the user is on the database with the id and then if the user is on it, just update their xp , but if the user is not on the database, make a document with their id and their xp. then i want to grab the data back and when user does ~rank , i want the bot to send their xp thats on their document.
that was sooo hard to explain
how can i get the bot to check if the document is already there, then decide what to do
no he is using couch db which uses documents instead of tables @hexed epoch
why does every user have a different table 🤔
you have to think about it like json
oh that makes sense
@crisp robin if you search for that particular user and nothing is returned you know they arent in the database, which in that case you can insert that user into the DB
Is there any other dB I could use cus I'm struggling with couchdb.. and is tables easier than documents..
@crisp robin do you use Sqlite?
Cause i coded a XP system that works perfectly fine in my bot
async def on_message(self, message):
self.bot.c.execute('UPDATE Profile SET XP=XP+5 where UID = {}'.format(message.author.id,))
self.bot.conn.commit()
cursor = self.bot.c.execute('Select XP from Profile where UID = {}'.format(message.author.id,))
row = cursor.fetchone()
levelcursor = self.bot.c.execute('Select Level from Profile where UID = {}'.format(message.author.id))
levelrow = cursor.fetchone()
print('{} ({}) is level {} and is {} / 100 away from Leveling up'.format(message.author.id, message.author.name, levelrow, row))
if row[0] % 100 == 0:
self.bot.c.execute('UPDATE Profile SET Level=Level+1 where UID = {}'.format(message.author.id,))
self.bot.c.execute('UPDATE Profile SET XP=0 where UID = {}'.format(message.author.id,))
cursor2 = self.bot.c.execute('Select Level from Profile where UID = {}'.format(message.author.id,))
row2 = cursor2.fetchone()
if row2[0] % 10 == 0:
if not row2[0] >= 280:
self.bot.c.execute('Update Profile SET Scrolls=Scrolls+1 where UID = {}'.format(message.author.id,))
self.bot.conn.commit()
Just remove a small bit of this and it would work for what you wanna do
Hello, am i in the right chanel for infos how to generate textfiles ?
Do you know where i can go ? Datascience ?
i just want to creat textfiles when reading an array, i managed to creat the new files, and right into it
but im stuck, becaus i want th
*but im stuck because i want lines instead of columns
Data = open("data_test.txt", "r")
lines = Data.readlines()
i=0
#file = open("Imput.txt", "w")
for element in lines:
filename='data_%d.txt'%(i,)
file = open(filename, "w")
X0=i
X1=i+1
X16=i+16
X24=i+24
X28=i+28
X30=i+30
X31=i+31
X32=i+32
Imput = [lines[X0],lines[X1],lines[X16],lines[X24],lines[X28],lines[X30],lines[X31],lines[X32]]
#print (i)
print (Imput[0])
file.writelines(Imput)
i=i+1
file.close()
The python help channels is what you should be asking this in then
hey
can someone help me to understand how mongodb atlas works?
it says Free MongoDB Cluster and also pay only for what you use, that means "is free under this limits"?
yes, is "free under this limits":
The free tier grants you 512 MB of storage for learning MongoDB, prototyping your application, and early development.
hey.. which is the best and easiest database to use for my xp system for discord bot
easiest? sqlite
i migrated mine from sqlite to postgresql though
there's this which works with postgresql, and it's really nice https://github.com/05bit/peewee-async
i use it in my bot
which is easier..
I need to know how I could access the file that holds the blocks, or read this file!
I've already seen something with Node + LevelWeb and also what else I'm trying to do would be with Python + plyvel
Who can help me???
Remembering that it is not by RPC I want to access the file that is written on the machine I think it would be the .ldb file
Thank you very much for helping me!
Sorry, I thought you could post here!
packs a cryptomoeda wallet!
@crisp robin sqlite is easier to set up because you can just give it some filepath and it works, there's no sort of database creation or authentication involved
Blocks*
Asking good questions will yield a much higher chance of a quick response:
• Don't ask to ask your question, just go ahead and tell us your problem.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
• Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
It is related in some way with database, although it is not relational database, it is a way of storing data stepped
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
??
I did not ask for code
Help is not for code
Maybe i have not been clear enough, but what i would like guidance , i see a lot the internet , but i do not find anything good enough
My code:
import plyvel
db = plyvel.DB("/root/Downloads/DashCoin/000760.ldb", create_if_missing=False,)
db.put("key", "value")
for key, value in db:
print(key)
print(value)
Line error:
Traceback (most recent call last):
File "/root/PycharmProjects/DashCoin/AcessDB.py", line 7, in <module>
db = plyvel.DB("/root/Downloads/DashCoin/000760.ldb", create_if_missing=False,)
File "plyvel/_plyvel.pyx", line 247, in plyvel._plyvel.DB.init
File "plyvel/_plyvel.pyx", line 88, in plyvel._plyvel.raise_for_status
plyvel._plyvel.IOError: IO error: /root/Downloads/DashCoin/000760.ldb/LOCK: Not a directory
Process finished with exit code 1
how do you interact two tables in a database
like for example. I have budget in Plan table and I have cost in Meal table
how do I deduct the budget and cost
I.. am sorta draining off a bit xD
@real thistle do you have something that links the budget and the cost
I put MealID at the Plan table does it help @ornate abyss
@real thistle Yea, so you can do something like
SELECT Plan.mealID, (Plan.budget - Meal.cost) FROM Plan, Meal WHERE Plan.mealID = Meal.id
oops
@ornate abyss by storing it to a variable would it be a permanent so that a plan entry could show how much budget would be lost from that meal?
Im not sure what you mean
wait
Alright
my code runs like this
https://pastebin.com/2s9wgEQM
basically it's a meal planner that each food you decide to take on a week, your budget will be deducted from the meal cost.
should I make a new variable to store the changes in a plan entry so that it would appear how much the budget has been decreased from all the food in your weekly plan
Well im assuming each time they buy something its just added to the Meal table no?
So when they buy something, and its linked to a certain Plan itll just minus it already
@ornate abyss ah so it will be automatic? I need another function to attach a Plan to meals, right? I assume you looked into the code
i just skimmed over, nothing serious
I need another function to attach a Plan to meals why? they are linked already by the foreign key
ah so it will be automatic as long as they are in the database and linked to a Plan they will be subtracted from the budget, yes
@ornate abyss I mean, in the GUI, there is still no real connection to the meal itself. I think I need to add a drop-down menu or something that can inidcate which meals the plan will take
oh, that's it, a checkbox
wait, nvm
IDK if a checkbox would be proactive, on additions in the database...
if levelrow < 5:
levelcursor = self.bot.c.execute('Select Level from Profile where UID = {}'.format(ctx.message.author.id))
levelrow = levelcursor.fetchone()
What am i doing wrong?
my "Level" is 58
Do i need to convert to a int or somethin
Its saying it ain't supported between tuple and int
fetchone() fetches a row, iirc
and a row is represented as a tuple
print levelrow to see what it is
(58, )
That is what it shows me in my XP adder which is where i got this code from into this command
What would i do to fix this?
so levelrow = int(levelrow[0]) ?
try it and see
I think it is doing what it is supposed to
you probably don't need the int
Cause it is doing nothing
given that Level is stored as an int
Which is what it is supposed to for now
Cause my level is above 5
I will probably make a event for the hub now
Cause this "Hub" is gonna be infinately backable and forwardable
How do I create a dropdown menu from a set of data in one of my tables?
Do you mean accessing the table, or the dropdown part is stressing you
Anyone ever going along with mongoDB ?
I assume you would just query from whichever, or do you want an input?
what I want to do is to be able to link it up Since, I got the data part as the foreign key for another table. What I want is to add it to a Plan
wait
this is my code for now
I am planning to add another function, where i am able to add Meals to a Plan. So I thought a dropdown menu to add meals on a plan would be a great way to attach meals on it. The mealID is already linked to Plan table as a foreign key. I only need to add which specific meal in every plan
I'm not very experienced with this stuff, I hope someone else can help you
ahhh okay thanks anyway 😄
I usually use PyQt. Sorry man
how about this one
def mealplan():
if (bdg.get() >= 0):
cur.execute ('insert into Plan(mealID) values(?) where planID=(?)', (choption.get(), choptionu.get()))
con.commit()
budget = cur.execute('SELECT Plan.mealID, (Plan.budget - Meal.cost) FROM Plan, Meal WHERE Plan.mealID = Meal.id')
else:
messagebox.showinfo("You've stretched your budget", "Sorry! But your budget is not sufficient for you to add another food")
filewin=Toplevel(root, bg="#39FF14")
lblPlanID=tk.Label(filewin,text="Plan ID ",bg="#39FF14", font="Arial 12 bold")
lblPlanID.grid(row=1,column=1)
optionu=[]
cur.execute('SELECT * from Plan')
con.commit()
result=cur.fetchall()
for row in result:
optionu.append(row[0])
optionub=ttk.Combobox(filewin, width=7, values = optionu)
optionub.grid(row = 1, column = 2)
option=[]
lblMealID=tk.Label(filewin,text="Meal ID ",bg="#39FF14", font="Arial 12 bold")
lblMealID.grid(row=2,column=1)
cur.execute('SELECT * from Meal')
con.commit()
result=cur.fetchall()
for row in result:
option.append(row[0])
optionub=ttk.Combobox(filewin, width=7, values = option)
optionub.grid(row = 2, column = 2)
choptionu=StringVar()
choptionu.set(optionu[0])
choption=StringVar()
choption.set(option[0])
btnOK=tk.Button(filewin,text='OK',command=mealplan,bg="#FFFFFF",bd=3,height = 0, width = 8,font="Arial 10 bold")
btnOK.grid(row=3,column=1)
getting near where error
anyone cthat can help me out here...
nvm
tried something out
i need hellp
please
https://hastebin.com/gabicawova.py
i want to implement SQlite into there.. i tried many ways but it just isnt working out as well as i think it would.. i dont have much knowledge about Db's btw..
please mention me
Read the Sqlite docs m8
you're really not someone who should tell other people to read docs
@crisp robin what have you tried already & what did you run into issues with?
Hi. Most languages use strings to create SQL and interact with databases. I wish to create a DSL dialect to solve this issue. I'm stack on views. I'm not sure how to deal with 1:M situation. So I'm not sure my design will work and I need ideas. Any one wish to contribute?
bot.tags['ask']
Asking good questions will yield a much higher chance of a quick response:
• Don't ask to ask your question, just go ahead and tell us your problem.
• Try to solve the problem on your own first, we're not going to write code for you.
• Show us the code you've tried and any errors or unexpected results it's giving
• Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
Ok ok
So
There is a table called LDL_Cholesterol
And three categories within it (Classification, Min, Max)
I have no prior experience with SQL, would I do
SELECT LDL_Cholesterol
or
SELECT Classification from LDL_Cholesterol
I need to find two things under the Classification category.
The second will select Classification from every row
The first isn't a complete query
when I work with DB containing simple strings, it works thousands times slower than numeric Ids Is there any way to automatically replace the equal words by equal numbers?
im unsure what you're asking..
how can I make the json
on next line
I tried \n at end
and it didnt work
I just have one massive line of json
the JSON outputted by json.dump?
Just as a side note based on your code; you're not allowed to store unencrypted data about discord users other than ID. Afaik
why was that asked in here :(
So I'm using ORDER BY column
but it isn't ordering it as I would like, I have the values 5.3, 5.10, 5.15, and 5.17 stored in this column
wait, I might be an idiot
every time I ask a question I swear
I think that's called rubber duck troubleshooting
You explain the problem to the rubber duck, and by the time you're done, you've figured out the answer
^ rubber duck debugging is our favorite
hey yall - do you know of any free db hosting?
I know some pretty cheap VPS hosting?
by cheap I mean cents per month
eventually itll go on a vps
o dang
hmm i'll probably use heroku/cleardb until performance becomes an issue
then migrate ig
link?
and they have a super cool app that's fully functional (it even let's you use your vps via ssl)
just look up google cloud compute
Google Cloud provides flexible infrastructure, end-to-security, modern productivity, and intelligent insights engineered to help your business thrive.
@wispy fable someone said a few cents a month? except if its not amazon where you have to use cc
any debit card with visa works too
Friend is looking for a good MySQL package, any recommendations from the experienced among you?
MySQL community version is good, I use it with the workbench which makes it even easier
https://github.com/edgedb/edgedb I'm hyped
looks interesting
WITH
Alice := (SELECT User FILTER .login = "alice"),
Bob := (SELECT User FILTER .login = "bob")
wouldn't the filter operation return multiple objects though..?
built-in migration support is definitely interesting imo but aside from that i dont see how a python database would be performant
@ionic pecan This is how: https://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python
Oh, would it be on the same level as postgres for discord bots then?
what
Oh, I was confused by same level
That depends on the client implementation
There is already an async postgres client impl though https://github.com/MagicStack/asyncpg
or https://github.com/05bit/peewee-async if you're into ORMs
I use the latter
Yeah, I'm using asyncpg
Is there a injection for update if possible else insert ?
query = "SELECT * FROM members WHERE id = $1 AND guildid = $2;"
if await self.bot.db.fetchrow(query, member.id, ctx.guild.id):
update = """UPDATE members SET
ap = $1,
aap = $2,
dp = $3,
level = $4,
class = $5,
gearpic = $6
WHERE id = $7;"""
else:
insert = """INSERT INTO members(
id,
guild_id,
ap,
aap,
dp,
level,
class,
gearpic) VALUES ($1, $2, $3, $4, $5, $6, $7, $8);"""```I'm currently doing something like this, but feel like it could be done with one execution?
Some ORMs have an UPSERT, which is basically "insert or update". IIRC you're using PostgreSQL, so this post may provide some insight: https://stackoverflow.com/questions/17267417/how-to-upsert-merge-insert-on-duplicate-update-in-postgresql

Hello all. I need some suggestions on an error I'm getting. Thank you very much for any help you input you have.
Error: mysql.connector.errors.ProgrammingErrors: Not all parameters were used in the SQL statement.
if cursor.rowcount == 0:
add_sql = ("INSERT INTO stormdata "
"(StormName, StormID, AdvisoryNumber, Basin, AdvDateTime, Cat, Eye,"
" MoveDir, MoveSpeed, SLP, FA, PA, CD, WW, UserModified, AgencyID, CatNum) "
"VALUES (%s, %s, %s, %s, %s, %s, %d, %d, %d, %f, %s, %s, %s, %s, %d, %s, %d)")
add_data = (
self.name, self.storm_id, self.advisory_number, self.basin, self.sqldatetime, self.cat, self.eye,
self.dir, self.speed, self.pressure, '', '', '', '', 0, 'NHC', self.catnum)
# Execute the Query
cursor.execute(add_sql, add_data)
last_record_id = cursor.lastrowid
print(last_record_id)
It looks like I did the markdown wrong for discord code highlighting. 😦
ok, fixed the markdown... used apostrophe instead of back-tick 😃
try making all of the values %s
That did the trick! Thanks for your help. 😃
is there any proper way of getting the row from an sqlite cursor right after i've inserted it? i'm doing this:py cur.execute("INSERT INTO messages(name, message, created) VALUES (?, ?, ?)", data)and i need to get the resulting row's assigned primary key value. right now i'm re-searching the database with the data as conditions to get the primary key, but that seems impractical.
apparently there's an optional extension you can use https://stackoverflow.com/questions/6242756/how-to-retrieve-inserted-id-after-inserting-row-in-sqlite-using-python
oh haha goodness knows how i didn't find that after searching for 10 minutes. thanks ^^
o7
How would you for a feature like "Choose one/two/three of the following" in a database?
for column types?
i think some databases have an ENUM type, for others, you can use text and then add a constraint to check IN ('value', 'two', 'three');
Not exactly. For example: I have a list of classes to take to graduate.
Here, the course guide says to take 4 DIGI classes, then choose 3 from the list below
How do I have add "rules" to the database showing that I need 3 courses
@rain karma that doesn't really sound like something you can enforce at the DB level
If it were you how would you enforce it then? 🤔
Because I have to keep track of it somehow
@vestal apex
at the application level I'd validate the user's input
just the same as you do with, say, usernames and passwords
"hey, you can't use that password it's two characters long"
"hey, that username is already taken, you can't use that either!"
"you need to choose 3 classes from the list below and you didn't! do that now please!"
So even with an extensive list of rules like that one, you would have them all stored in the application?
I mean it hardly seems extensive, but... if I were writing a system like a class picking tool, I'd probably decide on a format I can use to write those rules down, and then have my application read rule configurations
another way to do it at the application level might be to interact with the DB using abstract models, although that seems a little rigid for this purpose
but at the DB level I am not aware of nor would I recommend a way to enforce those types of rules you listed
Yep. The DB should just enforce things like "you have too many characters in this field," "this field has to match a key in this other table," etc.
You should implement application logic in the application itself
So instead of storing the the rule configurations in a database of rows and collumns, you would have them in a type of file that you can parse through?
Doesn't really matter where you store the configurations. If you have a database already, you could use that too.
Actually, it's probably better there, if the rules are directly related to the data
^ I would do it with files because it's easy and I could easily tinker with and adapt them for other purposes, but the medium isn't significant to implementing the general concept
The file type is something that I haven't thought of. I was looking at putting this into an .csv to have it shown like a database, but honestly it's getting really hairy with trying to keep track of all the rules for each set of classes. Ex:
Some of them have more than one "Choose X courses"
So, I couldn't just do a bitfield, I'd have to have a grouping column to differentiate the groups
That's going to be a little bit complicated however you set it up, but there should be a reasonable way to implement it.
I'd probably have a Class table (with details for each class) and a Group table (with details about how many courses are required from the group). Then I'd set up a many-to-many relationship between the two.
Do a little reading on what a many-to-many relationship looks like in SQL, if you aren't familiar with it already. It's not an immediately obvious concept.
But it's very powerful once you understand it.
Well, I know that for M-N you split it up into two identifying 1-M relationships
{
'board': [[0,0,0], [0,0,0], [0,0,0]],
'turn': 0,
}
@light summit If this is my dict, how would you store it in redis?
Did you read on how namespaces work?
Not finding anything about namespaces in the docs.
I'm finding hmset("RedisKey", dictionaryToSet), but you mentioned something about not supporting multiple layers?
I'm with someone now. Give me a moment
Separate words in your key name using a ;. That creates browsable namespaces. You can use matching searches on them or just use that to organize your keys. On the surface it may look like sublevels, but it's really just a naming convention.
If you play around with Redis Desktop Manager, I promise you'll understand very quickly
@novel wharf
So, say you have a namespace for games. Then, under games, you can have namespaces that are the IDs for each game. Under that, you can have keys for tables, rows, turn, etc. however you want to store the data
games;1234567;table # list of string dumped rows or separate keys for row lists. Ya know, whatever totes your goat
games;1234567;turn # string
games;1234567;players # set
It may seem cumbersome at first, but with f string or what have you, it's easy to abstract out the name ugliness and keep everything well organized programmatically. Bonus point for making it a breeze to glance over with a browser
Not managing to install the redis browser on my linux.
I did it on Windows fairly straight forward, so I can't provide much help there ¯_(ツ)_/¯
There may be another better browser for Linux. I haven't done much looking
Anyway, not sure qute what you mean with the long strings of data. Is that the value I want to store?
Or is that how it's actually stored in redis?
What time zone are you in?
Uuh, stockholm, +1 GMT?
Shit. I get off work at 15:00 EDT. May be just enough time I can go over it in voice when I get home and explain it much better with screen share to help you visualize it
Consider the 45 minute drive home
Anyhow, as for now I assume that's how I should store my keys in redis? Separating with ; like in your examples.
Imagine those ; as separating directory names
So that all key names are a hypothetical full path from root
If you give them all plain Jane names, you storing all "files" in root dir
How is this necessary though? In case I somehow want all of the data connected to games for instance?
You putting anything else in redis besides your game instances?
I'm storing packed gameinfo dict, players dict, status string.
Actually, in the game lobby I'd like to collect the players dict from all tables, so a namespace fetch would be amazing.
You may want to look at scaniter.
It creates an iterable of keys that match an expression.
@light summit I can't seem to be able to set a dict as value in redis.
set and hset requires bytearray, bytes, float, int, or str type. hmset makes even less sense.
Feels like I should just use hset('table:id', key, json.dumps(dict))
There's also no such thing as scan_iter. Perhaps I'm using a different version. Although it's just calling self.scan and yields.
But alright, I guess if I use hset, using tableid and key, I can do a hscan of tableid and get all of its data.
Hello guys I have a problem. I am trying to set up a leveling up system. If I do .level @Blload#6680 its tells me what rank I am now and how many exp I have. Once I rank up and then I do again .level @Blload#6680 it doesnt respond. I do that for like paste that like 3 - 4 times then it works. It shows my new rank and exp but why it works only after 3 tries?
it has something to do with the exp set I thinki I dont know. I also have made the bot to Congratulate the user in the rank up and also made a check so if the user is already that rank it wont congratulate him again. and this is where the problem is I think. Because I put return after the check so it doesn continues to the next if statement
You sure you want to check for exact exp, and not a range between 5 < x < 20
A nice way to debug your code is to add a lot of prints. Find out where your code runs and what steps it's skipping.
If you're doing very specific if-statements, it feels like you might have a case that gets ignored or returned too early, and you wouldn't get a reply.
I used to add a shit ton of prints (and still some times do), but PyCharm's debugger is actually really nice. Throw in some breakpoints and run. It'll stop at each, show you all the objects in mem, and allow you to step through your code.
Okey I will try that thanks
can anyone help with aws database deployment?
please?
so i set up a RDS and i know something is wrong with the security group. when i telnet the url at 3306, i get a Could not open connection to the host, on port 3306: Connect failed Right now the security group rules should be allowing for connections, the only inbound rules are these: https://i.imgur.com/90ClqpG.png i'm super frustrated idk
also i know i can use 3306 on my local since i can connect to other dbs
hey folks - i was just talking with @terse stump and they suggested i come here to ask for advice about what database i should run for my project - i can tell you a bit about it here. so far i think i need a time series db like Grafana or InfluxDB.
i am gathering SEO performance metrics like domain authority and keyword rankings for a number of websites and their competitors.
i want to store them in such a way that I can then graph them and present them to our clients, and they can view these metrics over time so: last week, last 3 months, last year etc.
i'm confident that i can scrape the metrics that i'm after using python but i'm a bit clueless when it comes to importing them to a database and could do with some with advice on how to get started with this. someone suggest SQL to me in the past, but that wouldn't apply to a time series DB would it?
Time series databases are a very specific thing
rdb for example
What they do is aggregate data based on granularity
The further back you go, the less granularity it keeps
So you can have the last week, then averages for the last three weeks, the last month, the last six months, the last year, etc
Very efficient
I believe it's known as time bucketing
@viral crag
I'm looking for something that will display the true figures from each month, so let's say April 2018, the Domain Authority for my client's website was 50.
March was 49, February was 49, January was 47, etc. I'd like that to go as far back as possible and also graph the competitors Domain Authorities on the same graph but a different coloured line.
Is that easy to do? Do I want a time series DB for this, or is it overkill?
or maybe i'm jumping the gun by talking about displaying them at this stage?
It depends on the granularity you need
Obviously if you need accurate figures for every month ever then dropping granularity is not what you want
by granularity do you mean tiny fluctuations over a small space of time, like server load or web traffic?
i'm confused 😄 sorry
Well we've established that a time series database isn't going to work for you
ok 😃
Since you're going to be doing a lot of increments
You'll want a database that has that built into the query language
That way you can do the changes entirely on the server
Instead of having to get the data, change it, and put it back
Other than that, anything should be fine really
ok, i think i understand. so even something like MSSQL might work?
but avoid time series DB altogether you're saying?
you can still use Grafana with an SQL data source
so grafana is a good way of displaying the data as i want it, but not a database as such? sorry for being thick. i'm really new to the idea of databases and trying to grasp how they work compared with google sheets and excel.
grafana display data
and 