This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3.5 | |
from bs4 import BeautifulSoup | |
import requests | |
import json | |
URL="https://weather.gc.ca/warnings/report_e.html?qc67" | |
raw_html = requests.get(URL).text | |
data = BeautifulSoup(raw_html, 'html.parser') | |
j=dict() | |
date="None" | |
details="No warnings in effect" | |
raw_title=data.select('.col-xs-12:nth-of-type(1) p:nth-of-type(1)')[0] | |
title=str(raw_title).split(">")[5].split("<")[0][:-5] | |
date = str(raw_title).split(">")[2].split("<")[0] | |
if "No Alerts in effect" in str(raw_title): | |
title = "No alerts in effect" | |
details = "No alerts in effect" | |
else: | |
try: | |
details = data.select('.col-xs-12:nth-of-type(1) p:nth-of-type(2)')[0].text | |
except: | |
print("Unable to get details for alert") | |
j["date"] = date | |
j["details"] = details | |
j["title"] = title | |
print(json.dumps(j)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment