Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,8 +15,46 @@ acontainer3 = st.empty()
|
|
15 |
def asubmit(aparam):
|
16 |
adf2 = aparam["adataframe"]
|
17 |
aselecteditem = adf2.loc[adf2["atitle"]==aparam["aselected"], "astationcode"]
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
adf = pd.DataFrame(
|
22 |
astations,
|
@@ -27,4 +65,4 @@ aoption = acontainer1.selectbox(
|
|
27 |
adf['atitle']
|
28 |
)
|
29 |
if acontainer2.button("Submit") == True:
|
30 |
-
asubmit(aparam={"aselected":aoption,"acontainer":acontainer3,"adataframe":adf,})
|
|
|
15 |
def asubmit(aparam):
|
16 |
adf2 = aparam["adataframe"]
|
17 |
aselecteditem = adf2.loc[adf2["atitle"]==aparam["aselected"], "astationcode"]
|
18 |
+
|
19 |
+
adf3 = pd.DataFrame(
|
20 |
+
[
|
21 |
+
[
|
22 |
+
adf2.loc[adf2["atitle"]==aparam["aselected"], "alatitude"],
|
23 |
+
adf2.loc[adf2["atitle"]==aparam["aselected"], "alongitude"],
|
24 |
+
]
|
25 |
+
],
|
26 |
+
columns=['lat', 'lon']
|
27 |
+
)
|
28 |
+
aparam["acontainer"].map(adf3)
|
29 |
+
|
30 |
+
return
|
31 |
+
|
32 |
+
abacklogmax = 10
|
33 |
+
atoday = datetime.date.today()
|
34 |
+
ayear = int(atoday.strftime("%Y"))-0
|
35 |
+
amonth = int(atoday.strftime("%m"))
|
36 |
+
amonthday = int(atoday.strftime("%d"))
|
37 |
+
|
38 |
+
|
39 |
+
csvString = ""
|
40 |
+
csvString += (",").join(mytitles)
|
41 |
+
adf3 = pd.DataFrame(columns=mytitles)
|
42 |
+
for i in range((ayear-abacklogmax),ayear,1):
|
43 |
+
alink = ("https://data.weather.gov.hk/weatherAPI/opendata/opendata.php?dataType=CLMTEMP&year={}&rformat=csv&station={}").format(str(i),aselecteditem.values[0])
|
44 |
+
adf4 = pd.read_csv(alink, skiprows=[0,1,2], skipfooter=3, engine='python', on_bad_lines='skip')
|
45 |
+
|
46 |
+
adf4 = df.reset_index() # make sure indexes pair with number of rows
|
47 |
+
for index, row in adf4.iterrows():
|
48 |
+
if (row[2]!=amonth) or (row[3]!=amonthday):
|
49 |
+
continue
|
50 |
+
|
51 |
+
adate = ("{:02d}.{:02d}.{} 00:00:00").format(row[3], row[2], row[1])
|
52 |
+
csvString += '\n'+(",").join([adate,str(row[4]),""])
|
53 |
+
st.write(row[0],adate)
|
54 |
+
adf3 = adf3.append({"Date Time":adate,"T (degC)":(row[4]),}, ignore_index=True)
|
55 |
+
break
|
56 |
+
adf3 = pd.read_csv(StringIO(csvString), sep=",")
|
57 |
+
aparam["acontainer"].dataframe(adf3)
|
58 |
|
59 |
adf = pd.DataFrame(
|
60 |
astations,
|
|
|
65 |
adf['atitle']
|
66 |
)
|
67 |
if acontainer2.button("Submit") == True:
|
68 |
+
asubmit(aparam={"aselected":aoption,"acontainer":acontainer3,"adataframe":adf,})
|