diff --git a/clear_data.sh b/clear_data.sh index 64d0f69..3708786 100644 --- a/clear_data.sh +++ b/clear_data.sh @@ -101,4 +101,24 @@ adb -s G7AZCY07H415CT3 shell am start -n com.android.chrome/com.google.android.a #asus oneplus 8 T adb -s 07fbd156 shell pm clear com.android.chrome adb -s 07fbd156 shell am set-debug-app --persistent com.android.chrome -adb -s 07fbd156 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main \ No newline at end of file +adb -s 07fbd156 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#xiao mi +adb -s 192.168.56.107:5555 shell pm clear com.android.chrome +adb -s 192.168.56.107:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.56.107:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#xiao mi +adb -s 192.168.56.105:5555 shell pm clear com.android.chrome +adb -s 192.168.56.105:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.56.105:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#xiao mi +adb -s 192.168.56.109:5555 shell pm clear com.android.chrome +adb -s 192.168.56.109:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.56.109:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main + +#xiao mi +adb -s 192.168.56.110:5555 shell pm clear com.android.chrome +adb -s 192.168.56.110:5555 shell am set-debug-app --persistent com.android.chrome +adb -s 192.168.56.110:5555 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main diff --git a/src/appointment.js b/src/appointment.js index 078ac6b..2744fb7 100644 --- a/src/appointment.js +++ b/src/appointment.js @@ -21,6 +21,52 @@ async function filterAlreadyBookedContacts(contactList) { return contactsToBook; } +async function filterAlreadyAccepteddContacts(contactList) { + let alreadyBookedContacts = await mongoManager.getAllAcceptedAppointments(); + let contactsToBook = []; + contactList.forEach((contact) => { + let needToBook = true; + alreadyBookedContacts.forEach((acceptedItem) => { + if (acceptedItem.email === contact.mail) { + console.log("=====handle already accepted item before booking===="); + console.log("accepted_at is " + acceptedItem.accepted_at); + console.log("accepted email is " + acceptedItem.email); + needToBook = acceptedItem.accepted_at + THIRTY_DAYS_IN_S <= (new Date()) / 1000; + if (!needToBook) { + console.log("already accepted appointment --> skip"); + } + } + }) + if (needToBook) { + contactsToBook.push(contact) + } + }) + return contactsToBook; +} + +async function filterBlacklistedContacts(contactList) { + let blackListedContacts = await mongoManager.getAllBlackedListItems(); + let contactsToBook = []; + contactList.forEach((contact) => { + let needToBook = true; + blackListedContacts.forEach((blackListItem) => { + if (blackListItem.mail === contact.mail) { + console.log("=====handle blacklist item before booking====="); + console.log("update_at_s is " + blackListItem.update_at_in_s) + console.log("black list email is " + blackListItem.mail) + needToBook = blackListItem.update_at_in_s + SEVEN_DAYS_IN_S <= (new Date()) / 1000; + if (!needToBook) { + console.log("contact in blacklist -->skip"); + } + } + }) + if (needToBook) { + contactsToBook.push(contact) + } + }) + return contactsToBook; +} + async function needToBook(contact, mongoManager) { console.log("check contact with email " + contact.mail) let alreadyBooked = await mongoManager.getAllSuccessfulItemsForDay(collectionName); @@ -99,21 +145,27 @@ async function startBookWithNumbers(startNumber, endNumber, selectedStore, pathT return } mongoManager.connect().then(r => { - filterAlreadyBookedContacts(contactList).then(listToBook => { - console.log("number of contacts to book:" + listToBook.length) - android.devices().then((devices) => { - if (devices.length === 0) { - alert("未找到连接的设备"); - return + filterAlreadyBookedContacts(contactList).then((listToBook)=>{ + filterAlreadyAccepteddContacts(listToBook).then(notAcceptedContacts => { + filterBlacklistedContacts(notAcceptedContacts).then(listWithoutBlackContact => { + console.log("number of contacts to book:" + listWithoutBlackContact.length) + android.devices().then((devices) => { + if (devices.length === 0) { + alert("未找到连接的设备"); + return + } + let segmentNumber = listWithoutBlackContact.length / devices.length; + console.log("connected device number:" + devices.length) + console.log("segmentNumber:" + segmentNumber) + for (let i = 0; i < devices.length; i++) { + startWithList(listWithoutBlackContact.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); + } + }) + }) } - let segmentNumber = listToBook.length / devices.length; - for (let i = 0; i < devices.length; i++) { - startWithList(listToBook.slice(i * segmentNumber, segmentNumber * (i + 1)), devices[i], selectedStore, audioAnalyse, alertBeep); - } - }) + ) }) - } - ) + }); } module.exports = startBookWithNumbers \ No newline at end of file