У меня большая проблема с моим кодом на Python. Немного добавлю, пишу с переводчика, так как плохо знаю английский, а также пишу код на PyDroid 3 на телефоне, так как компьютера у меня нет.
Вот мой код (свел к корню проблемы, оставив импорт):
import os
import random
import re
from datetime import datetime as dt
from bs4 import BeautifulSoup as bs
from translate import Translator as tr
import time as t
import requests as rq
from countryinfo import CountryInfo as ci
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.core.text import LabelBase
from kivy.uix.label import Label
LabelBase.register(name = "lucida", fn_regular = "/storage/emulated/0/Fonts/Lucida Console/lucidaconsole.ttf")
LabelBase.register(name = "fixedsys", fn_regular = "/storage/emulated/0/Fonts/Fixedsys/Fixedsys.ttf")
def check_internet_connection():
try:
print("\nПроверка подключения...")
check_internet = rq.get("https://www.google.com", timeout = 6)
if check_internet.status_code == 200:
os.system("clear")
return True
except rq.ConnectionError:
os.system("clear")
return False
def loading(root):
global ip
global data
global loc
global lat
global lon
global country
global country_info
global translate
global region
global city
global city_ru
global city_ru_e
global moon_phase
global moon_phase_name
global weather
global capital
global population
global area_country
global currency
global languages
global borders
global glasny
global soglasny
layout = BoxLayout(orientation = "vertical")
but = Button(text="Привет")
label = Label(text = "Hdhsuxj", font_name = "fixedsys")
root.add_widget(layout)
layout.add_widget(but)
layout.add_widget(label)
if check_internet_connection():
pass
else:
while True:
os.system("clear")
print("\nОтсутствует подключение к интернету!", end = "\r")
t.sleep(5)
print(blue, "Добро пожаловать!", reset)
print("\nЗагрузка ресурсов... 0%", end = "\r")
ip = rq.get("http://icanhazip.com").text.strip()
print("Загрузка ресурсов... 10%", end = "\r")
url_ip = f"https://ipinfo.io/{ip}"
resp_ip = rq.get(url_ip)
data = resp_ip.json()
print("Загрузка ресурсов... 15%", end = "\r")
loc = data.get('loc')
print("Загрузка ресурсов... 24%", end = "\r")
lat, lon = loc.split(',')
lat = lat.strip()
lon = lon.strip()
print("Загрузка ресурсов... 36%", end = "\r")
country = data.get('country').upper()
country_info = ci("ru")
translate = tr(to_lang = "ru")
if country != "RU":
while True:
os.system("clear")
print(red, "\n!ERROR!", reset)
print("\nThis app is not supported in your country...")
print("If you are in Russia, make sure your VPN is disabled!")
t.sleep(10)
print("Загрузка ресурсов... 39%", end = "\r")
region = data.get('region')
print("Загрузка ресурсов... 44%", end = "\r")
city = data.get('city')
city_ru = translate.translate(city)
city_check_letter = city_ru[-1].lower()
if city_check_letter in glasny:
city_ru_e = city_ru[:-1] + "е"
if city_check_letter in soglasny:
city_ru_e = city_ru + "e"
print("Загрузка ресурсов... 50%", end = "\r")
url_m = "https://phasesmoon.com/"
resp_m = rq.get(url_m)
print("Загрузка ресурсов... 61%", end = "\r")
html_m = resp_m.text
soup_m = bs(resp_m.content, 'html.parser')
moon = soup_m.find("section", class_ = "pargraph")
moon_phase = moon.find("strong", string = lambda text: "%" in text).text
moon_phase_name = moon.find("strong").text
city_low = city.lower()
url_w = f"https://www.ventusky.com/ru/{city_low}"
resp_w = rq.get(url_w)
html_w = resp_w.text
soup_w = bs(html_w, 'html.parser')
weather_get = soup_w.find_all(class_ = "temperature")
weather = weather_get[0].get_text().strip()
print("Загрузка ресурсов... 73%", end = "\r")
country_info = ci("Russia")
capital = country_info.capital()
languages = country_info.languages()
population = country_info.population()
area_country = country_info.area()
currency = "".join(country_info.currencies())
borders = country_info.borders()
print("Загрузка ресурсов... 78%", end = "\r")
url_c = f"https://www.investing.com/currencies/usd-{currency}"
resp_c = rq.get(url_c)
html_c = resp_c.text
soup_c = bs(html_c, "html.parser")
currency_now_get = soup_c.find_all("script")[2]
print(currency_now_get)
class Prototype(App):
def build(self):
root = BoxLayout(orientation = "vertical")
loading(root)
return root
if __name__ == "__main__":
Prototype().run()
Проблема в том, что графический интерфейс запускается с задержкой от 5 до 7 секунд. Запускаю скрипт, черный экран (хотя графические элементы уже должны появиться) держится около 7 секунд и только потом они появляются. Запускаю скрипт, черный экран (хотя графические элементы уже должны показываться) проходит секунд 7 и только потом они появляются. Я долго с этим боролся, но ничего не помогало. Я попробовал потоковую передачу, но проблема не устранена. P.S.: Я относительно новичок в Python.
У меня большая проблема с моим кодом на Python. Немного добавлю, пишу с переводчика, так как плохо знаю английский, а также пишу код на PyDroid 3 на телефоне, так как компьютера у меня нет. Вот мой код (свел к корню проблемы, оставив импорт): [code]
[/code] Проблема в том, что графический интерфейс запускается с задержкой от 5 до 7 секунд. Запускаю скрипт, черный экран (хотя графические элементы уже должны появиться) держится около 7 секунд и только потом они появляются. Запускаю скрипт, черный экран (хотя графические элементы уже должны показываться) проходит секунд 7 и только потом они появляются. Я долго с этим боролся, но ничего не помогало. Я попробовал потоковую передачу, но проблема не устранена. P.S.: Я относительно новичок в Python.