apple_system_status (0.1.0): Apple System Status scraping library http://t.co/bDBkkUgDwm
— RubyGems (@rubygems) 2015, 7æ 28
çµç·¯
å æ¥iTunes Storeãªã©ã§é害ãèµ·ãã¦ãã¦ãå¼ç¤¾ã§ãiOSã®èª²éå¨ãã§ã¨ã©ã¼ãå¤çºãã¦ãã¾ãã
ä¸è¨ã¨ã³ããªãè¦ã¦ãã¦ãã¾ãã¾Appleã®System Statusãã¼ã¸ããããã¨ãç¥ãã¾ãã
ã©ãããgemï¼
Githubã¿ããã«rssãåããã° IFTTT ã¨é£æºãã¦ã¡ã¼ã«éãããã«ãã¦é害ãæ¤ç¥ã¨ããã®ãã§ããã®ã§ãã*1ãAppleã®æ¹ã¯ããããAPIããªãã£ãã®ã§ã¹ã¯ã¬ã¤ãã³ã°ãã¦ã¨ããããã«ããã®ãä»åã®apple_system_statusã¨ããgemã§ã
使ãæ¹
phantomjs ãå¿ è¦ãªã®ã§å¥éã¤ã³ã¹ãã¼ã«ãã¦ãã ãã
Rubyã§ä½¿ãå ´åã«ã¯ãããªæãã§ã
crawler = AppleSystemStatus::Crawler.new pp crawler.perform("jp") {:title=>"00:53 JST æç¹ã®ã·ã¹ãã ç¶æ³", :services=> [{:title=>"App Store", :description=>"åé¡ãªã: App Store", :status=>"allgood"}, {:title=>"iCloud ã¹ãã¬ã¼ã¸ã¢ããã°ã¬ã¼ã", :description=>"åé¡ãªã: iCloud ã¹ãã¬ã¼ã¸ã¢ããã°ã¬ã¼ã", :status=>"allgood"}, {:title=>"iTunes Store", :description=>"åé¡ãªã: iTunes Store", :status=>"allgood"}, # ... ]}
ã³ãã³ãçµç±ã§ãå®è¡ã§ãã¾ã
$ apple_system_status fetch --country=jp --title="iTunes Store" 00:47 JST æç¹ã®ã·ã¹ãã ç¶æ³ iTunes Store,allgood,åé¡ãªã: iTunes Store
jsonåºåããµãã¼ããã¦ããã®ã§ jq ã¨çµã¿åãããã°ãããããã¨ãã§ãã¾ããç£è¦ãæãã¾ãNEï¼
$ apple_system_status fetch --country=jp --format=json --title="iTunes Store" | jq . { "title": "00:51 JST æç¹ã®ã·ã¹ãã ç¶æ³", "services": [ { "title": "iTunes Store", "description": "åé¡ãªã: iTunes Store", "status": "allgood" } ] } $ apple_system_status fetch --country=jp --format=json --title="iTunes Store" | jq .services[0].status "allgood"
ä»ã«ã
phantomjsã¤ã³ã¹ãã¼ã«ããã®('A`)ï¾ï¾ï¾ï¾ï½¸ï½¾ã¨ãã人ã«ã¯APIãµã¼ããããã¾ãã
https://app-stat-api.herokuapp.com/
Sinatraã§Web APIãä½ã£ã¦ãã®ä¸ã§ãã®gemãå¼ãã§ããã ãã§ã
使ãæ¹ããã£ãã¨ã ãããåã
$ curl -s https://app-stat-api.herokuapp.com/jp/services.json?title=iTunes+Store | jq .services[0].status "allgood"
æ¯åã¹ã¯ã¬ã¤ãã³ã°ããã¨éããªãã®ã§ã¹ã¯ã¬ã¤ãã³ã°ã®çµæã¯5åéãã£ãã·ã¥ãã¦ãã¾ãã
ãã£ãã·ã¥ã使ã£ã¦ã»ãããªãã¨ãHerokuã®ã¤ã³ã¹ã¿ã³ã¹ãèµ·åããæã®ãªã¼ãã¼ããããæ°ã«ãªãæ¹ã¯gemã®æ¹ã使ã£ã¦ãã ããã
ä½è«
趣å³ã§çµæ§ã¹ã¯ã¬ã¤ãã³ã°ãã¦ãã®ã§ãããphantomjs + capybara + poltergeist ã®çµã¿åãããèªåã®ä¸ã§éæ¿ã«ãªãã¤ã¤ããã¾ã
- phantomjs : ãããã¬ã¹ãã©ã¦ã¶*2ã®å®çªãwebkitå èµãã¦ãã®ã§jsãåãã®ããã
- capybara : webã¢ããªã®ã·ã¹ãã ãã¹ãã«ä½¿ããããã¨ãå¤ããã©ã¹ã¯ã¬ã¤ãã³ã°ã§ãéå®ï½
- poltergeist : capybaraã§poltergeist使ãæã®ãã©ã¤ã
æ㯠mechanize ã使ã£ã¦ããã§ããjsãå®è¡ã§ããªãã®ã§bodyã«å«ã¾ããªãè¦ç´ ãåå¾ã§ããªãã¨ãããã¡ãªããããï¼ãã®å軽éãªãã§ããï¼