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)
# -*- 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)
with requests.Session() as session:
cookies = dict(uid=uid, usess=usess)
auth = dict(username=login, password=password) # Данные в виде словаря, которые отправлятся в POST
r = session.get(url, timeout=5) # Получаем страницу с формой логина
r.encoding = 'utf-8'
session.post(url, auth) # Отправляем данные в POST, в session записываются наши куки
r = session.get(link, cookies=cookies, timeout=5)
open('some_file_name', 'wb').write(r.content)
CREATE TABLE IF NOT EXISTS games
(game TEXT NOT NULL, play_date TEXT NOT NULL, play_time TEXT NOT NULL,
team_a TEXT NOT NULL, team_b TEXT NOT NULL, cup TEXT,
PRIMARY KEY (game , play_date , play_time ));
user_id = 123
get_id_from_db = 6
user_data = {user_id: {'city':'', 'fio':'', 'phone':'', 'inn':'', 'address':'', 'napravlenie':'', 'id': get_id_from_db}}
print(user_data)
user_data[user_id]['city'] = 'Павлодар'
print(user_data)
user_data[user_id]['fio'] = 'Иванов а м'
print(user_data)
user_data[user_id]['phone'] = '77777777'
print(user_data)
user_data[user_id]['inn'] = '4679085467'
print(user_data)
user_data[user_id]['address'] = 'Петрова 65 кв 98'
print(user_data)
user_data[user_id]['napravlenie'] = 'сайт-визитка'
print(user_data)
from time import sleep
def check_email():
while True:
mails = loop()
if mails:
for mail in mails:
bot.send_message(admin_id, mail)
sleep(60)
from threading import Thread
Thread(target=check_email, args=()).start()
colour
The colour code of the embed. Aliased to color as well. This can be set during initialisation.
Type
Union[Colour, int]
embed=discord.Embed(description="Показывает информацию об игроке", color=int(tsvet, 16))
with sqlite3.connect('my.db') as connection:
cursor = connection.cursor()
cursor.execute(cmd)
def is_user_warned(user_id: int) -> bool:
if not is_user_warned(event.obj.reply_message['from_id']):
def post_sql_query(sql_query):
with sqlite3.connect('my.db') as connection:
cursor = connection.cursor()
try:
cursor.execute(sql_query)
except Error:
pass
result = cursor.fetchall()
return result
def is_user_warned(user_id: int):
cmd = "select count(user_id) from warnlist where user_id = %d" % (user_id)
result = post_sql_query(cmd)
return result
if not is_user_warned(event.obj.reply_message['from_id']):
print('добавить')
else:
print('+ 1/3 варн')