-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetweather.rb
109 lines (72 loc) · 1.98 KB
/
getweather.rb
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'open-uri'
require 'csv'
module STUFF
def sayhello
puts "HEllo!"
end
end
#@base_path = "/src/stuff/data/"
@base_path = "/Users/rebeccag/stuff/data/"
@url_start = "http://www.wunderground.com/history/airport/"
@airport = "KATT" # "KATT/" # "ENBR/"
@url_end = "/MonthlyHistory.html?format=1"
def get_year_url(airport, year)
start_year = year
start_month = 1
start_day = 1
end_year = year
end_month = 12
end_day = 31
"http://www.wunderground.com/history/airport/#{airport}/#{start_year}/#{start_month}/#{start_day}/CustomHistory.html?dayend=#{end_day}&monthend=#{end_month}&yearend=#{end_year}&req_city=NA&req_state=NA&req_statename=NA&format=1"
end
def get_yearly(airport, start_year, end_year)
current = start_year
while current <= end_year
url = get_year_url(airport, current)
file_string = ""
#puts "About to open file"
open (url) do |f|
file_string = f.read
end
file_string = file_string.gsub("<br />", "")
# puts "file_string: #{file_string}"
filepath = @base_path + airport + "-" + current.to_s + ".txt"
file = File.open(filepath, "w")
file.puts file_string
file.close
puts "wrote file #{filepath}"
current = current + 1
end
end
def get_monthly
start_date = 1948
end_date = 2012
current = start_date
while current <= end_date
month = 1
while month <= 12
date = "#{current}/#{month}/13"
date_string = date.split("/").join("-")
url = @url_start + @airport + date + @url_end
file_string = ""
#puts "About to open file"
open (url) do |f|
file_string = f.read
end
file_string = file_string.gsub("<br />", "")
# puts "file_string: #{file_string}"
filepath = @base_path + @airport.gsub("/", "-") + date_string + ".txt"
file = File.open(filepath, "w")
file.puts file_string
file.close
puts "wrote file #{filepath}"
month = month + 1
end
current = current + 1
end
end
def get_daily(month)
url_end = "DailyHistory.html?format=1"
end
puts "Running!"
# get_yearly(@airport, 1948, 2013)