import xml.etree.ElementTree as ET
xml_file = r'C:\metadata.xml'
tree = ET.parse(xml_file)
root = tree.getroot()
for elem in root.findall('meta'):
meeting_name = elem.find('meetingName').text
sql = r"..."
cursor.execute(sql, [uid])
id = 123
name = 'alekssamos'
sql = "SELECT * FROM TABLE WHERE id = ? and name = ?"
cursor.execute(sql, (id, name))
from tkinter import *
def check_bmi(h, w, a):
bmi = round(w / (h / 100) / (h / 100), 2)
if bmi < 16.5:
result = 'очень плохо'
elif 16.5 <= bmi < 18.5:
result = 'недостаточная масса тела'
elif 18.5 <= bmi < 25:
result = 'нормальный вес'
elif 25 <= bmi < 30:
result = 'избыточная масса тела'
else:
result = 'Ожирение!'
return result
def bmi_index():
if not entry1.get() or not entry2.get() or not entry3.get():
label4.configure(text='заполните все поля')
label4.pack()
else:
height = float(entry1.get())
weight = float(entry2.get())
age = int(entry3.get())
bmi = check_bmi(height, weight, age)
entry1.delete(0, END)
entry2.delete(0, END)
entry3.delete(0, END)
label4.configure(text=bmi)
label4.pack()
if __name__ == '__main__':
root = Tk()
f1 = Frame()
f1.pack(side=LEFT, padx=10)
entry1 = Entry(f1)
label1 = Label(f1, text="рост в см", justify=LEFT)
entry2 = Entry(f1)
label2 = Label(f1, text="вес в кг", justify=LEFT)
entry3 = Entry(f1)
label3 = Label(f1, text="возраст полных лет", justify=LEFT)
label1.pack(fill=X)
entry1.pack(fill=X)
label2.pack(fill=X)
entry2.pack(fill=X)
label3.pack(fill=X)
entry3.pack(fill=X)
f2 = Frame()
f2.pack(side=LEFT, padx=10)
badd = Button(f2, text="подсчитать", background="#555", foreground="#ccc",
padx="20", pady="8", font="16", command=bmi_index)
badd.pack(fill=X)
label4 = Label(f2, text="", justify=LEFT)
label4.pack(fill=X)
root.mainloop()
import sqlite3
blob = bytearray(b'{"param1":"1","param2":"2"}')
with sqlite3.connect('np.db') as connection:
cursor = connection.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS t_info_t (blob_Value BLOB )")
cursor.execute("INSERT OR IGNORE INTO t_info_t (blob_Value) values (?)", (blob,))
cursor.execute("SELECT * FROM t_info_t")
data = cursor.fetchall()
print(data)
print(type(data[0][0]))
out = data[0][0].decode()
print(out)
print(type(out))
import requests
import os
import urllib3
import csv
import sqlite3
source = r'https://rossvyaz.gov.ru/data/'
abc3 = 'ABC-3xx.csv'
abc4 = 'ABC-4xx.csv'
abc8 = 'ABC-8xx.csv'
def9 = 'DEF-9xx.csv'
path = os.getcwd() + '\\NP\\'
db = path + "np.db"
try:
os.mkdir(path)
except OSError:
pass
file_list = [abc3, abc4, abc8, def9]
table = "CREATE TABLE numbering_plan(prefix INT, begin INT, end INT, capacity INT, operator TEXT, region TEXT);"
with sqlite3.connect(db) as connection:
cursor = connection.cursor()
cursor.execute(table)
for file in file_list:
urllib3.disable_warnings()
r = requests.get(source + file, verify=False)
open(path + file, 'wb').write(r.content)
with open(path + file, 'r', encoding='utf-8') as f:
dr = csv.DictReader(f, delimiter=';', quoting=csv.QUOTE_NONE)
to_db = [(i['АВС/ DEF'], i['От'], i['До'], i['Емкость'], i['Оператор'], i['Регион']) for i in dr]
with sqlite3.connect(db) as connection:
cursor = connection.cursor()
cursor.executemany("INSERT INTO numbering_plan (prefix, begin, end, capacity, operator, region) "
"VALUES (?, ?, ?, ?, ?, ?);", to_db)
import sqlite3
import os
path = os.getcwd() + '\\NP\\'
db = path + "np.db"
num = 1
while num:
num = input('Введите номер в формате ABD/DEАххх ')
prefix = num[:3]
number = num[3:]
search_query = 'SELECT * FROM numbering_plan WHERE prefix=? AND ? BETWEEN begin AND end;'
with sqlite3.connect(db) as connection:
cursor = connection.cursor()
cursor.execute(search_query, (prefix, number))
result = cursor.fetchall()
print(result)
from threading import Thread
import schedule
def sheduler():
schedule.every().day.at("12:00").do(daily_notify)
while True:
schedule.run_pending()
sleep(1)
def daily_notify():
pass
#bot send text
Thread(target=sheduler, args=()).start()
bot.get_chat_members_count(group_chat_id)
bot.get_chat_administrators(group_chat_id)
bot.get_chat_member(group_chat_id, chat_id )
# -*- coding: utf-8 -*-
import telebot
from time import time
import os
bot = telebot.TeleBot(token_test)
@bot.message_handler(content_types=['voice'])
def voice_processing(message):
file_info = bot.get_file(message.voice.file_id)
downloaded_file = bot.download_file(file_info.file_path)
with open(f'{message.chat.id}_{int(time())}.ogg', 'wb') as new_file:
new_file.write(downloaded_file)
@bot.message_handler(commands=['start'])
def voice_send(message):
l_send = [filename for filename in os.listdir() if filename.startswith(f'{message.chat.id}')]
for f in l_send:
voice = open(f'{f}', 'rb')
bot.send_voice(chat_id=message.chat.id, voice=voice)
if __name__ == "__main__":
try:
bot.polling(none_stop=True)
except Exception as e:
print(e)
# -*- coding: utf-8 -*-
import telebot
from time import sleep
from threading import Thread
bot = telebot.TeleBot(token_test)
@bot.message_handler(commands=['start'])
def thread_main(message):
Thread(target=timer, args=(message,)).start()
Thread(target=counter, args=(message,)).start()
def timer(message):
msg = bot.send_message(chat_id=message.chat.id, text='Timer start')
sleep(1)
msg_id = msg.message_id
time_s = 15
for t in range(time_s, 0, -1):
bot.edit_message_text(chat_id=message.chat.id, message_id=msg_id, text=f'Timer - {t}')
sleep(1)
bot.edit_message_text(chat_id=message.chat.id, message_id=msg_id, text='Timer End')
def counter(message):
msg = bot.send_message(chat_id=message.chat.id, text='Count start')
sleep(1)
msg_id = msg.message_id
count = 15
for c in range(count):
bot.edit_message_text(chat_id=message.chat.id, message_id=msg_id, text=f'Count - {c}')
sleep(1)
bot.edit_message_text(chat_id=message.chat.id, message_id=msg_id, text='Count End')
if __name__ == "__main__":
try:
bot.polling(none_stop=True)
except Exception as e:
print(e)
# -*- coding: utf-8 -*-
import telebot
from time import sleep
bot = telebot.TeleBot(token)
@bot.message_handler(commands=['start'])
def send_notification(message):
msg = bot.send_message(chat_id=message.chat.id, text='START')
sleep(1)
msg_id = msg.message_id
time_s = 15
for t in range(time_s, 0, -1):
bot.edit_message_text(chat_id=message.chat.id, message_id=msg_id, text=f'Wait...{t} секунд')
sleep(1)
bot.edit_message_text(chat_id=message.chat.id, message_id=msg_id, text='END')
if __name__ == "__main__":
try:
bot.polling(none_stop=True)
except Exception as e:
print(e)