Skip to content

Instantly share code, notes, and snippets.

@shibacow
Created August 29, 2015 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibacow/cf9b51839fbf25632b18 to your computer and use it in GitHub Desktop.
Save shibacow/cf9b51839fbf25632b18 to your computer and use it in GitHub Desktop.
http://qiita.com/HirofumiTamori/items/602d9b326cb4816c2fe6 のソースを今でも動くように改良(2015/08/29)
defmodule VercheckEx do
# requireで使用するライブラリを指定
require HTTPoison
require Floki
require Timex
use Timex
def fetch_content(url, type) do
ret = HTTPoison.get!( url ) # urlで指定されるページのデータを取得
%HTTPoison.Response{status_code: 200, body: body} = ret
# HTML bodyを取得する
# HTMLパーザー Flokiで処理
# 名前、リリース日時を取得
{_,_,n} = Floki.find(body, "[itemprop=title]") |> List.first
{_, date} = Floki.find(body, "time") |> Floki.attribute("datetime")
|> List.first
|> Timex.DateFormat.parse("{ISOz}")
if(type == :type1) do # バージョン番号を取得
{_,_,x} = Floki.find(body, ".tag-name span") |> List.first
else
{_,_,x} = Floki.find(body, ".css-truncate-target span") |> List.first
end
#UTC時刻をJSTに変更
date |> DateConvert.to_erlang_datetime
|> Timex.Date.from "Asia/Tokyo"
{hd(n),hd(x),date} # 戻り値はタプル
end
def put_a_formatted_line(val) do # 1行出力
{title, ver, date} = val
l = title
if String.length(title) < 8 do
l = l <> "\t"
end
l = l <> "\t" <> ver
if String.length(ver) < 8 do
l = l <> "\t"
end
l = l <> "\t" <> Timex.DateFormat.format!(date, "%Y.%m.%d", :strftime)
now = Timex.Date.now("JST")
diff = Timex.Date.diff( date, now, :days) # リリースから今日までの日数
if diff < 14 do # 14日以内なら警告する。以前の仕事が2週間スプリントだった名残り。
l = l <> "\t<<<<< updated at " <> Integer.to_string(diff) <> " day(s) ago."
end
IO.puts(l)
end
end
urls = [
{"https://github.com/jquery/jquery/releases", :type1},
{"https://github.com/angular/angular/releases", :type1},
{"https://github.com/facebook/react/releases", :type2},
{"https://github.com/PuerkitoBio/goquery/releases", :type1},
{"https://github.com/revel/revel/releases", :type2},
{"https://github.com/lhorie/mithril.js/releases", :type1},
{"https://github.com/riot/riot/releases", :type1},
{"https://github.com/atom/atom/releases", :type2},
{"https://github.com/Microsoft/TypeScript/releases", :type2},
{"https://github.com/docker/docker/releases", :type1},
{"https://github.com/JuliaLang/julia/releases", :type2},
{"https://github.com/nim-lang/Nim/releases", :type1},
{"https://github.com/elixir-lang/elixir/releases", :type2},
{"https://github.com/philss/floki/releases", :type1},
{"https://github.com/takscape/elixir-array/releases", :type2},
]
# 逐次呼出し→結果出力 HTTPoison.start
Enum.each(urls, fn(i) ->
{u,t} = i
res = VercheckEx.fetch_content(u,t)
VercheckEx.put_a_formatted_line res
end)
@shibacow
Copy link
Author

実行結果

 mix run vercheckex
jquery          3.0.0-alpha1    2015.07.13
angular         2.0.0-alpha.35  2015.08.18      <<<<< updated at 11 day(s) ago.
facebook        v0.13.3         2015.08.03
PuerkitoBio     v0.3.2          2013.09.07
revel           v0.12.0         2015.03.25
lhorie          v0.1.34         2015.05.01
riot            v2.2.4          2015.08.12
atom            v1.0.9          2015.08.28      <<<<< updated at 1 day(s) ago.
Microsoft       v1.5.4          2015.07.15
docker          v1.8.0-rc2      2015.08.13
JuliaLang       v0.3.11         2015.07.27
nim-lang        v0.11.2         2015.05.04
elixir-lang     v1.0.5          2015.06.29
philss          v0.3.3          2015.08.23      <<<<< updated at 6 day(s) ago.
takscape        1.0.1           2014.09.23

@shibacow
Copy link
Author

実行環境はubuntu14.04です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment