-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathscript.py
More file actions
49 lines (38 loc) · 1.63 KB
/
script.py
File metadata and controls
49 lines (38 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from pathlib import Path
from geopy.geocoders import Nominatim
import requests
import pandas as pd
def get_forecast( city='Pittsburgh' ):
'''
Returns the nightly's forecast for a given city.
Inputs:
city (string): A valid string
Output:
period (dictionary/JSON): a dictionary containing at least, the forecast keys startTime, endTime and detailedForecast.
Throws:
CityNotFoundError if geopy returns empty list or if the latitude longitude fields are empty.
ForecastUnavailable if the period is empty or the API throws any status code that is not 200
Hint:
* Return the period that is labeled as "Tonight"
'''
raise NotImplementedError()
def main():
period = get_forecast()
file = 'weather.pkl'
if Path(file).exists():
df = pd.read_pickle( file )
else:
df = pd.DataFrame(columns=['Start Date', 'End Date', 'Forecast'])
df = df.append({'Start Date': period['startTime'], 'End Date': period['endTime'], 'Forecast': period['detailedForecast']}, ignore_index=True)
df = df.drop_duplicates()
df.to_pickle(file)
#sort repositories
file = open("README.md", "w")
file.write('\n')
file.write('\n')
file.write('# Pittsburgh Nightly Forecast\n\n')
file.write(df.to_markdown(tablefmt='github'))
file.write('\n\n---\nCopyright © 2022 Pittsburgh Supercomputing Center. All Rights Reserved.')
file.close()
if __name__ == "__main__":
main()