tottori-opendata-pm25-api 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d95f3b7d9a9308a2978dee541fceee87c4702cb
4
- data.tar.gz: 35edb9a9823a031534cbcfff60bff482b887e5b9
3
+ metadata.gz: 0abec8763c2bfe425afeb31d04c62c7d6af34617
4
+ data.tar.gz: deed2ef46322163c76ba82290f8f9547a704e400
5
5
  SHA512:
6
- metadata.gz: 54c33017e684a53d6269c6ee626143e2703d96f82585341c63026a34443830f8f33f2e15a9435637689249e61e2ef77a8c3d4a24e5969eb38fb56291c4c72666
7
- data.tar.gz: 2a37943717273812d351a5675eff288230c9b0d8c6aa1ef4f9041456fd9070fa4450a86ca1775975e4084a1baebbaef714f3b6920d5dbf6e27d7fdb05a8b6169
6
+ metadata.gz: 29ff7d1f786dddea62d3c678a5665a84932c2c9efb8b88d71824d9bfbd63d0a8437ad4eeac4523267d7caa29cb75f49dfd02f1a56f0df898ae7798b071ccd4c7
7
+ data.tar.gz: b3444acbb02bbab3dba072fcbc93459de7c95f6bff205a7840e403a26924a9cf29b81e4248b1faf9d98582c59e23f71b217e57869a04f85f1c5a0f7872d4380a
data/README.md CHANGED
@@ -1,41 +1,46 @@
1
- # Tottori::Opendata::Pm25::Api
1
+ # Tottori OpenData PM2.5 API
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tottori/opendata/pm25/api`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- ```ruby
12
- gem 'tottori-opendata-pm25-api'
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
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- ## Contributing
32
+ API:
34
33
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/Masayuki Higashino/tottori-opendata-pm25-api.
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
- puts Tottori::OpenData::PM25::API.get(time).to_json
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
- # Scraping
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 do |value, i|
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
- end
40
+ }
40
41
  record = {
41
42
  name: name,
42
43
  values: values
@@ -1,3 +1,3 @@
1
1
  module Tottori; module OpenData; module PM25; module API
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end; end; end; end
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.0
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-22 00:00:00.000000000 Z
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient