wetterinfo angefügt
This commit is contained in:
1 parent
ed7fd71368
commit
a5b9e96ebd
5 files changed
+119
-5
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import sqlite3
|
||||
from flask import Flask, render_template, request, url_for, flash, redirect
|
||||
import sqlite3,requests, json
|
||||
|
||||
from flask import Flask, flash, redirect, render_template, request, url_for
|
||||
from werkzeug.exceptions import abort
|
||||
|
||||
|
||||
def get_db_connection():
|
||||
conn = sqlite3.connect('energiemon.db')
|
||||
conn.row_factory = sqlite3.Row
|
||||
@@ -9,7 +11,23 @@ def get_db_connection():
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = 'Voobaiyae*h7kigj'
|
||||
|
||||
|
||||
def wetterinfo():
|
||||
api_key = "536479df69dcad6956b0c27300e8fddb"
|
||||
lat = "50.63856454090637"
|
||||
lon = "7.5160431030656145"
|
||||
url = "https://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&appid=%s&units=metric&lang=de" % (lat, lon, api_key)
|
||||
response = requests.get(url)
|
||||
data = json.loads(response.text)
|
||||
|
||||
current = data["main"]["temp"]
|
||||
wetterString=""+str(current)+"°C|"
|
||||
|
||||
current = data["weather"][0]["description"]
|
||||
wetterString+= current+"|"
|
||||
return wetterString
|
||||
|
||||
|
||||
@app.route('/', methods=('GET', 'POST'))
|
||||
def index():
|
||||
|
||||
@@ -18,7 +36,7 @@ def index():
|
||||
gaszaehler = request.form['gaszaehler']
|
||||
stromzaehler = request.form['stromzaehler']
|
||||
wasserzaehler = request.form['wasserzaehler']
|
||||
wetter = "Wetter " + request.form['wetter']
|
||||
wetter = wetterinfo() + request.form['wetter']
|
||||
conn = get_db_connection()
|
||||
conn.execute("INSERT INTO eintraege ( gaszaehler, stromzaehler, wasserzaehler, wetterinfo) VALUES ( ?, ?, ?, ?)",
|
||||
(gaszaehler , stromzaehler, wasserzaehler, wetter )
|
||||
@@ -35,4 +53,4 @@ def index():
|
||||
return render_template('index.html', eintraege=eintraege )
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
app.run()
|
||||
@@ -0,0 +1,30 @@
|
||||
# import the module
|
||||
import python_weather
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
async def getweather():
|
||||
# declare the client. format defaults to the metric system (celcius, km/h, etc.)
|
||||
async with python_weather.Client(format=python_weather.METRIC) as client:
|
||||
|
||||
# fetch a weather forecast from a city
|
||||
weather = await client.get("Flammersfeld,DE")
|
||||
|
||||
# returns the current day's forecast temperature (int)
|
||||
print(weather.current.temperature)
|
||||
|
||||
# get the weather forecast for a few days
|
||||
for forecast in weather.forecasts:
|
||||
print(forecast)
|
||||
|
||||
# hourly forecasts
|
||||
for hourly in forecast.hourly:
|
||||
print(f' --> {hourly!r}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
# see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
|
||||
# for more details
|
||||
if os.name == "nt":
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
asyncio.run(getweather())
|
||||
@@ -0,0 +1,25 @@
|
||||
# import the module
|
||||
import python_weather
|
||||
import os
|
||||
|
||||
def getweather():
|
||||
# declare the client. format defaults to the metric system (celcius, km/h, etc.)
|
||||
with python_weather.Client(format=python_weather.METRIC) as client:
|
||||
|
||||
# fetch a weather forecast from a city
|
||||
weather = client.get("Flammersfeld,DE")
|
||||
|
||||
# returns the current day's forecast temperature (int)
|
||||
print("Temp in FFeld: " + weather.current.temperature)
|
||||
|
||||
# get the weather forecast for a few days
|
||||
for forecast in weather.forecasts:
|
||||
print(forecast)
|
||||
|
||||
# hourly forecasts
|
||||
for hourly in forecast.hourly:
|
||||
print(f' --> {hourly!r}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
getweather()
|
||||
@@ -0,0 +1,23 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
def dingens():
|
||||
api_key = "536479df69dcad6956b0c27300e8fddb"
|
||||
lat = "50.63856454090637"
|
||||
lon = "7.5160431030656145"
|
||||
#url = "https://api.openweathermap.org/data/3.0/onecall?lat=%s&lon=%s&appid=%s&units=metric" % (lat, lon, api_key)
|
||||
url = "https://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&appid=%s&units=metric&lang=de" % (lat, lon, api_key)
|
||||
response = requests.get(url)
|
||||
data = json.loads(response.text)
|
||||
#print(data)
|
||||
|
||||
current = data["main"]["temp"]
|
||||
wetterString=""+str(current)+"°C|"
|
||||
#print(current)
|
||||
current = data["weather"][0]["description"]
|
||||
#print(current)
|
||||
wetterString+= current+"|"
|
||||
return wetterString
|
||||
|
||||
erg=dingens()
|
||||
print (erg)
|
||||
@@ -0,0 +1,18 @@
|
||||
from yahoo_weather.weather import YahooWeather
|
||||
from yahoo_weather.config.units import Unit
|
||||
|
||||
data = YahooWeather(APP_ID="zvpvcSm8",
|
||||
api_key="dj0yJmk9MkZpa0NuaVBFUVI2JmQ9WVdrOWVuWndkbU5UYlRnbWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTE1",
|
||||
api_secret="27067344a9651608e034bd156ce125bf6c45790e")
|
||||
|
||||
#data.get_yahoo_weather_by_city("flammersfeld-649875", Unit.celsius)
|
||||
data.get_yahoo_weather_by_location(50.63856454090637, 7.5160431030656145, Unit.celsius)
|
||||
#50.63856454090637, 7.5160431030656145
|
||||
#data.get_yahoo_weather_by_location(60,70,Unit.celsius)
|
||||
#data.get_yahoo_weather_by_city("tehran", Unit.celsius)
|
||||
# print(data.condition.text)
|
||||
print(data.condition.text)
|
||||
print(data.condition.temperature)
|
||||
|
||||
# print(data.condition.text)
|
||||
# print(data.condition.temperature)
|
||||
Reference in new issue
Block a user