Проверь код import requests from colorama import init, Fore, Style import time…
- User
User: Проверь код
import requests from colorama import init, Fore, Style import time import datetime import os from requests.exceptions import ConnectionError from json import JSONDecodeError from configparser import ConfigParser config = ConfigParser() config.read('config.ini')
init(autoreset=True) start_time = time.time() headers = {"user-agent": "Mozilla/5.0 (Linux; Android 13; Redmi Note 10S) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36"} sellers_array = [] new_elements = [] timestamps = [] selection_array = [] yes = {'yes','y', ''} no = {'no','n'} r_r = 1 cached_data = None a, a_b, a_p, s, s_b, s_p, r = 0, 0, 0, 0, 0, 0, 0 a_int, a_b_int, a_p_int, r_int, s_int, s_b_int, s_p_int = 0, 0, 0, 0, 0, 0, 0 useconf = input("Использовать конфиг? (Y/n): ") if useconf in yes: trafficType = input("Введите цифру типа трафика (1-ГБ, 2-минуты, 3-SMS): ") traffic_types = {"1": "data", "2": "voice", "3": "sms"} trafficType = traffic_types.get(trafficType, trafficType) volume = int(input('Введите кол-во ГБ/минут/SMS: ')) mincost = input("Минималка? (Y/n): ").lower() interval = config.getint("Settings", "interval") delay = config.getint("Settings", "delay") delete = config.get("Settings", "delete") interval *= 60 else: writeconf = input("Запомнить настройки? (Y/n): ") trafficType = input("Введите цифру типа трафика (1-ГБ, 2-минуты, 3-SMS): ") traffic_types = {"1": "data", "2": "voice", "3": "sms"} trafficType = traffic_types.get(trafficType, trafficType) volume = int(input('Введите кол-во ГБ/минут: ')) interval = int(input('За какой интервал собирать статистику (в минутах): ')) * 60
delay = int(input('Введите частоту обновления (в секундах): ')) delete = input('Обнулить лог-файл? (Y/n): ').lower() mincost = input("Минималка? (Y/n): ").lower() if writeconf in yes: config.set("Settings", "interval", str(round(interval/60))) config.set("Settings", "delay", str(delay)) config.set("Settings", "delete", delete) with open('config.ini', 'w') as config_file: config.write(config_file) if 10 < interval / 60 % 100 < 20: ending = "" elif interval / 60 % 10 == 1: ending = "у" elif interval /60 % 10 in [2, 3, 4]: ending = "ы" else: ending = "" if mincost in yes:
cost_url = f"https://tele2.ru/api/exchange/lots/stats/volumes?trafficType={trafficType}" try: response = requests.get(cost_url, headers=headers) data = response.json() except (JSONDecodeError, ConnectionError, requests.exceptions.ReadTimeout): print(Fore.YELLOW + 'Нет связи с сервером') input("Нажмите Enter для выхода..") try:
def get_cost(volume): for item in data['data']: if item['volume'] == volume: cost = item["minCost"] return cost return None cost = int(get_cost(volume)) except: InputErrHandler()
elif mincost in no: cost = int(input("Введите цену лота: "))while True:
trafficTypeFile = "gb" if trafficType == "data" else "min" if trafficType == "voice" else "sms" if delete in yes: open(f"sales_{volume}{trafficTypeFile}_{cost}p.txt", "w").close() break elif delete in no: break - Assistant
Проверка и улучшение Python кода
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.