Skip to content

Instantly share code, notes, and snippets.

@nwatab
Last active April 16, 2018 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nwatab/55fc0ed07656692bfd025d14acd85010 to your computer and use it in GitHub Desktop.
Save nwatab/55fc0ed07656692bfd025d14acd85010 to your computer and use it in GitHub Desktop.
QBHouse-mail-notification-for-no-waiting
/**
* This is a code for Google App Script to see if there is a line for QBHouse at Kojimachi.
* main(): Access to qb house kojimachi homepage and check the number of people in line.
* Replace an email with yours.
* doGet(): This function is for publishing a web service as API (only one endpoint).
*/
function main() {
var url = 'http://www.qbhouse.co.jp/search/detail.php?id=475'; // QB HOUSE Kojimachi
var text = UrlFetchApp.fetch(url).getContentText('utf-8');
var waiting = text.match(/待ち人数:\d名/)[0];
if (!waiting) {
return;
}
var queue = waiting[waiting.length - 2];
var sheet = SpreadsheetApp.getActiveSheet();
var date = new Date();
var formattedDate = Utilities.formatDate(date, "Asia/Tokyo", "yyyy-MM-dd'T'HH:mm:ss'Z'");
sheet.appendRow([date.getTime(), formattedDate, queue]);
if (queue == 0) {
GmailApp.sendEmail('replace-with-your-email@example.com', 'Go to QB Kojimachi', '');
}
}
// Above is all for email notification. Below code is for public API.
function doGet(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange(1, 3, 30);
var data = sheet.getDataRange().getValues();
Logger.log(data);
var values = []
for (var i = 0; i < data.length; i++) {
values.push({unixtimestamp: data[i][0],
tokyotime: data[i][1],
queue: data[i][2]
})
}
return createContent(e.parameter.callback , {title: 'QBハウス麹町店待ち人数データベース',
shop: {
address: '東京都千代田区麹町3-4-1麹町3丁目ビル1F',
zipcode: '102-0083',
open: '平日:10:00~20:00 (受付終了20:00),土曜:09:00~19:00 (受付終了19:00),日祝:09:00~19:00 (受付終了19:00)',
website: 'http://www.qbhouse.co.jp/search/detail.php?id=475'
},
response : values});
}
function createContent(callback , returnObject ) { // returns JSON or JSONP
if(callback) {
return ContentService.createTextOutput(callback + '(' + JSON.stringify(returnObject) + ')').setMimeType(ContentService.MimeType.JAVASCRIPT);
} else {
return ContentService.createTextOutput(JSON.stringify(returnObject)).setMimeType(ContentService.MimeType.JSON);
}
}
@nwatab
Copy link
Author

nwatab commented Apr 16, 2018

Example of dumped data to Google Spread Sheet
screen shot 2018-04-17 at 0 47 51

@nwatab
Copy link
Author

nwatab commented Apr 16, 2018

Example API on Firefox
screen shot 2018-04-17 at 0 52 55

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