-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_automationMAC.py
executable file
·67 lines (50 loc) · 1.92 KB
/
report_automationMAC.py
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
#description : This script automates entering reports at the end
# of the shift from a file to a web page.
#author : Florin Badea for SiteGround
#date : 15.10.2017
#usage : python3 report_automationMAC.py or create a bash alias
# (adding shutdown -h now shuts down system too)
#requirements : download the MAC chromedriver @ https://sites.google.com/a/chromium.org/chromedriver/downloads
# copy the chromedriver binary to /usr/local/bin/
#=============================================================================
import os
import time
from selenium import webdriver
today = time.strftime("%d.%m.%Y")
reportFilePath = '/path/to/file.txt'
driver = webdriver.Chrome()
#open the page with basic HTTP authentcation (https://user@pass:reportspage.tld)
driver.get("https://$USERL$PASS@URL_HERE")
#open the forum login page
driver.get("LOGIN_URL")
#find user and pass fields on the page and store them in variables
usernameElem = driver.find_element_by_id('username')
passwordElem = driver.find_element_by_id('password')
#send the authentications to the user and pass fields
#TOD:
# GET USER
# GET PASS
#find the login button and click (login)
driver.find_element_by_name('login').click()
#go to Dimitar's report's page
driver.get("DIMITAR_PAGE")
#enter submit new thread on the forum
driver.get("HIT SUBMIT")
#find the subject and message fields in the page
subjectElem = driver.find_element_by_id("subject")
messageElem = driver.find_element_by_id("message")
#enter the subject
subjectElem.send_keys('Report - Florin B - ',today)
#open the report file
reportFile = open(reportFilePath,'r')
#iterate over each line of the report file and fill in the message body
for line in reportFile.readlines():
messageElem.send_keys(line)
#close the file
reportFile.close()
#click submit
driver.find_element_by_name('post').click()
#wait 3 seconds
time.sleep(3)
#close the browser
driver.quit()