-
Notifications
You must be signed in to change notification settings - Fork 3
/
coxusage.py
50 lines (41 loc) · 1.6 KB
/
coxusage.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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import json
import datetime
import calendar
import os
import time
now = datetime.datetime.now()
cox_user = os.getenv('COX_USER')
cox_pass = os.environ.get('COX_PASSWORD')
json_filename = os.getenv('JSON_FILENAME').strip()
json_file = f"/data/{json_filename}"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1420,1080')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
print("[+] Starting Chrome")
driver = webdriver.Chrome(options=chrome_options)
print("[+] Getting Login page")
driver.get('https://www.cox.com/content/dam/cox/okta/signin.html')
print("[+] Waiting for fields to load")
username = WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.ID, 'okta-signin-username')))
password = driver.find_element_by_id("okta-signin-password")
username.send_keys(cox_user)
password.send_keys(cox_pass)
print("[+] Submitting Login")
driver.find_element_by_id("okta-signin-submit").click()
print("[+] Waiting for login to complete")
time.sleep(5)
print("[+] Loading Usage")
driver.get('https://www.cox.com/internet/mydatausage.cox')
time.sleep(5)
print("[+] Extracting Json")
data = driver.execute_script("return utag_data;")
data["currentMonthDays"] = calendar.monthrange(now.year, now.month)[1]
print("[+] Saving File")
with open(json_file, 'w+') as outfile:
json.dump(data, outfile, sort_keys=True)