Spaces:
Sleeping
Sleeping
Commit
·
31a591d
1
Parent(s):
d29d315
Upload 2 files
Browse files- Warning.py +39 -0
- telegram.py +91 -0
Warning.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from ApiCall import *
|
3 |
+
from Location import *
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
class Warning:
|
7 |
+
def __init__(self, ort):
|
8 |
+
# Ort aus Bot Anfrage
|
9 |
+
self.ort = ort
|
10 |
+
# Warnings DataFrame
|
11 |
+
self.warnings = ApiCall.getData(self)
|
12 |
+
|
13 |
+
def compare(self):
|
14 |
+
# Plz von Chat auslesen
|
15 |
+
plzChat = Location(self.ort).getPostalCode()
|
16 |
+
#print(plzChat)
|
17 |
+
return plzChat
|
18 |
+
|
19 |
+
def cleanWarnings(self):
|
20 |
+
# Gibt Warnings die Plz haben aus
|
21 |
+
self.warnings.replace('', np.nan, inplace=True)
|
22 |
+
warnings = self.warnings[self.warnings['Plz'].notna()]
|
23 |
+
|
24 |
+
return warnings
|
25 |
+
|
26 |
+
# plz = Warning("Rottach-Egern")
|
27 |
+
# plz2 = plz.compare()
|
28 |
+
|
29 |
+
# plz2 = plz2.iloc[0]['name']
|
30 |
+
# print(plz2)
|
31 |
+
|
32 |
+
# data = plz.cleanWarnings()
|
33 |
+
# print(data)
|
34 |
+
|
35 |
+
# gesuchte_zeile = data.loc[data['Plz'] == plz2]
|
36 |
+
|
37 |
+
# print("data:")
|
38 |
+
# print(gesuchte_zeile)
|
39 |
+
|
telegram.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import telebot
|
2 |
+
# from telebot import types
|
3 |
+
import asyncio
|
4 |
+
from telebot.async_telebot import AsyncTeleBot
|
5 |
+
|
6 |
+
from Warning import *
|
7 |
+
|
8 |
+
|
9 |
+
#### Julian neu #####
|
10 |
+
|
11 |
+
with open("token.txt") as file:
|
12 |
+
token = file.read()
|
13 |
+
bot = AsyncTeleBot(token)
|
14 |
+
|
15 |
+
# Handle '/start' and '/help'
|
16 |
+
@bot.message_handler(commands=['help', 'start'])
|
17 |
+
async def send_welcome(message):
|
18 |
+
await bot.reply_to(message, """\
|
19 |
+
Hi there, I am EchoBot.
|
20 |
+
I am here to echo your kind words back to you. Just say anything nice and I'll say the exact same thing to you!\
|
21 |
+
""")
|
22 |
+
|
23 |
+
@bot.message_handler(func=lambda message: True)
|
24 |
+
async def get_Message(message):
|
25 |
+
frage = message.text
|
26 |
+
print(frage)
|
27 |
+
|
28 |
+
# GetLocation von Nutzereingabe
|
29 |
+
plz = Warning(frage)
|
30 |
+
plz2 = plz.compare()
|
31 |
+
plz2 = plz2.iloc[0]['name']
|
32 |
+
print(plz2)
|
33 |
+
|
34 |
+
data = plz.cleanWarnings()
|
35 |
+
print(data)
|
36 |
+
|
37 |
+
gesuchte_zeile = data.loc[data['Plz'] == plz2]
|
38 |
+
|
39 |
+
await bot.reply_to(message, gesuchte_zeile)
|
40 |
+
|
41 |
+
asyncio.run(bot.polling())
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
# ### Paul alt ####
|
49 |
+
# with open("token.txt") as file:
|
50 |
+
# token = file.read()
|
51 |
+
|
52 |
+
# bot = telebot.TeleBot(token)
|
53 |
+
# frage = ""
|
54 |
+
|
55 |
+
# # Startnachricht
|
56 |
+
# startnachricht = "Disclaimer zu unserem Chatbot: ..."
|
57 |
+
# markup = types.InlineKeyboardMarkup()
|
58 |
+
# button = types.InlineKeyboardButton('Aktuelle Informationen zu Warnungen', callback_data='api_warnung')
|
59 |
+
# button = types.InlineKeyboardButton('Allgemeine Informationen zu Katastrophen', callback_data='allg_infos')
|
60 |
+
# markup.add(button)
|
61 |
+
|
62 |
+
# bot.send_message(chat_id='6475480143',text=startnachricht, reply_markup=markup)
|
63 |
+
|
64 |
+
# # Command Handler
|
65 |
+
# @bot.message_handler(commands=['start'])
|
66 |
+
# def start(message):
|
67 |
+
# markup = types.InlineKeyboardMarkup()
|
68 |
+
# button = types.InlineKeyboardButton('Aktuelle Informationen zu Warnungen', callback_data='api_warnung')
|
69 |
+
|
70 |
+
# markup.add(button)
|
71 |
+
|
72 |
+
# bot.send_message(message.chat.id, 'Hallo! Klicke auf den Button:', reply_markup=markup)
|
73 |
+
|
74 |
+
# # Nachricht erkennen
|
75 |
+
# @bot.callback_query_handler(func=lambda call: True)
|
76 |
+
# def callback_handler(call):
|
77 |
+
# # Antworten wenn API Infos gefordert
|
78 |
+
# if call.data == 'api_warnung':
|
79 |
+
# bot.send_message(call.message.chat.id, 'Antworten zu aktuellen Informationen:')
|
80 |
+
# if call.data == 'allg_infos':
|
81 |
+
# bot.send_message(call.message.chat.id, 'Antworten zu allgemeinen Informationen:')
|
82 |
+
|
83 |
+
# # Get_Message
|
84 |
+
# @bot.message_handler(func=lambda message: True)
|
85 |
+
# def get_Message(message):
|
86 |
+
# #bot.reply_to(message, message.text)
|
87 |
+
# frage = message.text
|
88 |
+
# print(frage)
|
89 |
+
|
90 |
+
# # Bot starten
|
91 |
+
# bot.infinity_polling()
|