erster Commit
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sun Jun 23 14:23:26 2024
|
||||
|
||||
@author: sven
|
||||
"""
|
||||
import requests
|
||||
|
||||
def send_request(vdat):
|
||||
# GET http://homeassistant.local:8123/api/history/period
|
||||
response = ''
|
||||
# vondatum = "2024-06-20T14:08:00.0000+00:00"
|
||||
bisdatum = vdat
|
||||
vdat = '"' + vdat + '"'
|
||||
|
||||
try:
|
||||
|
||||
response = requests.get(
|
||||
url="http://homeassistant.local:8123/api/history/period",
|
||||
params={
|
||||
vdat: "null",
|
||||
"filter_entity_id": "sensor.id_4_pro_performance_150_kw_204_ps_odometer",
|
||||
"minimal_response": "null",
|
||||
"end_time": bisdatum,
|
||||
"no_attributes": "null"
|
||||
},
|
||||
headers={
|
||||
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI1ZmNhNDVkZWQ1Mzg0MDZmOTY0NWVjOTI0MDNmYTEwNiIsImlhdCI6MTcxODk3Nzg5NiwiZXhwIjoyMDM0MzM3ODk2fQ.BGuVaCR9UM4O_LqYlcLd4LRLM8F_Vwnb9oU_xwh0Wew",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data={
|
||||
},
|
||||
)
|
||||
return response
|
||||
|
||||
# print('Response HTTP Status Code: {status_code}'.format(
|
||||
# status_code=response.status_code))
|
||||
# print('Response HTTP Response Body: {content}'.format(
|
||||
# content=response.content))
|
||||
except requests.exceptions.RequestException:
|
||||
print('HTTP Request failed')
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Sun Jun 23 14:49:38 2024
|
||||
|
||||
@author: sven
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
def umrechnen(dat_alt):
|
||||
zeitstempel1 = datetime.datetime.strptime(dat_alt, '%d.%m.%Y %H:%M:%S')
|
||||
zeitstempel_string = datetime.datetime.strftime(zeitstempel1, "%Y-%m-%dT%H:%M:%S")
|
||||
zeitstempel_string = zeitstempel_string + '.000000+00:00'
|
||||
return zeitstempel_string
|
||||
# pass
|
||||
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import api_call
|
||||
import datum_umrechnen
|
||||
|
||||
|
||||
kosten_pro_kwh = ''
|
||||
# kosten_pro_kwh = input('Kosten pro kWh (0.31) ')
|
||||
if kosten_pro_kwh == '':
|
||||
kosten_pro_kwh = 0.31
|
||||
|
||||
filename = '/Users/sven/Downloads/Eve Connect Export 28.06.2024.csv'
|
||||
|
||||
# Datei öffnen
|
||||
file = open(filename, 'r')
|
||||
|
||||
# Zeilenweise einlesen
|
||||
#inhalt = file.read().splitlines()
|
||||
|
||||
inhalt = file.readlines()
|
||||
file.close()
|
||||
|
||||
# Zeilenweise abloopen
|
||||
counter = 0
|
||||
kosten_gesamt = 0
|
||||
verbrauch_gesamt = 0
|
||||
|
||||
for zeile in inhalt:
|
||||
spalte = zeile.strip().split(',')
|
||||
if counter > 0:
|
||||
# Kosten pro Ladevorgang ermitteln
|
||||
verbrauch = spalte[4].strip()
|
||||
verbrauch = verbrauch.replace('kWh','')
|
||||
verbrauch = float(verbrauch)
|
||||
kosten_zeile = verbrauch * kosten_pro_kwh
|
||||
kosten_gesamt = kosten_gesamt + kosten_zeile
|
||||
verbrauch_gesamt = verbrauch_gesamt + verbrauch
|
||||
# Kilometerstand ermitteln und anfügen
|
||||
datum_zeit_alt = spalte[1].strip() + ' ' + spalte[2].strip()
|
||||
datum_von = datum_umrechnen.umrechnen(datum_zeit_alt)
|
||||
|
||||
# Homeassistant API rufen
|
||||
api_response = api_call.send_request(datum_von)
|
||||
apitext = api_response.text
|
||||
position = apitext.find("state")
|
||||
kilometer = apitext[position+8:position+13]
|
||||
|
||||
kosten_zeile = str(kosten_zeile)
|
||||
kilometer = str(kilometer)
|
||||
zeile = zeile + ', ' + kilometer + ' , ' + kosten_zeile
|
||||
print(zeile)
|
||||
counter = counter + 1
|
||||
else:
|
||||
zeile = zeile + ', ' + "Kilometerstand, " + "Kosten"
|
||||
print(zeile)
|
||||
|
||||
print(zeile)
|
||||
counter = counter + 1
|
||||
continue
|
||||
|
||||
print(" ")
|
||||
print('Kosten Gesamt: ', kosten_gesamt)
|
||||
strkostenkwh = str(kosten_pro_kwh)
|
||||
print("Kosten pro kWh: " + strkostenkwh + " €")
|
||||
verbrauch_gesamt = str(verbrauch_gesamt)
|
||||
print("Verbrauch Gesamt: " + verbrauch_gesamt)
|
||||
Reference in New Issue
Block a user