Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Commit

Permalink
simler_code_url_requests
Browse files Browse the repository at this point in the history
  • Loading branch information
voronov-nikita committed Apr 14, 2023
1 parent 3dd5d88 commit 1a4c82b
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions MainApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

min_temp, min_hum_earth, min_hum_air = 0, 0, 0

PORT = 5000


db = sql.connect("tableinfo.db")
cursor = db.cursor()

Expand Down Expand Up @@ -157,6 +154,8 @@ def splitting_for(s):
"""


url = "http://192.168.0.19:5000"

# Класс для Выпадающего меню
class LeftMenu(Screen):
def __init__(self):
Expand All @@ -172,7 +171,7 @@ def __init__(self):

self.button_value = []
for i in range(1, 4 + 1):
res = get(f"https://192.168.43.147:{PORT}/temp_hum/{i}")
res = get(f"{url}/temp_hum/{i}")
self.button_value.append(
f"""Сенсор {i}:\nТемпература: {splitting_for(res.text)["temperature"]}\nВлажность: {splitting_for(res.text)["humidity"]}""")
self.fl = FloatLayout()
Expand Down Expand Up @@ -243,7 +242,7 @@ def next(self, instance):
# обновляем текст
def update(self, instance):
id_btn = instance.text[7:8]
res = get(f"https://192.168.43.147:{PORT}/temp_hum/{id_btn}")
res = get(f"{url}/temp_hum/{id_btn}")
txt = f"""Сенсор {id_btn}:\nТемпература: {splitting_for(res.text)["temperature"]}\nВлажность: {splitting_for(res.text)["humidity"]}"""
instance.text = txt

Expand Down Expand Up @@ -274,10 +273,10 @@ def temp_hum(self):
res_eath = []
for i in range(1, 4 + 1):
res_temp.append(
splitting_for(get(f"https://192.168.43.147:{PORT}/temp_hum/{i}").text)["temperature"])
res_air.append(splitting_for(get(f"https://192.168.43.147:{PORT}/temp_hum/{i}").text)["humidity"])
splitting_for(get(f"{url}/temp_hum/{i}").text)["temperature"])
res_air.append(splitting_for(get(f"{url}/temp_hum/{i}").text)["humidity"])
for i in range(1, 6 + 1):
res_eath.append(splitting_for(get(f'https://192.168.43.147:{PORT}/hum/{i}').text)["humidity"])
res_eath.append(splitting_for(get(f'{url}/hum/{i}').text)["humidity"])
return [self.average_value(res_temp),
self.average_value(res_air),
self.average_value(res_eath)]
Expand Down Expand Up @@ -325,25 +324,25 @@ def Init(self):
def start_all_water(self, instance):
if instance.text == "Начать\nОбщий полив":
instance.text = "Остановить полив"
res = patch("https://192.168.43.147:{PORT}/total_hum",
res = patch("{url}/total_hum",
params={"state": 0}
)
print(res.status_code)
else:
instance.text = "Начать\nОбщий полив"
res = patch("https://192.168.43.147:{PORT}/total_hum",
res = patch("{url}/total_hum",
params={"state": 1}
)

# отправляем patch запрос на открытие/закрытие форточки
def move_luck(self, instance):
if instance.text == "Открыть":
instance.text = "Закрыть"
res = get("https://192.168.43.147:{PORT}/fork_drive")
res = get("{url}/fork_drive")
print(res.status_code)
else:
instance.text = "Открыть"
res = get("https://192.168.43.147:{PORT}/fork_drive")
res = get("{url}/fork_drive")

def watering_one(self, instance):
pass
Expand All @@ -356,7 +355,7 @@ def __init__(self):

self.button_value = []
for i in range(1, 6 + 1):
res = get(f"https://192.168.43.147:{PORT}/hum/{i}")
res = get(f"{url}/hum/{i}")
self.button_value.append(
f"""Сенсор {i}:\nВлажность: {splitting_for(res.text)["humidity"]}""")
self.fl = FloatLayout()
Expand Down Expand Up @@ -433,7 +432,7 @@ def next(self, instance):
# обновляем текст
def update(self, instance):
id_btn = instance.text[7:8]
res = get(f"https://192.168.43.147:{PORT}/hum/{id_btn}")
res = get(f"{url}/hum/{id_btn}")
txt = f"""Сенсор {id_btn}:\nВлажность: {splitting_for(res.text)["humidity"]}"""
instance.text = txt

Expand Down Expand Up @@ -526,17 +525,17 @@ def Init(self):

def leaf_move(self, instance):
self.count_open = (1 if self.count_open == 0 else 0)
get("https://192.168.43.147:{PORT}/fork_drive")
get("{url}/fork_drive")

def water_run(self, instance):
get("https://192.168.43.147:{PORT}/watering")
get("{url}/watering")

def water_all_run(self, instance):
if self.water_all == 0:
self.water_all = 1
else:
self.water_all = 0
res = get("https://192.168.43.147:{PORT}/total_hum")
res = get("{url}/total_hum")

def warning(self, instance, value):
if value:
Expand Down Expand Up @@ -707,15 +706,15 @@ def Init(self):
def new_row_table(self, instance):
new_data_row = []
for i in range(1, 4 + 1):
res = get(f"https://192.168.43.147:{PORT}/temp_hum/{i}").text
res = get(f"{url}/temp_hum/{i}").text
temp = splitting_for(res)["temperature"]
hum = splitting_for(res)["humidity"]
new_data_row.append(
(i,
temp,
hum,
))
cursor.execute(f"""INSERT INTO tabel(id, температура, влажность воздуха)
cursor.execute(f"""INSERT INTO tabel(id, temperature, humidity_air)
VALUES("{i}", "{temp}", "{hum}");
""")
db.commit()
Expand Down Expand Up @@ -870,7 +869,8 @@ def build(self):


if __name__ == "__main__":
try:
MainApp().run()
except:
ErrorApp().run()
MainApp().run()
# try:
# MainApp().run()
# except:
# ErrorApp().run()

0 comments on commit 1a4c82b

Please sign in to comment.