modified: .dockerignore

modified:   src/main.py
	modified:   src/moj_licznik.py

	modified:   .dockerignore
	modified:   src/CHANGELOG.md
	modified:   src/config.yaml
	modified:   src/main.py
	modified:   src/moj_licznik.py
This commit is contained in:
TC
2023-10-22 15:09:06 +02:00
parent cdc3f93e56
commit d210d3108b
5 changed files with 55 additions and 40 deletions

View File

@@ -2,6 +2,7 @@ env/
__pycache__
src/database.sqlite
src/config.ini
config.ini
import.py
check.py
Dockerfile

View File

@@ -1,2 +1,4 @@
## v0.1.0 [2023-10-21]
- Wersja beta
- Wersja beta
## v0.1.1 [2023-10-22]
- Dodano obsługe błędnego logowania

View File

@@ -1,6 +1,6 @@
name: "Energa meter"
description: "Energa meter addon"
version: "0.1.0"
version: "0.1.1"
slug: "energa_meter"
init: false
options:

View File

@@ -20,15 +20,16 @@ def main():
mojLicznik = MojLicznik()
print(f"Logowanie...", username)
mojLicznik.login(username, password)
print(f"Aktualizacja liczników...")
mojLicznik.uppdate_measurments()
print(f"Wyszukiwanie najstarszych danych...")
mojLicznik.update_first_date()
print(f"Pobieranie danych...")
mojLicznik.download_charts(True)
mojLicznik.update_last_days()
mojLicznik.set_daily_zones()
mojLicznik.logout()
if mojLicznik.loginStatus:
print(f"Aktualizacja liczników...")
mojLicznik.uppdate_measurments()
print(f"Wyszukiwanie najstarszych danych...")
mojLicznik.update_first_date()
print(f"Pobieranie danych...")
mojLicznik.download_charts(True)
mojLicznik.update_last_days()
mojLicznik.set_daily_zones()
mojLicznik.logout()
if __name__ == "__main__":
main()

View File

@@ -110,39 +110,50 @@ class MojLicznik:
try:
response = self.session.post(login_url, data=login_data)
response.raise_for_status()
self.loginStatus = True
print(f"Zalogowano")
except HTTPError as e:
print(f"Wystąpił błąd HTTP: {e}")
soup = BeautifulSoup(response.text, 'html.parser')
select_elements = soup.find_all('script', type='text/javascript')
meter_isd = []
for el in select_elements:
pattern = r"id:\s+(\d+),[\s\S]*?ppe:\s+'([\d\s]+)',[\s\S]*?tariffCode:\s+'([^']+)',[\s\S]*?name:\s+'([^']+)'"
matches = re.search(pattern, el.text)
if matches:
id_value = matches.group(1)
ppe_value = matches.group(2)
tariffCode_value = matches.group(3)
name_value = matches.group(4)
meter_isd.append(id_value)
retrieved_record = PPETable.get_or_none(id=id_value)
if retrieved_record:
print(f"Licznik {id_value} istnieje w systemie.")
if not retrieved_record.is_active:
retrieved_record.is_active = True
retrieved_record.save()
else:
print(f"Licznik {id_value} nie istnieje w systemie.")
data = PPETable.create(
id=id_value,
ppe=ppe_value,
tariffCode=tariffCode_value,
name=name_value
)
update_query = PPETable.update(is_active=0).where(PPETable.id.not_in(meter_isd))
update_query.execute()
login_error_text = 'Użytkownik lub hasło niepoprawne'
login_error = soup.find('div', text=login_error_text)
if login_error:
self.loginStatus = False
print(login_error_text)
else:
self.loginStatus = True
print(f"Zalogowano")
select_elements = soup.find_all('script', type='text/javascript')
meter_isd = []
for el in select_elements:
pattern = r"id:\s+(\d+),[\s\S]*?ppe:\s+'([\d\s]+)',[\s\S]*?tariffCode:\s+'([^']+)',[\s\S]*?name:\s+'([^']+)'"
matches = re.search(pattern, el.text)
if matches:
id_value = matches.group(1)
ppe_value = matches.group(2)
tariffCode_value = matches.group(3)
name_value = matches.group(4)
meter_isd.append(id_value)
retrieved_record = PPETable.get_or_none(id=id_value)
if retrieved_record:
print(f"Licznik {id_value} istnieje w systemie.")
if not retrieved_record.is_active:
retrieved_record.is_active = True
retrieved_record.save()
else:
print(f"Licznik {id_value} nie istnieje w systemie.")
data = PPETable.create(
id=id_value,
ppe=ppe_value,
tariffCode=tariffCode_value,
name=name_value
)
update_query = PPETable.update(is_active=0).where(PPETable.id.not_in(meter_isd))
update_query.execute()
def logout(self):
logout_url = f"{self.meter_url}/dp/MainLogout.go"