-
Notifications
You must be signed in to change notification settings - Fork 0
/
sugarloaf_status.py
executable file
·73 lines (54 loc) · 1.89 KB
/
sugarloaf_status.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# coding: utf-8
from bs4 import BeautifulSoup
import requests
import pandas as pd
MOBILE_SUGARLOAF_CONDITIONS_URL = (
"http://spotlio-snowconditions.s3.amazonaws.com/sugarloaf/status.json"
)
MOUNTAIN_REPORT_HTML = "https://www.sugarloaf.com/mountain-report"
response = requests.get(MOBILE_SUGARLOAF_CONDITIONS_URL)
json = response.json()
def flatten_item(item):
""" Returns a flattened version of the item """
output = {}
for key in item.keys():
if key not in ["status", "properties"]:
output[key] = item[key]
for status in item["status"]:
output[status["status_name"]] = status["status_value"]
for key, obj in item["properties"].items():
if key == "features":
for feature_key, feature_obj in obj.items():
output[feature_key] = feature_obj
else:
output[key] = obj
return output
trails_df = pd.DataFrame(
[flatten_item(item) for item in json if "type" in item and item["type"] == "trail"]
)
lifts_df = pd.DataFrame(
[flatten_item(item) for item in json if "type" in item and item["type"] == "lift"]
)
trails_df = trails_df.sort_values("name")
trails_df.to_csv("trails.csv", index=False)
lifts_df = lifts_df.sort_values("name")
lifts_df.to_csv("lifts.csv", index=False)
response = requests.get(MOUNTAIN_REPORT_HTML)
soup = BeautifulSoup(response.text)
longest_div = None
for div in soup.findAll("div", class_="content"):
div_text = div.getText()
if (
"Last Updated" not in div_text
and "Trail Status" not in div_text
and "Snow Making" not in div_text
and "Swedish Fiddle Glade" not in div_text
):
try:
if len(longest_div.getText()) < len(div_text):
longest_div = div
except AttributeError:
longest_div = div
with open("report.html", "w") as f:
f.write(str(longest_div))