Esempio n. 1
0
# coding: utf-8


from include import loadairports
import os, csv

STATIONSPATH = os.getcwd() + '/data/stations.csv'
HISTORYPATH = os.getcwd() + '/out/history/'
SUMSTATESPATH = os.getcwd() + '/out/sumstates/'

#load all ICAO airports codes for all states in all countries
adata = loadairports.load_airports(STATIONSPATH)
for country in adata:
    for state in adata[country]:
        maxtemp = {}
        mintemp = {}
        humidity = {}
        precip = {}
        date = []
        for icao in adata[country][state]:
            date = []
            rows = csv.reader(open(HISTORYPATH + icao + '.csv', 'r'), delimiter=';')
            for row in rows:
                dt = row[0]
                date.append(dt)

                if row[1] != '':
                    if not (dt in maxtemp):
                        maxtemp[dt] = [int(row[1])]
                    else:
                        maxtemp[dt].append(int(row[1]))
Esempio n. 2
0
    outlist = []
    url = 'http://www.wunderground.com/history/airport/' + icao + '/' + str(year) + '/' + str(month) + \
          '/1/MonthlyHistory.html?format=1'
    request = urllib2.urlopen(url)
    data = request.readlines()
    for idx in range(2, len(data)):
        splitted = data[idx].decode("utf-8").replace(u'<br />\n', '').split(',')
        outlist.append([splitted[0], splitted[1], splitted[3], splitted[8], splitted[-4]])
    return outlist


if __name__ == '__main__':
#    print(getmonthhistory('SBIL', 2015, 1))
    import time, datetime, os.path
    from include import loadairports
    adata = loadairports.load_airports(os.getcwd() + '/data/stations.csv')
    for country in adata:
        for state in adata[country]:
            for icao in adata[country][state]:
                print('Loading history for ' + icao)
                file_path = os.getcwd() + '/out/history/' + icao + '.csv'
                if os.path.exists(file_path):
                    outfile = open(file_path, 'r')
                    lastdate = outfile.readlines()[-1].split(';')[0]
                    outfile.close()
                else:
                    lastdate = '2010-1-1'
                startyear = int(lastdate.split('-')[0])
                startmonth = int(lastdate.split('-')[1])
                outfile = open(file_path, 'a')
                for year in range(startyear, datetime.datetime.now().year + 1):