2022-11-22 02:07:36 -05:00
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
from tabulate import tabulate
|
|
|
|
import csv
|
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
|
|
|
|
# Replace with curl
|
|
|
|
# f = open("utils/.tmp_html","r")
|
|
|
|
def get_session():
|
2023-10-30 03:40:43 -04:00
|
|
|
login_data = {'username':"infidel","password":"roadsidepicnic", 'rememberMe':False}
|
|
|
|
headers = {'Content-type': 'application/json'}
|
2022-11-22 02:07:36 -05:00
|
|
|
inf_s = requests.Session()
|
2023-10-30 03:40:43 -04:00
|
|
|
response = inf_s.post('http://10.30.1.106:5000/login', json=login_data)
|
|
|
|
#inf_s = response.cookies
|
|
|
|
print("-"*20)
|
|
|
|
print("Session")
|
|
|
|
print(inf_s)
|
|
|
|
print(response.status_code)
|
|
|
|
print("-"*20)
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
return inf_s
|
|
|
|
|
|
|
|
def get_logs():
|
|
|
|
inf_s = get_session()
|
2023-10-30 03:40:43 -04:00
|
|
|
# curl --location --request POST 'http://10.30.1.106:5000/login' \
|
2022-11-22 02:07:36 -05:00
|
|
|
|
2023-10-30 03:40:43 -04:00
|
|
|
html_data = inf_s.get('http://10.30.1.106:5000/status')
|
2022-11-22 02:07:36 -05:00
|
|
|
|
2023-10-30 03:40:43 -04:00
|
|
|
#print(html_data.text)
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
html_data = BeautifulSoup(html_data.text, "lxml")
|
|
|
|
|
2023-10-30 03:40:43 -04:00
|
|
|
#print(html_data)
|
|
|
|
#print(html_data.body.prettify())
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
table = html_data.find_all('table')[0]
|
|
|
|
|
|
|
|
# print(table)
|
|
|
|
raw_data = []
|
|
|
|
|
|
|
|
for row in table.find_all('tr'):
|
|
|
|
tmp_data = []
|
|
|
|
|
|
|
|
for row_data in row.find_all('td'):
|
|
|
|
|
|
|
|
tmp_data.append(row_data)
|
|
|
|
|
|
|
|
# print(row_data.text)
|
|
|
|
|
|
|
|
# if not row_data.text:
|
|
|
|
# print("-")
|
|
|
|
# if row_data.has_attr('title'):
|
|
|
|
# print(row_data['title'])
|
|
|
|
# # print("Got title for you")
|
|
|
|
raw_data.append(tmp_data)
|
|
|
|
# print(tmp_data)
|
|
|
|
|
|
|
|
prod_data = []
|
|
|
|
for proc_data in raw_data:
|
|
|
|
|
|
|
|
if ( len(proc_data) > 0 ):
|
|
|
|
i = 1
|
|
|
|
tmp_data = []
|
|
|
|
|
|
|
|
# if not "DTS" in str(proc_data[0]):
|
|
|
|
# # print("String ", proc_data[0])
|
|
|
|
# continue
|
|
|
|
|
|
|
|
for proc_val in proc_data:
|
|
|
|
|
|
|
|
data = BeautifulSoup(str(proc_val), "lxml")
|
|
|
|
data = data.find('td')
|
|
|
|
|
|
|
|
if data.has_attr('title'):
|
|
|
|
# Handle ugly byte notation
|
|
|
|
data = str(data['title'])
|
|
|
|
data = data[:-6]
|
|
|
|
data = int(data)
|
|
|
|
|
|
|
|
elif len(data.text) < 1:
|
|
|
|
data = "-"
|
|
|
|
|
2023-10-30 03:40:43 -04:00
|
|
|
elif i == 5:
|
2022-11-22 02:07:36 -05:00
|
|
|
data = str(data.text)
|
2023-10-30 03:40:43 -04:00
|
|
|
print(data)
|
|
|
|
data = data[:5]+"***"+data[-5:]
|
|
|
|
#data = data+"***"
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
elif i == 7:
|
|
|
|
data = str(data.text)
|
|
|
|
if len(data) > 29:
|
|
|
|
data = data[:-20]
|
|
|
|
else:
|
|
|
|
data = data[:-10]
|
|
|
|
else:
|
|
|
|
data = data.text
|
|
|
|
|
|
|
|
my_data = data
|
|
|
|
# print(i,"->",my_data)
|
|
|
|
tmp_data.append(my_data)
|
|
|
|
|
|
|
|
i=i+1
|
|
|
|
# print("*"*100)
|
|
|
|
prod_data.append(tmp_data)
|
|
|
|
|
|
|
|
# print(prod_data)
|
|
|
|
|
|
|
|
# print(json.dumps(prod_data))
|
|
|
|
|
|
|
|
# with open("mon_data.csv", "w") as f:
|
|
|
|
#
|
|
|
|
# write = csv.writer(f)
|
|
|
|
#
|
|
|
|
# write.writerows(prod_data)
|
|
|
|
#
|
|
|
|
# with open("mon_data.json", "w") as f:
|
|
|
|
#
|
|
|
|
# json.dump(prod_data, f)
|
|
|
|
|
|
|
|
# print(">>"*100)
|
|
|
|
# print(prod_data)
|
|
|
|
# print(">>"*100)
|
|
|
|
|
|
|
|
final_data = []
|
2023-10-30 03:40:43 -04:00
|
|
|
#list_display = ['wgName', 'wgMail', 'wgKey', 'wgDin', 'wgDout', 'wgStatus', 'wgTStamp']
|
|
|
|
list_display = ['wgName', 'wgMail', 'wgAIP', 'wgEP', 'wgKey', 'wgDin', 'wgDout', 'wgStatus', 'wgTStamp']
|
2022-11-22 02:07:36 -05:00
|
|
|
j=1
|
|
|
|
for v in prod_data:
|
|
|
|
|
|
|
|
fucker_dict={}
|
|
|
|
i=0
|
|
|
|
|
|
|
|
for x in v:
|
2023-10-30 03:40:43 -04:00
|
|
|
#print(x)
|
2022-11-22 02:07:36 -05:00
|
|
|
fucker_dict[list_display[i]]=x
|
|
|
|
i=i+1
|
|
|
|
fucker_dict["data_id"]=j
|
|
|
|
j=j+1
|
|
|
|
final_data.append(fucker_dict)
|
2023-10-30 03:40:43 -04:00
|
|
|
|
|
|
|
#sorted_footballers_by_goals = sorted(footballers_goals.items(), key=lambda x:x[1])
|
|
|
|
final_data = sorted(final_data, key=lambda x: (x['wgStatus'], x['wgTStamp']), reverse=True)
|
|
|
|
#final_data = sorted(final_data.items(), key=labda x:x[1])
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
# r = requests.post("http://127.0.0.1:8000/api/wgAPI/?format=api", json=final_data)
|
2023-10-30 03:40:43 -04:00
|
|
|
# final_data = json.dumps(final_data)
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
return final_data
|
|
|
|
|
|
|
|
def get_profiles():
|
|
|
|
|
|
|
|
inf_s = get_session()
|
2023-10-30 03:40:43 -04:00
|
|
|
html_data = inf_s.get('http://10.30.1.106:5000/api/clients?')
|
2022-11-22 02:07:36 -05:00
|
|
|
|
|
|
|
html_data = html_data.json()
|
|
|
|
# html_data = json.loads(html_data)
|
|
|
|
|
|
|
|
list_display = ['wgName', 'wgMail', 'wgKey', 'wgDin', 'wgDout', 'wgStatus', 'wgTStamp']
|
|
|
|
final_data = []
|
|
|
|
i = 1
|
|
|
|
|
|
|
|
for x in html_data:
|
|
|
|
current_data = x["Client"]
|
|
|
|
current_data["data_id"]=i
|
|
|
|
final_data.append(current_data)
|
|
|
|
i = i + 1
|
2022-11-24 05:11:55 -05:00
|
|
|
|
2023-10-30 03:40:43 -04:00
|
|
|
# final_data = json.dumps(final_data)
|
2022-11-22 02:07:36 -05:00
|
|
|
# print(final_data)
|
|
|
|
|
2023-10-30 03:40:43 -04:00
|
|
|
final_data = sorted(final_data, key=lambda x: (x['enabled'], x['created_at']), reverse=True)
|
|
|
|
|
2022-11-22 02:07:36 -05:00
|
|
|
return final_data
|
|
|
|
|
|
|
|
# get_profiles()
|
|
|
|
|