Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Created January 27, 2021 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackknight36/58406f27ee153a2343fc94d9f892d3fd to your computer and use it in GitHub Desktop.
Save blackknight36/58406f27ee153a2343fc94d9f892d3fd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2.7
import datetime, gnupg, pytz, time
from selenium import webdriver
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
#from selenium.webdriver.common.action_chains import ActionChains
#from selenium.webdriver.common.by import By
#from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.support import expected_conditions as EC
gpg = gnupg.GPG(gnupghome='/home/00/d861703/.gnupg', use_agent=True)
username = 'michael.watters@dart.biz'
# This file can be generated with gpg as follows:
# echo 'password' | gpg -r first.last@example.com --encrypt --armor > sap_login.asc
with open('/home/00/d861703/Nextcloud/projects/scripts/sap_login.asc', 'r') as file:
encrypted_ascii_data = file.read()
password = gpg.decrypt(encrypted_ascii_data)
opts = Options()
#opts.set_headless()
#assert opts.headless # Operating in headless mode
timezone = pytz.timezone("America/Detroit")
# SAP time periods start on Sunday
today = datetime.datetime.today()
# Get day of week as an integer
dow = datetime.date.isoweekday(today)
# Create a datetime object representing Sunday
sunday = datetime.datetime.fromordinal((today.toordinal() - dow))
s_aware = timezone.localize(sunday)
ds = s_aware.strftime("%a %b %d %Y %T GMT%z (%Z)")
sap_url = 'https://sapweb.dartcontainer.com/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html?sap-ushell-config=standalone#ZHCM-TimeConf&/week/%s' %ds
#sap_url = 'https://sapweb.dartcontainer.com/sap/opu/odata/sap/ZHCM_TIME_CONFIRM2_SRV/ConfirmTime(I_StartDate="%s")?sap-client=200"' %sunday
#sap_url = 'https://sapweb.dartcontainer.com/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html?sap-ushell-config=standalone#ZHCM-TimeConf&/week/Sun%20Sep%2001%202019%2000:00:00%20GMT-0400%20(EDT)'
#sap_url = 'https://sapweb.dartcontainer.com/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html?sap-ushell-config=standalone#ZHCM-TimeConf&/week/Sun%20Aug%2025%202019%2000:00:00%20GMT-0400%20(EDT)'
#sap_url = 'https://sapweb.dartcontainer.com/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html?sap-ushell-config=standalone#ZHCM-TimeConf&/noweek'
#sap_url = 'https://www.dartcentral.com'
#print(sap_url)
browser = Firefox(options=opts)
browser.get(sap_url)
browser.implicitly_wait(30)
uname = browser.find_element_by_id('userNameInput')
uname.send_keys(str(username))
passwd = browser.find_element_by_id('passwordInput')
passwd.send_keys(str(password))
browser.find_element_by_id('submitButton').click()
## wait for the login page to load
time.sleep(10)
confirm_button = browser.find_elements_by_xpath("//*[@id='__xmlview2--confirmButton']")[0]
confirm_button.click()
#browser.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment