Last active
April 4, 2023 02:09
-
-
Save bi119aTe5hXk/b5fd6180aa0390bc40d7c3d41e97d7c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get AI count from ATOM Cam AI Service API. | |
**/ | |
function GetAICount() { | |
/* 設定 */ | |
const instance_id = "1234" //自分のサービスIDに変更してください | |
//営業時間帯。指定した時間帯のみ記録します。 | |
const openTime = "9:00";//開店時間 | |
const closeTime = "18:00";//閉店時間 | |
const restDay = [0,6];//定休日:0=日,1=月,2=火,3=水,4=木,5=金,6=土、デフォルト:土日 | |
/* 以下の内容は変更しないてください */ | |
const now = new Date(); | |
var open = Utilities.parseDate(openTime, "JST", "HH:mm"); | |
var close = Utilities.parseDate(closeTime, "JST", "HH:mm"); | |
var hasRest = 0; | |
restDay.forEach(function(day){ | |
if(day === now.getDay()){ | |
console.log("定休日のため記録なし"); | |
hasRest = 1; | |
} | |
}); | |
if(hasRest === 1){ | |
return; | |
} | |
let inTimeRange = checkTime(now.getHours(),now.getMinutes(),open.getHours(),open.getMinutes(),close.getHours(),close.getMinutes); | |
if(!inTimeRange){ | |
console.log("営業時間外のため記録なし") | |
return; | |
} | |
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
const formatNow = Utilities.formatDate(now, 'GMT', 'dd MMM yyyy HH:mm:ss z'); | |
const unixTime = Date.parse(formatNow)/1000; | |
const sc = Utilities.newBlob(Utilities.base64Decode("YzA4NDJhYmVjNTRkNDNhYWI4ODc0NjNhMWY0NTNiZWM=", Utilities.Charset.UTF_8)).getDataAsString(); | |
const sv = Utilities.newBlob(Utilities.base64Decode("Y2RlZWZlZWY5ZjVlNGQwYzk2MDBkM2JkYzQ0ZmU0OGQ=", Utilities.Charset.UTF_8)).getDataAsString(); | |
payload = '{"app_ver":"com.atom.web___1.0.0","sc":"'+sc+'","sv":"'+sv+'","ts":'+ unixTime +',"phone_id":"Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36","instance_id":"'+ instance_id +'"}' | |
var options = { | |
'method' : 'post', | |
'contentType': 'application/json', | |
'payload' : payload | |
}; | |
var url = 'https://beta-api.atomtech.co.jp/app/v1/service/aps/live_url/refresh'; | |
var res = UrlFetchApp.fetch(url,options).getContentText(); | |
console.log(res); | |
var json = JSON.parse(res); | |
var data = json["data"]; | |
const formatAPITime = Utilities.formatDate(new Date(json["ts"]), 'JST', 'yyyy/MM/dd HH:mm:ss'); | |
var level; | |
switch (data["current_level"]){ | |
case 1: | |
level="🟢"; | |
break; | |
case 2: | |
level="🟡"; | |
break; | |
case 3: | |
level="🟥"; | |
break; | |
default: | |
level="不明"; | |
} | |
var titleRowText = ["日付","人数","混雑状況"]; | |
var newDataRowText = [formatAPITime,data["current_person"],level]; | |
sheet.getRange(1,1,1,3).setValues([titleRowText]); | |
sheet.appendRow(newDataRowText); | |
} | |
// check if h:m is in the range of a:b-c:d | |
// does not support over-night checking like 23:00-1:00am | |
function checkTime(h,m,a,b,c,d){ | |
if (a > c || ((a == c) && (b > d))) { | |
console.log("not a valid input") | |
} else { | |
if (h > a && h < c) { | |
return true; | |
} else if (h == a && m >= b) { | |
return true; | |
} else if (h == c && m <= d) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment