Skip to content

Instantly share code, notes, and snippets.

@Mr-Coxall
Last active April 25, 2018 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mr-Coxall/acd10aecf318b1e9556d43a2e41940c7 to your computer and use it in GitHub Desktop.
Save Mr-Coxall/acd10aecf318b1e9556d43a2e41940c7 to your computer and use it in GitHub Desktop.
# getting the Ottawa weather forcast into a dictionary
import requests
weather_forcast = {}
response = requests.get('https://weather.gc.ca/wxlink/site_js/s0000623_e.js').text
weather_output = response.splitlines()
print("Got weather")
#print()
i = 0
while i < len(weather_output):
temp = weather_output[i]
weather_output[i] = temp[4:]
i = i + 1
for a in range(5, 8):
key,value = weather_output[a].split(' = ')
value = value[:-1]
#print(key + '->' + value)
weather_forcast[key] = value;
#print()
for x in range(9, 17):
key,value = weather_output[x].split(' = ')
value = value[1:]
temp1, temp2 = value.split('"')
value = temp1
#print(key + '->' + value)
weather_forcast[key] = value;
#print()
for y in range(18, 23):
key2,value2 = weather_output[y].split(' = ')
element = value2.split(',')
tempa = element[0]
tempa = tempa[1:]
tempa = tempa.replace('"', '')
element[0] = tempa
tempb = element[1].replace('"', '')
element[1] = tempb[1:]
tempc = element[2]
tempc = tempc[:-2]
tempc = tempc[1:]
tempc = tempc.replace('"', '')
element[2] = tempc
#print(key2 + '->' + element[0] + element[1] + element[2])
weather_forcast[key2] = element;
print("\n\n")
print(weather_forcast)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment