Форум сайта python.su
import os from tkinter import * import subprocess from tkinter import ttk path = "C:/Program Files/Organaizer" m1 = "C:/Program Files/Organaizer/Monday/Registration" m2 = "C:/Program Files/Organaizer/Monday/Literature" m3 = "C:/Program Files/Organaizer/Monday/ITGS" m4 = "C:/Program Files/Organaizer/Monday/Maths" t1 = "C:/Program Files/Organaizer/Tuesday/Registration" t2 = "C:/Program Files/Organaizer/Tuesday/English" t3 = "C:/Program Files/Organaizer/Tuesday/Literature" t4 = "C:/Program Files/Organaizer/Tuesday/CS" t5 = "C:/Program Files/Organaizer/Tuesday/PE" w1 = "C:/Program Files/Organaizer/Wednesday/Registration" w2 = "C:/Program Files/Organaizer/Wednesday/CS" w3 = "C:/Program Files/Organaizer/Wednesday/Psychology" w4 = "C:/Program Files/Organaizer/Wednesday/English" h1 = "C:/Program Files/Organaizer/Thursday/Registration" h2 = "C:/Program Files/Organaizer/Thursday/English" h3 = "C:/Program Files/Organaizer/Thursday/Maths" h4 = "C:/Program Files/Organaizer/Thursday/Literature" h5 = "C:/Program Files/Organaizer/Thursday/ITGS" f1 = "C:/Program Files/Organaizer/Friday/Registration" f2 = "C:/Program Files/Organaizer/Friday/CS" f3 = "C:/Program Files/Organaizer/Friday/Psychology" f4 = "C:/Program Files/Organaizer/Friday/Grorootg Minds" try: os.makedirs(path) except OSError: print ("The %s directory could not be created" % path) else: print ("The %s directory was successfully created" % path) try: os.makedirs(m1) except OSError: print ("The %s directory could not be created" % m1) else: print ("The %s directory was successfully created" % m1) try: os.makedirs(m2) except OSError: print ("The %s directory could not be created" % m2) else: print ("The %s directory was successfully created" % m2) try: os.makedirs(m3) except OSError: print ("The %s directory could not be created" % m3) else: print ("The %s directory was successfully created" % m3) try: os.makedirs(m4) except OSError: print ("The %s directory could not be created" % m4) else: print ("The %s directory was successfully created" % m4) try: os.makedirs(t1) except OSError: print ("The %s directory could not be created" % t1) else: print ("The %s directory was successfully created" % t1) try: os.makedirs(t2) except OSError: print ("The %s directory could not be created" % t2) else: print ("The %s directory was successfully created" % t2) try: os.makedirs(t3) except OSError: print ("The %s directory could not be created" % t3) else: print ("The %s directory was successfully created" % t3) try: os.makedirs(t4) except OSError: print ("The %s directory could not be created" % t4) else: print ("The %s directory was successfully created" % t4) try: os.makedirs(t5) except OSError: print ("The %s directory could not be created" % t5) else: print ("The %s directory was successfully created" % t5) try: os.makedirs(w1) except OSError: print ("The %s directory could not be created" % w1) else: print ("The %s directory was successfully created" % w1) try: os.makedirs(w2) except OSError: print ("The %s directory could not be created" % w2) else: print ("The %s directory was successfully created" % w2) try: os.makedirs(w3) except OSError: print ("The %s directory could not be created" % w3) else: print ("The %s directory was successfully created" % w3) try: os.makedirs(w4) except OSError: print ("The %s directory could not be created" % w4) else: print ("The %s directory was successfully created" % w4) try: os.makedirs(h1) except OSError: print ("The %s directory could not be created" % h1) else: print ("The %s directory was successfully created" % h1) try: os.makedirs(h2) except OSError: print ("The %s directory could not be created" % h2) else: print ("The %s directory was successfully created" % h2) try: os.makedirs(h3) except OSError: print ("The %s directory could not be created" % h3) else: print ("The %s directory was successfully created" % h3) try: os.makedirs(h4) except OSError: print ("The %s directory could not be created" % h4) else: print ("The %s directory was successfully created" % h4) try: os.makedirs(h5) except OSError: print ("The %s directory could not be created" % h5) else: print ("The %s directory was successfully created" % h5) try: os.makedirs(f1) except OSError: print ("The %s directory could not be created" % f1) else: print ("The %s directory was successfully created" % f1) try: os.makedirs(f2) except OSError: print ("The %s directory could not be created" % f2) else: print ("The %s directory was successfully created" % f2) try: os.makedirs(f3) except OSError: print ("The %s directory could not be created" % f3) else: print ("The %s directory was successfully created" % f3) try: os.makedirs(f4) except OSError: print ("The %s directory could not be created" % f4) else: print ("The %s directory was successfully created" % f4) root = Tk() root.title("Login") root.resizable(0, 0) root.configure(bg='black') root.geometry("910x740") attempts=0 correctpassword="1234" entrypass = Entry(root, width=25, textvariable=password, show="*") entrypass.pack() def start(): while attempts<3: if entrypass==correctpassword: print('Correct.') altroot = Toplevel(root) altroot.title("Organaizer") altroot.resizable(0, 0) altroot.configure(bg='black') altroot.geometry('910x740') def monviewcom(): subprocess.Popen(r'explorer /select,"C:\Program Files\Organaizer\Monday\Registration"') def tuviewcom(): subprocess.Popen(r'explorer /select,"C:\Program Files\Organaizer\Tuesday\Registration"') def wedviewcom(): subprocess.Popen(r'explorer /select,"C:\Program Files\Organaizer\Wednesday\Registration"') def huviewcom(): subprocess.Popen(r'explorer /select,"C:\Program Files\Organaizer\Thursday\Registration"') def frviewcom(): subprocess.Popen(r'explorer /select,"C:\Program Files\Organaizer\Friday\Registration"') def mondays(): monles = Toplevel(root) monles.title("MONDAY") monles.resizable(0, 0) monles.configure(bg='black') monles.geometry('910x740') monlesson = Frame(monles, width=750, height=600, bg='black') monlesson.grid(row=0, column=0, padx=1, pady=1) monregistration = Label(monlesson, text="Registration || 8:20 - 8:40", fg='white', bg='black', font=200, width=85, height=6) monregistration.grid(row=0, column=0, sticky=S, padx=1, pady=1) monliterature = Label(monlesson, text="Russian Literature || 10:20 - 11:40", fg='white', bg='black', font=200, width=85, height=6) monliterature.grid(row=1, column=0, sticky=S, padx=1, pady=1) monitgs = Label(monlesson, text="ITGS || 11:40 - 12:20 / 13:20 - 14:00", fg='white', bg='black', font=200, width=85, height=6) monitgs.grid(row=2, column=0, sticky=S, padx=1, pady=1) monmaths = Label(monlesson, text="Maths || 14:00 - 15:20", fg='white', bg='black', font=200, width=85, height=6) monmaths.grid(row=3, column=0, sticky=S, padx=1, pady=1) monview = Button(monlesson, text="View", fg='black', bg='white', font=300, width=85, height=6, command=monviewcom) monview.grid(row=4, column=0, sticky=S, padx=1, pady=1) def tuesdays(): tules = Toplevel(root) tules.title("TUESDAY") tules.resizable(0, 0) tules.configure(bg='black') tules.geometry('910x740') tulesson = Frame(tules, width=750, height=600, bg='black') tulesson.grid(row=0, column=0, padx=1, pady=1) turegistration = Label(tulesson, text="Registration || 8:20 - 8:40", fg='white', bg='black', font=200, width=85, height=5) turegistration.grid(row=0, column=0, sticky=S, padx=1, pady=1) tuenglish = Label(tulesson, text="English || 8:40 - 10:00", fg='white', bg='black', font=200, width=85, height=5) tuenglish.grid(row=1, column=0, sticky=S, padx=1, pady=1) tuliterature = Label(tulesson, text="Literature || 10:20 - 11:40", fg='white', bg='black', font=200, width=85, height=5) tuliterature.grid(row=2, column=0, sticky=S, padx=1, pady=1) tucs = Label(tulesson, text="CS || 11:40 - 12:20 / 13:20 - 14:00", fg='white', bg='black', font=200, width=85, height=5) tucs.grid(row=3, column=0, sticky=S, padx=1, pady=1) tupe = Label(tulesson, text="PE || 14:00 - 15:20", fg='white', bg='black', font=200, width=85, height=5) tupe.grid(row=4, column=0, sticky=S, padx=1, pady=1) tuview = Button(tulesson, text="View", fg='black', bg='white', font=300, width=85, height=5, command=tuviewcom) tuview.grid(row=5, column=0, sticky=S, padx=1, pady=1) def wednesdays(): wedles = Toplevel(root) wedles.title("WEDNESDAY") wedles.resizable(0, 0) wedles.configure(bg='black') wedles.geometry('910x740') wedlesson = Frame(wedles, width=750, height=600, bg='black') wedlesson.grid(row=0, column=0, padx=1, pady=1) wedregistration = Label(wedlesson, text="Registration || 8:20 - 8:40", fg='white', bg='black', font=200, width=85, height=6) wedregistration.grid(row=0, column=0, sticky=S, padx=1, pady=1) wedliterature = Label(wedlesson, text="CS || 8:40 - 10:00", fg='white', bg='black', font=200, width=85, height=6) wedliterature.grid(row=1, column=0, sticky=S, padx=1, pady=1) weditgs = Label(wedlesson, text="Psychology || 11:40 - 12:20 / 13:20 - 14:00", fg='white', bg='black', font=200, width=85, height=6) weditgs.grid(row=2, column=0, sticky=S, padx=1, pady=1) wedmaths = Label(wedlesson, text="English || 14:00 - 15:20", fg='white', bg='black', font=200, width=85, height=6) wedmaths.grid(row=3, column=0, sticky=S, padx=1, pady=1) wedview = Button(wedlesson, text="View", fg='black', bg='white', font=300, width=85, height=6, command=wedviewcom) wedview.grid(row=4, column=0, sticky=S, padx=1, pady=1) def thursdays(): hules = Toplevel(root) hules.title("THURSDAY") hules.resizable(0, 0) hules.configure(bg='black') hules.geometry('910x740') hulesson = Frame(hules, width=750, height=600, bg='black') hulesson.grid(row=0, column=0, padx=1, pady=1) huregistration = Label(hulesson, text="Registration || 8:20 - 8:40", fg='white', bg='black', font=200, width=85, height=5) huregistration.grid(row=0, column=0, sticky=S, padx=1, pady=1) huenglish = Label(hulesson, text="English || 8:40 - 10:00", fg='white', bg='black', font=200, width=85, height=5) huenglish.grid(row=1, column=0, sticky=S, padx=1, pady=1) humaths = Label(hulesson, text="Maths || 10:20 - 11:40", fg='white', bg='black', font=200, width=85, height=5) humaths.grid(row=2, column=0, sticky=S, padx=1, pady=1) huliterature = Label(hulesson, text="Literature || 11:40 - 12:20 / 13:20 - 14:00", fg='white', bg='black', font=200, width=85, height=5) huliterature.grid(row=3, column=0, sticky=S, padx=1, pady=1) huitgs = Label(hulesson, text="ITGS || 14:00 - 15:20", fg='white', bg='black', font=200, width=85, height=5) huitgs.grid(row=4, column=0, sticky=S, padx=1, pady=1) huview = Button(hulesson, text="View", fg='black', bg='white', font=300, width=85, height=5, command=huviewcom) huview.grid(row=5, column=0, sticky=S, padx=1, pady=1) def fridays(): frles = Toplevel(root) frles.title("FRIDAY") frles.resizable(0, 0) frles.configure(bg='black') frles.geometry('910x740') frlesson = Frame(frles, width=750, height=600, bg='black') frlesson.grid(row=0, column=0, padx=1, pady=1) frregistration = Label(frlesson, text="Registration || 8:20 - 8:40", fg='white', bg='black', font=200, width=85, height=6) frregistration.grid(row=0, column=0, sticky=S, padx=1, pady=1) frcs = Label(frlesson, text="CS|| 8:40 - 10:00", fg='white', bg='black', font=200, width=85, height=6) frcs.grid(row=1, column=0, sticky=S, padx=1, pady=1) frpsychology = Label(frlesson, text="Psychology || 10:20 - 11:40", fg='white', bg='black', font=200, width=85, height=6) frpsychology.grid(row=2, column=0, sticky=S, padx=1, pady=1) frgm = Label(frlesson, text="GM || 14:00 - 15:20", fg='white', bg='black', font=200, width=85, height=6) frgm.grid(row=3, column=0, sticky=S, padx=1, pady=1) frview = Button(frlesson, text="View", fg='black', bg='white', font=300, width=85, height=6, command=frviewcom) frview.grid(row=4, column=0, sticky=S, padx=1, pady=1) lu = Frame(altroot, width=250, height=200, bg='white') lu.grid(row=0, column=0, padx=1, pady=1, sticky=N) tp = Frame(altroot, width=250, height=200, bg='white') tp.grid(row=0, column=1, padx=1, pady=1, sticky=N) ru = Frame(altroot, width=250, height=200, bg='white') ru.grid(row=0, column=2, padx=1, pady=1, sticky=N) lt = Frame(altroot, width=250, height=200, bg='white') lt.grid(row=1, column=0, padx=1, pady=1, sticky=N) md = Frame(altroot, width=250, height=200, bg='white') md.grid(row=1, column=1, padx=1, pady=1, sticky=N) rt = Frame(altroot, width=250, height=200, bg='white') rt.grid(row=1, column=2, padx=1, pady=1, sticky=N) bt = Frame(altroot, width=250, height=200, bg='white') bt.grid(row=2, column=1, padx=1, pady=1, sticky=N) mday = Button(lu, text="MONDAY", fg='black', bg='white', font=150, width=27, height=10, command=mondays) mday.pack() tday = Button(tp, text="TUESDAY", fg='black', bg='white', font=150, width=27, height=10, command=tuesdays) tday.pack() wday = Button(ru, text="WEDNESDAY", fg='black', bg='white', font=150, width=27, height=10, command=wednesdays) wday.pack() thday = Button(lt, text="THURSDAY", fg='black', bg='white', font=150, width=27, height=10, command=thursdays) thday.pack() fday = Button(md, text="FRIDAY", fg='black', bg='white', font=150, width=27, height=10, command=fridays) fday.pack() saday = Label(rt, text="SATURDAY", fg='black', bg='white', font=150, width=27, height=10) saday.pack() sday = Label(bt, text="SUNDAY", fg='black', bg='white', font=150, width=27, height=10) sday.pack() altroot.mainloop() else: attempts+=1 print('incorrect!') if attempts==3: print('too many attempts') ttt = Button(root, text="Enter", command=start).pack() root.mainloop()
urlpatterns = [ path('login', views.login, name = 'login'), ]
def login(request): #return HttpResponse('<h4>LogIn page</h4>') url = 'https://login.abc.com/v2/oauth/authorize/?' parametres ={ 'a' :'response_type=code', 'b' :'redirect_uri=http%3A%2F%2Flocalhost%2Fcallback%3A8000', #http://localhost/callback:8000 'c' :'client_id=1234', 'd' :'scope=publicData', 'e' :'state=somethingunique',} return redirect(url+'&'.join(list(parametres.values())) )
from PIL import Image, ImageGrab #Cкриншоты import cv2 import pytesseract #определение цифр img1 = ImageGrab.grab( (1697,410,1787,447) )#Скрингот заданной области img1.save("picture.jpg")#Сохранение скриншота image = cv2.imread("picture.jpg") #Открытие скришота T, image2 = cv2.threshold(image, 215, 255, cv2.THRESH_BINARY)#Делаю черно белым cv2.imwrite('graygirl.jpg', image2)#Сохарнение черно белого pytesseract.pytesseract.tesseract_cmd = r'C:\Users\Desktop\AppData\Local\Programs\Tesseract-OCR\tesseract.exe' question_text = pytesseract.image_to_string(Image.open("picture.jpg"))
Traceback (most recent call last): File "C:\Users\Desktop\Desktop\Машенист\main.py", line 11, in <module> question_text = pytesseract.image_to_string(Image.open("picture.jpg")) File "C:\Users\Desktop\Desktop\Машенист\venv\lib\site-packages\pytesseract\pytesseract.py", line 409, in image_to_string return { File "C:\Users\Desktop\Desktop\Машенист\venv\lib\site-packages\pytesseract\pytesseract.py", line 412, in <lambda> Output.STRING: lambda: run_and_get_output(*args), File "C:\Users\Desktop\Desktop\Машенист\venv\lib\site-packages\pytesseract\pytesseract.py", line 287, in run_and_get_output run_tesseract(**kwargs) File "C:\Users\Desktop\Desktop\Машенист\venv\lib\site-packages\pytesseract\pytesseract.py", line 263, in run_tesseract raise TesseractError(proc.returncode, get_errors(error_string)) pytesseract.pytesseract.TesseractError: (1, 'Error opening data file D:\\Tesseract-OCR\\eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')
from telegram.ext import Updater, MessageHandler, Filters from pytube import YouTube import logging logging.basicConfig(level=logging.DEBUG, filename='logs.txt') from yandex import sendToScreen import config last_url = "" authorised_users = [] def getVideoUrl(url): global last_url if url == last_url: # Second attempt - trying another player yt = YouTube(url).streams.first() last_url = url return yt.url last_url = url if "https://www.youtube" in url: url = url.split("&")[0] # Removing arguments if "https://youtu.be" in url: url = "https://www.youtube.com/watch?v=" + url.split("/")[-1] # Page parsing and getting video_url here return url def extractUrl(message, context): return message.text # TODO: getting url by entities info def message_recieved(bot, update, context): user_id = update.message.chat_id print(update.message) if update.message.text == config.bot_password: authorised_users.append(user_id) bot.send_message(chat_id=update.message.chat_id, text="Успешная авторизация!") print(f"Authorised: {user_id}") return if not user_id in authorised_users: bot.send_message(chat_id=update.message.chat_id, text="Доступ закрыт!") print("Unauthorised request blocked!") return url = extractUrl(update.message) video_url = getVideoUrl(url) result = sendToScreen(video_url) print(result) bot.send_message(chat_id=update.message.chat_id, text=result + video_url) updater = Updater(token=config.telegram_bot_token, request_kwargs=config.proxy) print("Начинаю сбор Видосиков =)") updater.start_polling()
login = "123@yandex.ru" password = "123" telegram_bot_token = "123" proxy = None
import requests import json import config def sendToScreen(video_url): # Auth and getting Session_id auth_data = { 'login': config.login, 'passwd': config.password } s = requests.Session() s.get("https://passport.yandex.ru/") s.post("https://passport.yandex.ru/passport?mode=auth&retpath=https://yandex.ru", data=auth_data) Session_id = s.cookies["Session_id"] # Getting x-csrf-token token = s.get('https://frontend.vh.yandex.ru/csrf_token').text # Detting devices info TODO: device selection here devices_online_stats = s.get("https://quasar.yandex.ru/devices_online_stats").text devices = json.loads(devices_online_stats)["items"] # Preparing request headers = { "x-csrf-token": token, } data = { "msg": { "provider_item_id": video_url }, "device": devices[0]["id"] } if "https://www.youtube" in video_url: data["msg"]["player_id"] = "youtube" # Sending command with video to device res = s.post("https://yandex.ru/video/station", data=json.dumps(data), headers=headers) return res.text
debt
children debt
0 0 0
1 1064
1 0 0
1 444
2 0 0
1 194
3 0 0
1 27
4 0 0
1 4
5 0 0
20 0 0
1 8
size = [3, 5, 4, 6] res = [[randint(0, 9) for i in range(s)] for s in size] for a in res: for z in a: print(z, end=' ') print()
import sys import os.path as osPath # list of jar files listPBJdep = ["terajdbc4.jar", "tdgssconfig.jar", "tptwizard.jar"] # Add jars pbjDepPath = r"H:\temp\TD_jars" # Debug print("Adding PBJ dependencies from %s" % pbjDepPath) for jar in listPBJdep: pbjPathJar = osPath.join(pbjDepPath, jar) if pbjPathJar not in sys.path: sys.path.append(pbjPathJar) print("PBJ dependency appended to sys path: %s" % jar) print sys.path import java.sql.DriverManager as DriverManager import java.sql.SQLException as SQLException import java.sql.Types as Types import java.lang.Class as Class srcdriver = "com.teradata.jdbc.TeraDriver" srcurl = "jdbc:teradata://TERADATA/CHARSET=UTF8" srcuser = "orel_da" srcpass = 'password' fetchsize = "10000" Class.forName(srcdriver).newInstance() print('try to connect') con = DriverManager.getConnection(srcurl+',TYPE=FASTEXPORT',srcuser,srcpass ) print('connection sucecssful')
from flask import Flask from flask_restful import Api from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def create_app(Configuration): app = Flask(__name__) app.config.from_object(Configuration) db.init_app(app) api = Api(app) import src.views as views api.add_resource(views.CreateDriver, '/drivers/driver/') # создание нового водителя api.add_resource(views.CreateVehicle, '/vehicles/vehicle/') # создание нового автомобиля api.add_resource(views.Driver, '/drivers/driver/<driver_id>/') # получение инфо по конкретному водителю api.add_resource(views.Vehicle, '/vehicles/vehicle/<vehicle_id>') # получение инфо по конкретному автомобилю api.add_resource(views.Drivers, '/drivers/driver/') # вывод списка водителей api.add_resource(views.Vehicles, '/vehicles/vehicle/') # вывод списка автомобилей api.add_resource(views.DriverCreated_at__gte, '/drivers/driver/*****???????*****') # вывод списка водителей, которые созданы после 10-11-2021 (запрос должен выглядеть вот так GET /drivers/driver/?created_at__gte=10-11-2021) КАК??? api.add_resource(views.FindDriver_gte, '/drivers/drivers/search_gte') # вот что я смог, выводит водителей после даты указанной в views.FindDriver_gte > db_methods.find_drivers_gte return app
class FindDriver_gte(Resource): def get(self): parser = reqparse.RequestParser() parser.add_argument('first_name', type=str) parser.add_argument('last_name', type=str) parser.add_argument('created_at[gte]', type=transfer_date) args = parser.parse_args(strict=True) drivers = db_methods.find_drivers_gte(args) drivers_list = [] for driver in drivers: drivers_list.append({'first_name': driver.first_name, 'last_name': driver.last_name, 'created_at': str(driver.created_at), 'updated_at': str(driver.updated_at)}) return {"message": {"drivers": drivers_list}}
def find_drivers_gte(filters: date): dt = datetime.strptime("10/11/21", "%d/%m/%y") q = db.session.query(Driver).filter() if filters: q = q.filter(Driver.created_at >= dt) return q.all()
from flask import Flask from flask_restful import Api from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() def create_app(Configuration): app = Flask(__name__) app.config.from_object(Configuration) db.init_app(app) api = Api(app) import src.views as views api.add_resource(views.CreateDriver, '/drivers/driver/') # создание нового водителя api.add_resource(views.CreateVehicle, '/vehicles/vehicle/') # создание нового автомобиля api.add_resource(views.Driver, '/drivers/driver/<driver_id>/') # получение инфо по конкретному водителю api.add_resource(views.Vehicle, '/vehicles/vehicle/<vehicle_id>') # получение инфо по конкретному автомобилю api.add_resource(views.Drivers, '/drivers/driver/') # вывод списка водителей api.add_resource(views.Vehicles, '/vehicles/vehicle/') # вывод списка автомобилей api.add_resource(views.DriverCreated_at__gte, '/drivers/driver/*****???????*****') # вывод списка водителей, которые созданы после 10-11-2021 (запрос должен выглядеть вот так GET /drivers/driver/?created_at__gte=10-11-2021) КАК??? api.add_resource(views.FindDriver_gte, '/drivers/drivers/search_gte') # вот что я смог, выводит водителей после даты указанной в views.FindDriver_gte > db_methods.find_drivers_gte return app
class FindDriver_gte(Resource): def get(self): parser = reqparse.RequestParser() parser.add_argument('first_name', type=str) parser.add_argument('last_name', type=str) parser.add_argument('created_at[gte]', type=transfer_date) args = parser.parse_args(strict=True) drivers = db_methods.find_drivers_gte(args) drivers_list = [] for driver in drivers: drivers_list.append({'first_name': driver.first_name, 'last_name': driver.last_name, 'created_at': str(driver.created_at), 'updated_at': str(driver.updated_at)}) return {"message": {"drivers": drivers_list}}
def find_drivers_gte(filters: date): dt = datetime.strptime("10/11/21", "%d/%m/%y") q = db.session.query(Driver).filter() if filters: q = q.filter(Driver.created_at >= dt) return q.all()
def http(url, secure=443, encoding='utf-8'): components = urllib.parse.urlsplit(url) print(components) path = '%s' % components.path if components.path else '/' HTTPS = (components.scheme == 'https') addr = components.hostname port = secure if HTTPS else 80 CRLF = '\r\n\r\n' print(HTTPS) print(addr) print(port) Page = namedtuple('Page', ('code', 'headers', 'body')) print(Page) def handshake(sock): # this will trigger the handshake # if sock is already connected new_sock = ssl.wrap_socket(sock, ciphers="GOST2012-GOST8912-GOST8912:HIGH", ssl_version=ssl.PROTOCOL_TLSv1, cert_reqs=ssl.CERT_REQUIRED, # I will verify your certificate ca_certs=certifi.where(), # using a list of trusted CA's certificates server_side=False, do_handshake_on_connect = True, certfile= None, keyfile= None ) return new_sock def make_header(): headers = [ 'Content-Type:application/json', 'Accept:application/json', 'Authorization: token %s' % token, 'POST %s HTTP/1.1' % (path), 'Host: %s' % addr, 'Charset: %s' % encoding ] print(headers) header = '\n'.join(headers) header += CRLF return bytes(header, encoding=encoding) def parse_response(resp): ''' resp http.client.HTTPResponse, not closed ''' resp.begin() code = resp.getcode() # assume status 200 headers = dict(resp.getheaders()) def get_charset(): ctt_type = headers.get('Content-Type') return cgi.parse_header(ctt_type)[1].get('charset', encoding) body = resp.read() body = str(body, encoding=get_charset()) return Page(code, headers, body) def request(header): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) print(addr) HOST = socket.getaddrinfo(addr, 443)[0][4][0] print(HOST) sock.connect((addr, port)) try: if HTTPS: sock = handshake(sock) sock.sendall(header) # receive it resp = HTTPResponse(sock) return parse_response(resp) finally: sock.shutdown(1) sock.close() return request(make_header()) url = "https://api.mdlp.crpt.ru/api/v1/reestr/sgtin/sgtins-by-list" rrr=http(url) print(rrr)
for row in list(queryset): # тут 100к строк и нужен dbf файл для древней программы table.append( (row['f1'], row['f2'], ) )