Skip to content

Commit

Permalink
Cleanup and actions update
Browse files Browse the repository at this point in the history
  • Loading branch information
BRoy98 committed Mar 12, 2024
1 parent d17cb89 commit 8ccdbab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,21 @@ jobs:

- name: Build service
run: yarn build

- name: Deploy Changes
run: |
mkdir ~/.ssh
touch ~/.ssh/known_hosts
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/private_key
chmod 600 ~/.ssh/private_key
ls -al ~/.ssh/
ssh-keygen -R ${{ secrets.SSH_HOST }}
sudo chown -v $USER ~/.ssh/known_hosts
# ssh-keygen -H -t rsa ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
scp -i ~/.ssh/private_key -r ./dist ${{ secrets.USER_NAME }}@${{ secrets.SSH_HOST }}:/home/ec2-user/auto-presence
ssh -o StrictHostKeyChecking=no -i ~/.ssh/private_key ${{ secrets.USER_NAME }}@${{ secrets.SSH_HOST}} '
ls
'
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "./server";
import { WebDriver } from "selenium-webdriver";

initUserTable();
const ONE_HOUR_MS = 3600000;

const clockIn = async (delayMs) => {
let driver: WebDriver;
Expand All @@ -20,7 +21,7 @@ const clockIn = async (delayMs) => {
driver = await loadKeka();
await handleClockIn(driver);

const successMessage = `✅ Clocked in 🕘 Successfully at: ${DateTime.now().toLocaleString(
const successMessage = `✅ Clock-In 🕘 Successful at: ${DateTime.now().toLocaleString(
DateTime.DATETIME_MED
)}`;
await sendNotification({
Expand All @@ -31,7 +32,6 @@ const clockIn = async (delayMs) => {
console.log(successMessage);
console.log("====================================");
} catch (error) {
driver.close();
const errorMessage = `❌ Clock-In 🕘 failed at: ${DateTime.now().toLocaleString(
DateTime.DATETIME_MED
)}`;
Expand All @@ -44,6 +44,7 @@ const clockIn = async (delayMs) => {
console.log(errorMessage);
console.log(error);
console.log("====================================");
driver?.close();
}
};

Expand All @@ -65,7 +66,6 @@ const clockOut = async (delayMs) => {
console.log(successMessage);
console.log("====================================");
} catch (error) {
driver.close();
const errorMessage = `❌ Clock-Out 🕕 failed at: ${DateTime.now().toLocaleString(
DateTime.DATETIME_MED
)}`;
Expand All @@ -78,12 +78,13 @@ const clockOut = async (delayMs) => {
console.log(errorMessage);
console.log(error);
console.log("====================================");
driver?.close();
}
};

const run = async () => {
cron.schedule("30 09 * * 1-5", () => {
const delayMs = Math.floor(Math.random() * 1200000);
const delayMs = Math.floor(Math.random() * ONE_HOUR_MS);
const message = `🕘 Clock-in started at: ${DateTime.now().toLocaleString(
DateTime.DATETIME_MED
)}`;
Expand All @@ -97,8 +98,8 @@ const run = async () => {
console.log("====================================");
clockIn(0);
});
cron.schedule("14 21 * * 1-5", () => {
const delayMs = Math.floor(Math.random() * 1200000);
cron.schedule("30 19 * * 1-5", () => {
const delayMs = Math.floor(Math.random() * ONE_HOUR_MS);
const message = `🕕 Clock-out started at: ${DateTime.now().toLocaleString(
DateTime.DATETIME_MED
)}`;
Expand Down
6 changes: 6 additions & 0 deletions src/selenium/clock-in.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { By, WebDriver, until } from "selenium-webdriver";
import { asyncDelay } from "../utils/delay";

export const handleClockIn = async (driver: WebDriver) => {
await driver.get("https://expian.keka.com/#/me/attendance/logs");
Expand All @@ -7,9 +8,14 @@ export const handleClockIn = async (driver: WebDriver) => {
5000
);

asyncDelay(2000);

const clockInButton = driver.findElement(
By.xpath('//a[text()="Web Clock-In"]')
);
console.log("====================================");
console.log("clockInButton", clockInButton);
console.log("====================================");
await clockInButton.click();

const closeLocationPopupIdentifier = By.xpath(
Expand Down

0 comments on commit 8ccdbab

Please sign in to comment.