-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (31 loc) · 1.19 KB
/
main.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
import os
import logging
import requests
from dotenv import load_dotenv
load_dotenv()
project_path = os.environ['project_path']
logging.basicConfig(filename=project_path+os.path.sep+"log"+os.path.sep+'run.log',filemode='a', format = '%(name)s - %(asctime)s - %(message)s', level= logging.INFO)
url = "http://10.254.254.71/0/up/"
logged_in_str = "Your Internet connection is configured properly."
login_params = {'login': 'Login', 'user':os.environ.get('internet_uname'), "pass":os.environ.get('internet_passwd') }
logout_params = {'logout': 'Click here to logout'}
def check_logged_in():
r = requests.get(url)
return r.status_code==200 and logged_in_str in r.text
def logout():
r = requests.post(url, data = logout_params)
assert r.status_code==200 and check_logged_in() is False
def login():
r = requests.post(url, data = login_params)
assert r.status_code==200 and check_logged_in() is True
if __name__=="__main__":
# logout()
if not check_logged_in():
logging.info("logging in ..")
login()
if not check_logged_in():
logging.error(" Login Failed!")
else:
logging.info("Logging Success!")
else:
logging.info("Already logged in.")