def users_in_db(message):
with sqlite3.connect(db) as conn:
with conn.cursor() as cursor:
sql_users_in_db = """SELECT chat_id FROM users WHERE chat_id = ?;"""
cursor.execute(sql_users_in_db, message.chat.id)
users = cursor.fetchall()
print(users)
if users:
return True
return False
@dp.message_handler(commands=["users"])
async def process_start_command(message: Message):
if users_in_db(message):
print("зареган")
else:
print("не зареган")
To fix this error install pymongo with the srv extra...
python -m pip install "pymongo[srv]"
from collections import defaultdict
a = [{'a': '1', 'b': '2'},
{'a': '1', 'b': '2'},
{'a': '5', 'b': '7'}]
b = [{'a': '3', 'b': '4'},
{'a': '1', 'b': '2'}]
def make_hash_table(list_of_dicts):
hashes = defaultdict(list)
for i, item in enumerate(list_of_dicts):
calculated_hash = hash(frozenset(item.items()))
hashes[calculated_hash].append(i)
return hashes
# Считаем хеши
a_hashes = make_hash_table(a)
b_hashes = make_hash_table(b)
# Определяем через вычитание множеств каких хешей у нас нет
not_in_a = [b[b_hashes[hash_value][0]] for hash_value in b_hashes.keys() - a_hashes.keys()]
not_in_b = [a[a_hashes[hash_value][0]] for hash_value in a_hashes.keys() - b_hashes.keys()]
print('Not in a \n')
print(not_in_a)
print()
print('Not in b \n')
print(not_in_b)
Not in a
[{'a': '3', 'b': '4'}]
Not in b
[{'a': '5', 'b': '7'}]
from tkinter import *
from tkinter import messagebox as mb
root = Tk()
root.geometry('500x200')
root.resizable(False, False)
root.title('Деление на 3')
root['bg'] = 'grey22'
txt = Label(text='Напишите число:', fg='white', bg='black')
txt.grid()
ent = Entry()
ent.grid(column=2, row=0)
def divBy3():
num = ent.get()
if not num.isnumeric():
mb.showerror(title='Ошибка', message='Произошла ошибка. Вы написали не число')
else:
num = int(num)
oper = num / 3 # get принимает только строки :(
if num % 3 == 0:
mb.showinfo(title='Информация', message='Число делится на 3, результат: ' + str(oper))
elif num % 3 != 0:
mb.showinfo(title='Информация', message='Данное число не делится на 3!')
btn = Button(text='Нажать', width=15, command=divBy3)
btn.place(x=250)
root.mainloop()
import random
fonts = ['1.ttf', '2.ttf', '3.ttf']
font = random.choice(fonts)
import base64
from io import BytesIO
from PIL import Image, ImageChops
a_base_64 = 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DA' \
'cdvqGQAAAAWSURBVBhXY3BwcGBgYGD8//8/AwMDABgGA7/DZDVsAAAAAElFTkSuQmCC'
b_base_64 = 'iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DA' \
'cdvqGQAAAAVSURBVBhXY/z//z8DAwMTEDMwMAAAJAYDAbrboo8AAAAASUVORK5CYII='
a = Image.open(BytesIO(base64.b64decode(a_base_64)))
b = Image.open(BytesIO(base64.b64decode(b_base_64)))
diff = ImageChops.difference(a, b).convert('L')
print(sum(diff.point(bool).getdata()))
2
Process finished with exit code 0
# Save this file as .wol_config.ini in the same directory as wol.py
[General]
broadcast=192.168.1.255
[myPC]
mac=00:2a:a0:cf:83:15
[myLaptop]
mac=00:13:0d:e4:60:61
wol.py myLaptop
var result = [];
var offset = 0;
var peer_id = 123456;
var count = 100;
var cycles = 20;
while (cycles != 0) {
result.push(API.messages.getHistory({"peer_id": peer_id , "count":count, "rev": 1, "offset":offset}));
offset = offset + count;
cycles = cycles - 1;
};
return result ;
timedelta(days=REMOVE_DATA_OLDER_THAN_DAYS)
timedelta(minutes=REMOVE_DATA_OLDER_THAN_MINUTES)
pip install .
, находясь в корневой директории репозиторияa = "100 80 40 30 120"
a = sorted([int(x) for x in a.split(' ')])
print(a)
[30, 40, 80, 100, 120]
Process finished with exit code 0
https://www.nowgoal.pro/gf/phone/livechange.txt?flesh=0.8612462102244902
1901759^3^20210312023000^20210312033818^1^0^0^0^0^1^0^4^0.50^^11^3^1^^1^3!1988407^-1^20210312023000^^1^4^1^1^0^0^0^0^^^0^0^0^^0^0
run == "Массу" or "m":
run == "Массу" or run == "m":
run in ['Массу', "m"]:
import random
old_state = random.getstate()
print(random.random())
random.setstate(old_state)
print(random.random())
# You can also restore the state into your own instance of the PRNG, to avoid
# thread-safety issues from using the default, global instance.
prng = random.Random()
prng.setstate(old_state)
print(prng.random())
0.845561713648235
0.845561713648235
0.845561713648235
ET.ElementTree(data).write("xml.xml")
<yml_catalog><offer><name>имя abc</name></offer></yml_catalog>
ET.ElementTree(data).write("xml.xml", encoding='UTF-8')
<yml_catalog><offer><name>имя abc</name></offer></yml_catalog>
//*[@class='testCard']/a
def parse(self):
self.go_to_questsions_page()
slide_elems = self.driver.find_elements_by_class_name("testCard")
f = open("text.txt", "w")
f.write(str(slide_elems))
for el in slide_elems:
print(el.get_attribute('href'))
как его активировать при помощи request или каким либо другим способом
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
elements = driver.find_elements_by_css_selector('.new-posts .post-item a')
page_urls = [element.get_attribute('href') for element in elements]
for url in page_urls:
driver.get(url)