-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.gs
89 lines (69 loc) · 2.13 KB
/
app.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const bienSoXeList = [
{
bienso: '77F123456', // Biển số xe của bạn
},
]
function sendMessageToTelegram(message, botToken = '<YOUR_BOT_TOKEN>') {
var chatId = '<YOUR_CHAT_ID>';
var url = 'https://api.telegram.org/bot' + botToken + '/sendMessage';
var payload = {
chat_id: chatId,
text: message,
parse_mode: "Markdown"
};
var options = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload)
};
UrlFetchApp.fetch(url, options);
}
function createMessage(violation) {
return violation.map(item => Object.keys(item).map(key => `*${key.replace(/([_*[\]()~`>#+-=|{}.!])/g, '\\$1')}*: ${Array.isArray(item[key]) ? item[key].join('\n') : item[key]}`).join('\n')).join('\n\n');
}
function fetchData(bienSoXe) {
var url = 'https://api.checkphatnguoi.vn/phatnguoi'
var payload = Object.keys(bienSoXe).map(function(key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(bienSoXe[key]);
}).join('&');
var options = {
'method': 'post',
'contentType': 'application/x-www-form-urlencoded',
'payload': payload
};
try {
var response = UrlFetchApp.fetch(url, options);
const data = JSON.parse(response).data;
if (data) {
sendMessageToTelegram(createMessage(data))
}
} catch (error) {
sendMessageToTelegram(`BSX ${bienSoXe.bienso}: ${error.message}`);
}
}
function run() {
bienSoXeList.forEach(fetchData);
}
function fetchDataWeekly(bienSoXe) {
var url = 'https://api.checkphatnguoi.vn/phatnguoi'
var payload = Object.keys(bienSoXe).map(function(key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(bienSoXe[key]);
}).join('&');
var options = {
'method': 'post',
'contentType': 'application/x-www-form-urlencoded',
'payload': payload
};
try {
var response = UrlFetchApp.fetch(url, options);
const data = JSON.parse(response).data;
if (data) {
sendMessageToTelegram(JSON.stringify(data))
}
} catch (error) {
sendMessageToTelegram(`BSX ${bienSoXe.bienso}: ${error.message}`);
}
}
function runWeekly() {
bienSoXeList.forEach(fetchDataWeekly);
}