SELECT * FROM Products
WHERE Date BETWEEN 1669013940394 AND 1669618553557;
from datetime import datetime, timedelta, timestamp
day = '12/Oct/2013'
dt = datetime.strptime(day, '%d/%b/%Y')
start = dt - timedelta(days=dt.weekday())
end = start + timedelta(days=6)
print(start.strftime('%d/%b/%Y'))
print(end.strftime('%d/%b/%Y'))
print(int(timestamp(start)*1000))
print(int(timestamp(end)*1000))
>>> a = [[1,2,3], [11,12,13], [22,33,44]]
>>> a[1][1]
12
>>> b = a[:] # копируем!
>>> b[1][1]=0
>>> b
[[1, 2, 3], [11, 0, 13], [22, 33, 44]]
>>> a
[[1, 2, 3], [11, 0, 13], [22, 33, 44]]
>>>
cur.execute("DELETE FROM datas WHERE user_id = ? AND registered < datetime('now','-1 day')", (user_id))
{"0": {"Date": "2022-07-15 11:25:19" .....},
"1": {"Date": "2022-07-15 11:26:19" .....},
"2": {"Date": "2022-07-15 11:27:19" .....},
"3": {"Date": "2022-07-15 11:28:19" .....}
...}
import json
import pprint
data = """
{
"0": {"Date": "2022-07-15 11:25:19", "Name": "Name-0"},
"1": {"Date": "2022-07-15 11:26:19", "Name": "Name-1"},
"2": {"Date": "2022-07-15 11:28:19", "Name": "Name-2"},
"3": {"Date": "2022-07-15 11:23:19", "Name": "Name-3"}
}
"""
data_ = json.loads(data)
data__ = [v for v in data_.values()]
pprint.pprint(sorted(data__, key = lambda measure: measure['Date']))
asyncio.ensure_future(check_time())
пишем loop.ensure_future(check_time()) import asyncio
from datetime import datetime
async def check_time():
utc = datetime.now()
print(utc)
async def checker(timeout):
while(True):
await asyncio.sleep(timeout)
await check_time()
loop = asyncio.get_event_loop()
task = loop.create_task(checker(60))
loop.run_forever()
servers_sql.execute(f"INSERT INTO servers(admin_channel) VALUES ('{channel}') WHERE guild = '{guild}' ")
leah@leah-pc ~> python3
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> imgsrc = b'\xd9\x01\x10\x02TZH\x00(\x00\xa2\x8b\x80Q@\x05\x14\x00QJ\xe0\x14P\x01E0\n(\x00\xa2\x80\n(\x00\xa2\x90\x05\x14\xc0(\xa0\x02\x8aL\x02\x8a\x00(\xa6\x01E\x00\x19\xa2\x90\x05\x14\x00QL\x02\x8aL\x02\x8aw\x00\xa2\x80?\xff\xff\xff\xff\xd9\x00\x0bV\x00\x00'
>>> file = open('myimage','wb')
>>> file.write(imgsrc)
80
>>>
leah@leah-pc ~> file myimage
myimage: data
leah@leah-pc ~> hexdump myimage
0000000 01d9 0210 5a54 0048 0028 8ba2 5180 0540
0000010 0014 4a51 14e0 0150 3045 280a a200 0a80
0000020 0028 90a2 1405 28c0 02a0 4c8a 8a02 2800
0000030 01a6 0045 a219 0590 0014 4c51 8a02 024c
0000040 778a a200 3f80 ffff ffff 00d9 560b 0000
0000050
import hashlib, uuid
salt = uuid.uuid4().hex
hashed_password = hashlib.sha512(password + salt).hexdigest()
#!/usr/bin/python3
import hashlib, uuid
SEPARATOR = "&"
# generate hash string with salt
def gen_hash(pwd, salt):
return hashlib.sha512(pwd + salt).hexdigest()
# generage hash password string (for safe to file)
def gen_pw_string(pwd):
salt = uuid.uuid4().hex
return salt + SEPARATOR + gen_hash(pwd, salt)
# parse hash password string, split it by salt and password hash
def parse_pw_string(pwstring):
return pwstring.split(SEPARATOR)
# check password by its password hash string
def check_pwd(pwd, pwstring):
salt, _pwhash = parse_pw_string(pwstring)
pwhash = gen_hash(pwd, salt)
return pwhash == _pwhash
### test time!
pwd1 = "123456"
pwd2 = "qwerty"
# genetate hash strings (may be saved to file or DB)
pwstring1 = gen_pw_string(pwd1)
pwstring2 = gen_pw_string(pwd2)
print(pwd1, pwstring1)
print(pwd2, pwstring2)
# check passwords
# must be True
print(check_pwd(pwd1, pwstring1))
print(check_pwd(pwd2, pwstring2))
# must be False
print(check_pwd(pwd1, pwstring2))
print(check_pwd(pwd2, pwstring1))
('123456', 'f2b56ad9006a475e8c4f9b64446c3f5b&46c2d252a2667cc4b5a754ef5816e981570fd4bd9ced3ed1a6f6aaeae8ae83b795d6ffb66b3fe34650469b1c0d537785c2611157d41ebee6e54dc09527600a0c')
('qwerty', 'f2b56ad9006a475e8c4f9b64446c3f5b&3da9c4223c9fa2c66f5d70432401db14a89ddfe6feb99423083d152f98ef199d484b95b09a6535c766f28223c422cd1d862250867c12c7077144564b5c3fbc79')
True
True
False
False