64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
import json
|
|
import requests
|
|
import os
|
|
import pandas as pd
|
|
import utils.pretty as ct
|
|
import shutil
|
|
|
|
|
|
def getActiveOTP(url):
|
|
|
|
endpoint = url + f'/v1/otp/usage'
|
|
payload = {
|
|
"status" : "0"
|
|
}
|
|
|
|
headers = {"X-APIKey": os.getenv('APIKEY')}
|
|
payload = json.dumps(payload)
|
|
|
|
response = requests.post(endpoint, headers=headers, data=payload, verify=False)
|
|
result = json.loads(response.text)
|
|
otp = pd.DataFrame(result["response"]["otpusage"])
|
|
otp.to_parquet("parquet\\newest_active_OTP.parquet", index=False)
|
|
if not otp.empty:
|
|
ct.style_dataframe_dark(otp, f"newest_active_OTP.html")
|
|
|
|
|
|
|
|
def getOTPActivities(url, otpid):
|
|
|
|
endpoint = url + f'/v1/otp/activities'
|
|
payload = {
|
|
"otpid" : f"{otpid}"
|
|
}
|
|
|
|
headers = {"X-APIKey": os.getenv('APIKEY')}
|
|
payload = json.dumps(payload)
|
|
|
|
response = requests.post(endpoint, headers=headers, data=payload, verify=False)
|
|
result = json.loads(response.text)
|
|
otp = pd.DataFrame(result["response"]["otpactivities"])
|
|
otp.to_parquet("parquet/otp_activities.parquet", index=False)
|
|
if not otp.empty:
|
|
ct.style_dataframe_dark(otp, f"OTP_activities_{otpid}.html")
|
|
|
|
|
|
def compareOTPHistory():
|
|
|
|
if not os.path.exists("parquet\\old_active_OTP"):
|
|
shutil.copy2("parquet\\newest_active_OTP.parquet", "parquet\\old_active_OTP.parquet")
|
|
|
|
old_active_OTP = pd.read_parquet("parquet\\old_active_OTP.parquet")
|
|
current_active_OTP = pd.read_parquet("parquet\\newest_active_OTP.parquet")
|
|
|
|
newly_added = current_active_OTP[~current_active_OTP['otpid'].isin(old_active_OTP['otpid'])]
|
|
still_in_OTP = old_active_OTP[old_active_OTP['otpid'].isin(current_active_OTP['otpid'])]
|
|
no_longer_OTP = old_active_OTP[~old_active_OTP['otpid'].isin(current_active_OTP['otpid'])]
|
|
|
|
|
|
|
|
for _, row in newly_added.iterrows():
|
|
pid = row['otpid']
|
|
# Access other columns via row['column_name']
|
|
print(f"Processing PID: {pid} with other data: {row}")
|