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)
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 ));