tottori-opendata-pm25-api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -24
- data/exe/tottori-opendata-pm25-api +8 -1
- data/lib/tottori-opendata-pm25-api/client.rb +4 -3
- data/lib/tottori-opendata-pm25-api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0abec8763c2bfe425afeb31d04c62c7d6af34617
|
4
|
+
data.tar.gz: deed2ef46322163c76ba82290f8f9547a704e400
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29ff7d1f786dddea62d3c678a5665a84932c2c9efb8b88d71824d9bfbd63d0a8437ad4eeac4523267d7caa29cb75f49dfd02f1a56f0df898ae7798b071ccd4c7
|
7
|
+
data.tar.gz: b3444acbb02bbab3dba072fcbc93459de7c95f6bff205a7840e403a26924a9cf29b81e4248b1faf9d98582c59e23f71b217e57869a04f85f1c5a0f7872d4380a
|
data/README.md
CHANGED
@@ -1,41 +1,46 @@
|
|
1
|
-
# Tottori
|
1
|
+
# Tottori OpenData PM2.5 API
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/tottori-opendata-pm25-api.svg)](https://badge.fury.io/rb/tottori-opendata-pm25-api)
|
4
4
|
|
5
|
-
|
5
|
+
This API gets data which is the concentration of PM2.5 (fine particulate matter) in the atmosphere in Tottori Prefecture, Japan from http://tottori-taiki.users.tori-info.co.jp/taiki/pc/graph/ as Open Data licensed [CC-BY](https://creativecommons.org/licenses/by/2.1/jp/).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
Add this line to your application's Gemfile:
|
10
9
|
|
11
|
-
```
|
12
|
-
gem
|
10
|
+
```bash
|
11
|
+
$ gem install tottori-opendata-pm25-api
|
13
12
|
```
|
14
13
|
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install tottori-opendata-pm25-api
|
22
|
-
|
23
14
|
## Usage
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
16
|
+
CLI:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
$ tottori-opendata-pm25-api | jq . | head
|
20
|
+
[
|
21
|
+
{
|
22
|
+
"name": "県庁西町分庁舎",
|
23
|
+
"values": [
|
24
|
+
{
|
25
|
+
"time": "2017-01-23T00:00:00.000+09:00",
|
26
|
+
"value": 9
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"time": "2017-01-23T01:00:00.000+09:00",
|
30
|
+
```
|
32
31
|
|
33
|
-
|
32
|
+
API:
|
34
33
|
|
35
|
-
|
34
|
+
```ruby
|
35
|
+
require 'tottori-opendata-pm25-api'
|
36
|
+
require 'time'
|
37
|
+
require 'json'
|
38
|
+
require 'active_support/json'
|
36
39
|
|
40
|
+
ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
|
41
|
+
puts Tottori::OpenData::PM25::API.get(Time.now).to_json
|
42
|
+
```
|
37
43
|
|
38
44
|
## License
|
39
45
|
|
40
46
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
@@ -3,9 +3,16 @@
|
|
3
3
|
require 'tottori-opendata-pm25-api'
|
4
4
|
require 'time'
|
5
5
|
require 'json'
|
6
|
+
require 'active_support/json'
|
7
|
+
|
8
|
+
ActiveSupport::JSON::Encoding.use_standard_json_time_format = true
|
6
9
|
|
7
10
|
def time
|
8
11
|
ARGV[0] ? Time.iso8601(ARGV[0]) : Time.now
|
9
12
|
end
|
10
13
|
|
11
|
-
|
14
|
+
def data
|
15
|
+
Tottori::OpenData::PM25::API.get(time)
|
16
|
+
end
|
17
|
+
|
18
|
+
puts data.to_json
|
@@ -15,6 +15,7 @@ def get(t = Time.now)
|
|
15
15
|
uri << [
|
16
16
|
'mode=table',
|
17
17
|
'graph=hour',
|
18
|
+
'item=021',
|
18
19
|
"date=#{date.strftime('%Y%m%d')}",
|
19
20
|
(1..6).map{ |i| 'term[]=%03d' % i }.join('&')
|
20
21
|
].join('&')
|
@@ -22,7 +23,7 @@ def get(t = Time.now)
|
|
22
23
|
content = HTTPClient.get_content(uri)
|
23
24
|
# Parse
|
24
25
|
doc = Nokogiri::HTML.parse(content)
|
25
|
-
#
|
26
|
+
# Scrap
|
26
27
|
data = []
|
27
28
|
doc.xpath('//table[@class="commonTable"]/tbody/tr').each do |tr|
|
28
29
|
row = tr.children
|
@@ -30,13 +31,13 @@ def get(t = Time.now)
|
|
30
31
|
values = row.map{ |c|
|
31
32
|
s = c.text.strip
|
32
33
|
s.empty? ? nil : s.to_i
|
33
|
-
}.map.with_index
|
34
|
+
}.map.with_index{ |value, i|
|
34
35
|
iso8601_time = ('%4d-%02d-%02dT%02d:00:00+09:00' % [date.year, date.month, date.day, i]).strip
|
35
36
|
{
|
36
37
|
time: Time.iso8601(iso8601_time),
|
37
38
|
value: value
|
38
39
|
}
|
39
|
-
|
40
|
+
}
|
40
41
|
record = {
|
41
42
|
name: name,
|
42
43
|
values: values
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tottori-opendata-pm25-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masayuki Higashino
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|