Secret Ninja Blog

Customer Experience Senior Directorしてます

embulk-output-pixelaを作ってみた

Pixelaとは

blog.a-know.me

pixe.la

そしてGemも

sue445.hatenablog.com

github.com

だったら過去データ用にEmbulkかな

というわけで作った。(あいかわずテスト無しjruby plugin...)

利用方法

ユーザ登録と登録対象となるグラフについては事前に作成の必要があります。

$ gem install pixela

$ irb
> require "pixela"
> client = Pixela::Client.new(username: "YOURNAME", token: "YOURTOKEN")
> client.create_user(agree_terms_of_service: true, not_minor: true)
> client.create_graph(graph_id: "YOURIDNAME", name: "YOURGRAPHNAME", unit: "commit", type: "int", color: "shibafu")

これをすると、下記のようになっているはずなので。

https://camo.githubusercontent.com/0bfe7f5f7abc6cb60b6152836b2355683d60e344/68747470733a2f2f742e6779617a6f2e636f6d2f7465616d732f74726561737572652d646174612f61623461346336656532643536643463626532623334623939376331356532342e706e67

Embulkインストール後に (Embulkの使い方はぐぐってみていただけると!)

embulk gem install embulk-output-pixela

でインストールして、下記みたいなCSVがあったときに

point,date
0,2018/10/01
1,2018/10/02
2,2018/10/03
3,2018/10/04
4,2018/10/05
5,2018/10/06
6,2018/10/07
7,2018/10/08
8,2018/10/09
9,2018/10/10
10,2018/10/11
11,2018/10/12
12,2018/10/13
13,2018/10/14
14,2018/10/15

下記の設定ファイルを用意して、

in:
  type: file
  path_prefix: test.csv
  parser:
    charset: UTF-8
    newline: CRLF
    type: csv
    delimiter: ','
    quote: '"'
    escape: '"'
    trim_if_not_quoted: false
    skip_header_lines: 1
    allow_extra_columns: false
    allow_optional_columns: false
    columns:
    - {name: point, type: long}
    - {name: date, type: timestamp, format: '%Y/%m/%d'}
out:
  type: pixela
  name: torut
  token: xxxx
  graph_id: embulk-test
  quantity_int_column: point
  date_column: date

Embulkを実行すると取り込めます。

embulk run example.yml

https://camo.githubusercontent.com/94bfb03920c61ce12c724ceb397e59b0cf5a8b5d/68747470733a2f2f742e6779617a6f2e636f6d2f7465616d732f74726561737572652d646174612f31643330333261643038653562376436326165363132643834646434636634622e706e67

参考:

github.com

今の所、各日付の新規追加しかできず、既存のアップデートなどはできません。

なんか手元にデータがあって、とりあえずインポートしたいってときにでも試して見てください。