Skip to content

Instantly share code, notes, and snippets.

@daichan4649
Created June 27, 2017 00:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daichan4649/99e055de82a52888dd2265e6356e2716 to your computer and use it in GitHub Desktop.
Save daichan4649/99e055de82a52888dd2265e6356e2716 to your computer and use it in GitHub Desktop.
scrape subway status
var URL_SUBWAY = "http://subway.city.fukuoka.lg.jp/status/";
var REGEXP_STATUS = /<div class=\"statusNews\">(.*)<\/div>/gi;
function doGet() {
var status = scrapeSubwayStatus();
Logger.log(status);
var json = {};
json['status'] = status;
json['url'] = URL_SUBWAY;
Logger.log(json);
return ContentService.createTextOutput(JSON.stringify(json)).setMimeType(ContentService.MimeType.JSON);
}
function scrapeSubwayStatus() {
var response = UrlFetchApp.fetch(URL_SUBWAY);
var elements = response.getContentText().match(REGEXP_STATUS);
if(elements == null || elements.length == 0) {
return "なにかが起きている";
}
// 1件目前提
var status = elements[0];
status = status.replace(/<div class=\"statusNews\">/gi, "");
status = status.replace(/<\/div>/gi, "");
return status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment