weatherscout 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/bin/weatherscout +2 -1
 - data/lib/weatherdesc/daily_weather.rb +29 -25
 - data/lib/weatherdesc/version.rb +1 -1
 - data/spec/weatherdesc_spec.rb +5 -0
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 065bceb5256db5d881158a995762ccc35562695e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 2471c33317bd0dfedb1386c321b9e6c7ee80e371
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: fd3036f6e2ce5f9dc8f58f4804ccb81fd890b7796f52f40c7ab4d5733e1e361ac436196573967af173a44588b5ae5c4e8d0f4b368a92d3fe33d73bc97689f30d
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b21b00571e29f00ec83b646fc9a37b2b82ee276efe90987f486533ed4ddbfe72a1b3eafcf4843f132ca1c1a751e0582f4b40417f9a2a5f21737ad393f4b78191
         
     | 
    
        data/bin/weatherscout
    CHANGED
    
    | 
         @@ -7,6 +7,7 @@ class WeatherCLI < Thor 
     | 
|
| 
       7 
7 
     | 
    
         
             
              desc 'today CITY', 'see the weather of the city today'
         
     | 
| 
       8 
8 
     | 
    
         
             
              def today(city)
         
     | 
| 
       9 
9 
     | 
    
         
             
                weather = DailyWeatherScraper::DailyWeather.new(city)
         
     | 
| 
      
 10 
     | 
    
         
            +
                city_eng = weather.city
         
     | 
| 
       10 
11 
     | 
    
         
             
                date = weather.date
         
     | 
| 
       11 
12 
     | 
    
         
             
                temperature_day = weather.temperature_day
         
     | 
| 
       12 
13 
     | 
    
         
             
                temperature_night = weather.temperature_night
         
     | 
| 
         @@ -14,7 +15,7 @@ class WeatherCLI < Thor 
     | 
|
| 
       14 
15 
     | 
    
         
             
                condition_day = weather.condition_day
         
     | 
| 
       15 
16 
     | 
    
         
             
                condition_night = weather.condition_night
         
     | 
| 
       16 
17 
     | 
    
         
             
                tips = weather.tips
         
     | 
| 
       17 
     | 
    
         
            -
                puts "#{city}(#{date} 
     | 
| 
      
 18 
     | 
    
         
            +
                puts "#{city}(#{city_eng})在 #{date} 的天氣狀況:"
         
     | 
| 
       18 
19 
     | 
    
         
             
                puts "白天氣象:#{condition_day},氣溫 #{temperature_day} 度"
         
     | 
| 
       19 
20 
     | 
    
         
             
                puts "晚上氣象:#{condition_night},氣溫 #{temperature_night} 度"
         
     | 
| 
       20 
21 
     | 
    
         
             
                puts "降雨機率:#{rain_probability}"
         
     | 
| 
         @@ -8,7 +8,12 @@ module DailyWeatherScraper 
     | 
|
| 
       8 
8 
     | 
    
         
             
                CITY_WEATHER_URL = "#{CWB_URL}/V7/forecast/taiwan/"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                def initialize(city)
         
     | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
      
 11 
     | 
    
         
            +
                  @city = name_mapping(city)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  parse_html(@city)
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def city
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @city
         
     | 
| 
       12 
17 
     | 
    
         
             
                end
         
     | 
| 
       13 
18 
     | 
    
         | 
| 
       14 
19 
     | 
    
         
             
                def date
         
     | 
| 
         @@ -42,8 +47,7 @@ module DailyWeatherScraper 
     | 
|
| 
       42 
47 
     | 
    
         
             
                private
         
     | 
| 
       43 
48 
     | 
    
         | 
| 
       44 
49 
     | 
    
         
             
                def parse_html(city)
         
     | 
| 
       45 
     | 
    
         
            -
                   
     | 
| 
       46 
     | 
    
         
            -
                  url = "#{CITY_WEATHER_URL}/#{english_name}.htm"
         
     | 
| 
      
 50 
     | 
    
         
            +
                  url = "#{CITY_WEATHER_URL}/#{city}.htm"
         
     | 
| 
       47 
51 
     | 
    
         
             
                  @document = Oga.parse_html(open(url))
         
     | 
| 
       48 
52 
     | 
    
         
             
                end
         
     | 
| 
       49 
53 
     | 
    
         | 
| 
         @@ -98,49 +102,49 @@ module DailyWeatherScraper 
     | 
|
| 
       98 
102 
     | 
    
         | 
| 
       99 
103 
     | 
    
         
             
                def name_mapping(city)
         
     | 
| 
       100 
104 
     | 
    
         
             
                  case city
         
     | 
| 
       101 
     | 
    
         
            -
                  when "臺北", "台北"
         
     | 
| 
      
 105 
     | 
    
         
            +
                  when "臺北", "台北", "臺北市", "台北市", "Taipei", "TaipeiCity"
         
     | 
| 
       102 
106 
     | 
    
         
             
                    result = "Taipei_City"
         
     | 
| 
       103 
     | 
    
         
            -
                  when "新北"
         
     | 
| 
      
 107 
     | 
    
         
            +
                  when "新北", "新北市", "NewTaipei", "NewTaipeiCity"
         
     | 
| 
       104 
108 
     | 
    
         
             
                    result = "New_Taipei_City"
         
     | 
| 
       105 
     | 
    
         
            -
                  when "桃園"
         
     | 
| 
      
 109 
     | 
    
         
            +
                  when "桃園", "桃園市", "Taoyuan", "TaoyuanCity"
         
     | 
| 
       106 
110 
     | 
    
         
             
                    result = "Taoyuan_City"
         
     | 
| 
       107 
     | 
    
         
            -
                  when "臺中", "台中"
         
     | 
| 
      
 111 
     | 
    
         
            +
                  when "臺中", "台中", "臺中市", "台中市", "Taichung", "TaichungCity"
         
     | 
| 
       108 
112 
     | 
    
         
             
                    result = "Taichung_City"
         
     | 
| 
       109 
     | 
    
         
            -
                  when "臺南", "台南"
         
     | 
| 
      
 113 
     | 
    
         
            +
                  when "臺南", "台南", "臺南市", "台南市", "Tainan", "TainanCity"
         
     | 
| 
       110 
114 
     | 
    
         
             
                    result = "Tainan_City"
         
     | 
| 
       111 
     | 
    
         
            -
                  when "高雄"
         
     | 
| 
      
 115 
     | 
    
         
            +
                  when "高雄", "高雄市", "Kaohsiung", "KaohsiungCity"
         
     | 
| 
       112 
116 
     | 
    
         
             
                    result = "Kaohsiung_City"
         
     | 
| 
       113 
     | 
    
         
            -
                  when "基隆"
         
     | 
| 
      
 117 
     | 
    
         
            +
                  when "基隆", "基隆市", "Keelung", "KeelungCity"
         
     | 
| 
       114 
118 
     | 
    
         
             
                    result = "Keelung_City"
         
     | 
| 
       115 
     | 
    
         
            -
                  when "新竹"
         
     | 
| 
      
 119 
     | 
    
         
            +
                  when "新竹", "新竹市", "Hsinchu", "HsinchuCiy"
         
     | 
| 
       116 
120 
     | 
    
         
             
                    result = "Hsinchu_City"
         
     | 
| 
       117 
     | 
    
         
            -
                  when " 
     | 
| 
      
 121 
     | 
    
         
            +
                  when "新竹縣", "HsinchuCounty"
         
     | 
| 
       118 
122 
     | 
    
         
             
                    result = "Hsinchu_County"
         
     | 
| 
       119 
     | 
    
         
            -
                  when "苗栗"
         
     | 
| 
      
 123 
     | 
    
         
            +
                  when "苗栗", "苗栗縣", "Miaoli", "MiaoliCounty"
         
     | 
| 
       120 
124 
     | 
    
         
             
                    result = "Miaoli_County"
         
     | 
| 
       121 
     | 
    
         
            -
                  when "彰化"
         
     | 
| 
      
 125 
     | 
    
         
            +
                  when "彰化", "彰化縣", "Changhua", "ChanghuaCounty"
         
     | 
| 
       122 
126 
     | 
    
         
             
                    result = "Changhua_County"
         
     | 
| 
       123 
     | 
    
         
            -
                  when "南投"
         
     | 
| 
      
 127 
     | 
    
         
            +
                  when "南投", "南投縣", "Nantou", "NantouCounty"
         
     | 
| 
       124 
128 
     | 
    
         
             
                    result = "Nantou_County"
         
     | 
| 
       125 
     | 
    
         
            -
                  when "雲林"
         
     | 
| 
      
 129 
     | 
    
         
            +
                  when "雲林", "雲林縣", "Yunlin", "YunlinCounty"
         
     | 
| 
       126 
130 
     | 
    
         
             
                    result = "Yunlin_County"
         
     | 
| 
       127 
     | 
    
         
            -
                  when "嘉義"
         
     | 
| 
      
 131 
     | 
    
         
            +
                  when "嘉義市", "嘉義", "Chiayi", "ChiayiCity"
         
     | 
| 
       128 
132 
     | 
    
         
             
                    result = "Chiayi_City"
         
     | 
| 
       129 
     | 
    
         
            -
                  when " 
     | 
| 
      
 133 
     | 
    
         
            +
                  when "嘉義縣", "ChiayiCounty"
         
     | 
| 
       130 
134 
     | 
    
         
             
                    result = "Chiayi_County"
         
     | 
| 
       131 
     | 
    
         
            -
                  when "屏東"
         
     | 
| 
      
 135 
     | 
    
         
            +
                  when "屏東", "屏東縣", "Pingtung", "PingtungCounty"
         
     | 
| 
       132 
136 
     | 
    
         
             
                    result = "Pingtung_County"
         
     | 
| 
       133 
     | 
    
         
            -
                  when "宜蘭"
         
     | 
| 
      
 137 
     | 
    
         
            +
                  when "宜蘭", "宜蘭縣", "Yilan", "YilanCounty"
         
     | 
| 
       134 
138 
     | 
    
         
             
                    result = "Yilan_County"
         
     | 
| 
       135 
     | 
    
         
            -
                  when "花蓮"
         
     | 
| 
      
 139 
     | 
    
         
            +
                  when "花蓮", "花蓮縣","Hualien", "HualienCounty"
         
     | 
| 
       136 
140 
     | 
    
         
             
                    result = "Hualien_County"
         
     | 
| 
       137 
     | 
    
         
            -
                  when "臺東", "台東"
         
     | 
| 
      
 141 
     | 
    
         
            +
                  when "臺東", "台東", "台東縣", "臺東縣", "Taitung", "TaitungCounty"
         
     | 
| 
       138 
142 
     | 
    
         
             
                    result = "Taitung_County"
         
     | 
| 
       139 
     | 
    
         
            -
                  when "澎湖"
         
     | 
| 
      
 143 
     | 
    
         
            +
                  when "澎湖", "澎湖縣" ,"Penghu", "PenghuCounty"
         
     | 
| 
       140 
144 
     | 
    
         
             
                    result = "Penghu_County"
         
     | 
| 
       141 
     | 
    
         
            -
                  when "金門"
         
     | 
| 
      
 145 
     | 
    
         
            +
                  when "金門", "金門縣", "Kinmen", "KinmenCounty"
         
     | 
| 
       142 
146 
     | 
    
         
             
                    result = "Kinmen_County"
         
     | 
| 
       143 
     | 
    
         
            -
                  when "連江"
         
     | 
| 
      
 147 
     | 
    
         
            +
                  when "連江", "連江縣", "Lienchiang", "LienchiangCounty"
         
     | 
| 
       144 
148 
     | 
    
         
             
                    result = "Lienchiang_County"
         
     | 
| 
       145 
149 
     | 
    
         
             
                  else
         
     | 
| 
       146 
150 
     | 
    
         
             
                    result = ""
         
     | 
    
        data/lib/weatherdesc/version.rb
    CHANGED
    
    
    
        data/spec/weatherdesc_spec.rb
    CHANGED
    
    | 
         @@ -5,6 +5,11 @@ CITY = "新竹" 
     | 
|
| 
       5 
5 
     | 
    
         
             
            weather = DailyWeatherScraper::DailyWeather.new(CITY)
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            describe 'Daily weather desc scrap' do
         
     | 
| 
      
 8 
     | 
    
         
            +
              it 'should return date with the "month/day" style' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                city = weather.city
         
     | 
| 
      
 10 
     | 
    
         
            +
                city.must_be_instance_of String
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
       8 
13 
     | 
    
         
             
              it 'should return date with the "month/day" style' do
         
     | 
| 
       9 
14 
     | 
    
         
             
                date = weather.date
         
     | 
| 
       10 
15 
     | 
    
         
             
                date.must_match /\d\d\/\d\d/
         
     |