Fixed dashboard weather, better status.
This commit is contained in:
parent
723bf34d74
commit
2142941aac
@ -20,8 +20,12 @@ class Help(BotFunc):
|
||||
CallbackQueryHandler(self.choose_specific, pattern="^specific$"),
|
||||
CallbackQueryHandler(self.print_one, pattern='func-'),
|
||||
],
|
||||
# ConversationHandler.TIMEOUT : [
|
||||
# CallbackQueryHandler(self.timeout)
|
||||
# ]
|
||||
},
|
||||
fallbacks=[CommandHandler('help', self.entry_point)],
|
||||
# conversation_timeout=5,
|
||||
)
|
||||
return conv_handler
|
||||
|
||||
@ -83,3 +87,19 @@ class Help(BotFunc):
|
||||
parse_mode = ParseMode.MARKDOWN_V2
|
||||
)
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
|
||||
def timeout(self, update: Update, context: CallbackContext) -> None:
|
||||
"""For dying conversation. Currently unused."""
|
||||
|
||||
query = update.callback_query
|
||||
name = query.data.replace("func-", "")
|
||||
query.answer()
|
||||
|
||||
message = name + ": `" + self.available_commands[name] + "`"
|
||||
query.edit_message_text(
|
||||
text= "EHHHHH",
|
||||
parse_mode = ParseMode.MARKDOWN_V2
|
||||
)
|
||||
return ConversationHandler.END
|
@ -5,6 +5,7 @@ import requests
|
||||
import socket
|
||||
import numpy as np
|
||||
import os
|
||||
import json
|
||||
|
||||
|
||||
FIRST = 1
|
||||
@ -59,6 +60,7 @@ class Status(BotFunc):
|
||||
message += "Reboots: `" + str(self.persistence["global"]["reboots"]) + "`\n"
|
||||
message += "IP (public): `" + ip + "`\n"
|
||||
message += "IP (private): `" + str(local_ips) + "`\n"
|
||||
message += "URL: `" + str(self.get_ngrok_url()) "`\n"
|
||||
|
||||
tot_r = np.array(self.persistence["bot"]["receive_activity"]["count"]).sum()
|
||||
message += "Total messages read: `" + str(tot_r) + "`\n"
|
||||
@ -80,4 +82,18 @@ class Status(BotFunc):
|
||||
with open("persistence/complete.log") as l:
|
||||
query.message.reply_document(l)
|
||||
|
||||
return ConversationHandler.END
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
def get_ngrok_url(self):
|
||||
try:
|
||||
url = "http://localhost:4040/api/tunnels/"
|
||||
res = requests.get(url)
|
||||
res_unicode = res.content.decode("utf-8")
|
||||
res_json = json.loads(res_unicode)
|
||||
for i in res_json["tunnels"]:
|
||||
if i['name'] == 'command_line':
|
||||
return i['public_url']
|
||||
break
|
||||
except:
|
||||
return "Not available"
|
@ -146,44 +146,56 @@ class DashBoard():
|
||||
return card
|
||||
|
||||
def card_weather(self):
|
||||
try:
|
||||
body = [html.H4("Wetter", className="card-title")]
|
||||
def weather_item(name, overview, temps):
|
||||
if len(temps) == 2:
|
||||
temp = "🌡(❄): " + str(temps[0]) + "° ➡ 🌡(🔥): " + str(temps[1]) + "°"
|
||||
else:
|
||||
temp = "🌡: " + str(temps[0]) + "°"
|
||||
temp_line = html.P(temp, className="mb-1")
|
||||
|
||||
it = html.A([
|
||||
html.Div([
|
||||
html.H5(name, className="mb-1"),
|
||||
html.Span(categories[overview], className="badge badge-primary badge-pill")
|
||||
],
|
||||
className="d-flex w-100 justify-content-between"),
|
||||
temp_line,
|
||||
],
|
||||
href="#", className="list-group-item bg-dark list-group-item-action text-light"
|
||||
)
|
||||
|
||||
return it
|
||||
|
||||
days = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"]
|
||||
categories = {"Clouds": "☁", "Rain": "🌧", "Thunderstorm": "🌩", "Drizzle": ":droplet:", "Snow": "❄", "Clear": "☀", "Mist": "🌫", "Smoke": "Smoke", "Haze": "Haze", "Dust": "Dust", "Fog": "Fog", "Sand": "Sand", "Dust": "Dust", "Ash": "Ash", "Squall": "Squall", "Tornado": "Tornado",}
|
||||
today = datetime.datetime.today().weekday()
|
||||
|
||||
body = []
|
||||
|
||||
try:
|
||||
content = self.bot.api_weather.show_weather([47.3769, 8.5417]) # still zürich
|
||||
|
||||
wt = content.pop(0)
|
||||
body.append(html.Span(children=[
|
||||
html.H6("Jetzt: " + wt["short"]),
|
||||
html.P("🌡 " + str(wt["temps"][0]) + "°")
|
||||
]))
|
||||
|
||||
days = ["Montag", "Dienstag", "Miitwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"]
|
||||
categories = {"Clouds": "☁", "Rain": "🌧", "Thunderstorm": "🌩", "Drizzle": ":droplet:", "Snow": "❄", "Clear": "☀", "Mist": "🌫", "Smoke": "Smoke", "Haze": "Haze", "Dust": "Dust", "Fog": "Fog", "Sand": "Sand", "Dust": "Dust", "Ash": "Ash", "Squall": "Squall", "Tornado": "Tornado",}
|
||||
|
||||
today = datetime.datetime.today().weekday()
|
||||
body.append(weather_item("Jetzt", wt["short"], wt["temps"]))
|
||||
|
||||
for i, day in enumerate(content):
|
||||
tmp = []
|
||||
if i == 0:
|
||||
tmp.append(html.H6("Heute: "+ categories[day["short"]]))
|
||||
day_name = "Heute"
|
||||
else:
|
||||
tmp.append(html.H6(days[(today + i + 1) % 7] + ": " + categories[day["short"]]))
|
||||
tmp.append(html.P("🌡 ❄ " + str(day["temps"][0]) + "° , 🌡 🔥 " + str(day["temps"][1]) + "°"))
|
||||
day_name = days[(today + i) % 7]
|
||||
|
||||
body.append(html.Span(children=tmp))
|
||||
body.append(weather_item(day_name, day["short"], day["temps"]))
|
||||
body = dbc.ListGroup(body, flush=True, style={"color":"black"})
|
||||
|
||||
|
||||
card = dbc.Card(
|
||||
[dbc.CardBody(body)],
|
||||
color="dark",
|
||||
inverse=True,
|
||||
)
|
||||
except:
|
||||
card = card = dbc.Card([
|
||||
dbc.CardBody([
|
||||
html.H4("Could not load WEATHER", className="card-title"),
|
||||
])
|
||||
],
|
||||
body.append(html.H6("Konnte nicht geladen werden"))
|
||||
|
||||
card = dbc.Card(
|
||||
[dbc.CardBody([
|
||||
html.H4("Wetter", className="card-title"),
|
||||
body])],
|
||||
color="dark",
|
||||
inverse=True,
|
||||
)
|
||||
@ -241,4 +253,5 @@ class DashBoard():
|
||||
color="dark",
|
||||
inverse=True,
|
||||
)
|
||||
return card
|
||||
return card
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user