Last active
September 2, 2020 04:05
-
-
Save chapagainmanoj/67cfcef22e89c43701c1663a51c84e8e 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
#!/usr/bin/python3 | |
# Required: python3, selenium-driver | |
""" | |
TODO: | |
chmod +x attandance.py | |
# add to .bashrc or .zshrc to run script as alias | |
export KHALTI_SCRIPT="$HOME/khalti-script" | |
alias -g khaltiin="$KHALTI_SCRIPT/attandance.py" | |
alias -g khaltiout="$KHALTI_SCRIPT/attandance.py" | |
# or add script path to run script directly | |
export PATH=$PATH:$KHALTI_SCRIPT | |
""" | |
""" | |
Command: | |
command khaltiin or khaltiout both run same script | |
check in or out is done based on current time is beforenoon or afternoon | |
""" | |
from datetime import datetime | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
USERNAME='XX' | |
PASSWORD='XXXX' | |
URL = 'http://janakitech.officehrm.com/Attendance/attendancerequest/Create' | |
ACTION = None | |
options = Options() | |
options.add_argument("--headless") | |
driver = webdriver.Chrome(options=options) | |
driver.get(URL) | |
field = driver.find_element_by_css_selector("input[type='text']") | |
field.send_keys(USERNAME) | |
field = driver.find_element_by_css_selector("input[type='password']") | |
field.send_keys(PASSWORD) | |
button = driver.find_elements_by_xpath("//*[contains(text(), 'Sign In')]") | |
print('Loging in ...') | |
button[0].click() | |
check_out = datetime.now().hour > 12 | |
if check_out: | |
field = driver.find_element_by_xpath("//select[@name='Direction']/option[text()='Check Out']").click() | |
ACTION = 'out' | |
print('Checking Out ...') | |
else: | |
field = driver.find_element_by_xpath("//select[@name='Direction']/option[text()='Check In']").click() | |
ACTION = 'in' | |
print('Checking In ...') | |
field = driver.find_element_by_id("Remarks") | |
field.send_keys("user {} checks {}".format(USERNAME, ACTION)) | |
button = driver.find_element_by_css_selector("input[type='submit']") | |
button.click() | |
errors = driver.find_elements_by_class_name("alert-danger"); | |
if len(errors): | |
print('Error occurred ...') | |
print(errors[0].text) | |
else: | |
print('Complete ...') | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment