comparison python/utils.py @ 856:e310577cc0b8

updated function (url) for weather data
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 05 Oct 2016 13:31:42 -0400
parents 2277ab1a8141
children a8de3c93f6b7
comparison
equal deleted inserted replaced
855:2277ab1a8141 856:e310577cc0b8
896 If month is provided (number 1 to 12), it means hourly data for the whole month 896 If month is provided (number 1 to 12), it means hourly data for the whole month
897 Otherwise, means the data for each day, for the whole year 897 Otherwise, means the data for each day, for the whole year
898 898
899 Example: MONTREAL MCTAVISH 10761 899 Example: MONTREAL MCTAVISH 10761
900 MONTREALPIERRE ELLIOTT TRUDEAU INTL A 5415 900 MONTREALPIERRE ELLIOTT TRUDEAU INTL A 5415
901 see ftp://client_climate@ftp.tor.ec.gc.ca/Pub/Get_More_Data_Plus_de_donnees/Station%20Inventory%20EN.csv
901 902
902 To get daily data for 2010 and 2011, downloadECWeather(10761, [2010,2011], [], '/tmp') 903 To get daily data for 2010 and 2011, downloadECWeather(10761, [2010,2011], [], '/tmp')
903 To get hourly data for 2009 and 2012, January, March and October, downloadECWeather(10761, [2009,2012], [1,3,10], '/tmp')''' 904 To get hourly data for 2009 and 2012, January, March and October, downloadECWeather(10761, [2009,2012], [1,3,10], '/tmp')'''
904 import urllib2 905 import urllib2
905 if english: 906 if english:
912 else: 913 else:
913 timeFrame = 1 914 timeFrame = 1
914 915
915 for year in years: 916 for year in years:
916 for month in months: 917 for month in months:
917 url = urllib2.urlopen('http://climat.meteo.gc.ca/climateData/bulkdata_{}.html?format=csv&stationID={}&Year={}&Month={}&Day=1&timeframe={}&submit=++T%C3%A9l%C3%A9charger+%0D%0Ades+donn%C3%A9es'.format(language, stationID, year, month, timeFrame)) 918 url = urllib2.urlopen('http://climate.weather.gc.ca/climate_data/bulk_data_{}.html?format=csv&stationID={}&Year={}&Month={}&Day=1&timeframe={}&submit= Download+Data'.format(language, stationID, year, month, timeFrame))
919 #http://climat.meteo.gc.ca/climateData/bulkdata_{}.html?format=csv&stationID={}&Year={}&Month={}&Day=1&timeframe={}&submit=++T%C3%A9l%C3%A9charger+%0D%0Ades+donn%C3%A9es
918 data = url.read() 920 data = url.read()
919 outFilename = '{}/{}-{}'.format(outputDirectoryname, stationID, year) 921 outFilename = '{}/{}-{}'.format(outputDirectoryname, stationID, year)
920 if timeFrame == 1: 922 if timeFrame == 1:
921 outFilename += '-{}-hourly'.format(month) 923 outFilename += '-{}-hourly'.format(month)
922 else: 924 else: