MaxGit32 commited on
Commit
289125f
1 Parent(s): ab5eca3

Create Warning.py

Browse files
Files changed (1) hide show
  1. pages/Warning.py +67 -0
pages/Warning.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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):
8
+ # Ort aus Bot Anfrage
9
+ #self.ort = ort
10
+ # Warnings DataFrame
11
+ warnings = ApiCall.getData(self)
12
+ warnings.replace('', np.nan, inplace=True)
13
+ warnings = warnings[warnings['Plz'].notna()]
14
+ warnings.to_csv('api.csv', index=True)
15
+
16
+ def getPlz(self, ort):
17
+ # Plz von Chat auslesen
18
+ plzChat = Location(ort).getPostalCode()
19
+ #print(plzChat)
20
+ return plzChat
21
+
22
+ def cleanWarnings(self):
23
+ # Gibt Warnings die Plz haben aus
24
+ self.warnings.replace('', np.nan, inplace=True)
25
+ warnings = self.warnings[self.warnings['Plz'].notna()]
26
+
27
+ return warnings
28
+
29
+ def getWarningOrt(self, ort):
30
+ # Plz aus Ort von Nutzer
31
+ plz2 = self.getPlz(ort)
32
+ plz2 = plz2.iloc[0]['name']
33
+
34
+ try:
35
+ plz2 = int(plz2)
36
+ except:
37
+ fehler = "Keine Warnung gefunden"
38
+ print("Fehler")
39
+ return fehler
40
+
41
+ print(type(plz2))
42
+ print(plz2)
43
+
44
+ # Datafrme mit Warnings erstellen
45
+ data = pd.read_csv('api.csv')
46
+ print(data)
47
+
48
+ # Plz in DF suchen
49
+ gesuchte_zeile = data.loc[data['Plz'] == plz2]
50
+ print(gesuchte_zeile)
51
+ print("zeile")
52
+
53
+ if gesuchte_zeile.empty:
54
+ print("fehler")
55
+ fehler = "Es gibt keine Warnung"
56
+ return fehler
57
+ else:
58
+ wert_als_string = gesuchte_zeile.iloc[0]
59
+ print("in schleife")
60
+ return wert_als_string['Titel']
61
+
62
+
63
+ ## Testing Waring
64
+
65
+ # plz = Warning("Rottach-Egern")
66
+ # gesuchte_zeile = plz.getWarningOrt()
67
+ # print(gesuchte_zeile)