Fixed UX Design's Script, added some directory changes for Walmart. Notes for Anthology

This commit is contained in:
Norm Rasmussen
2023-02-23 15:34:42 -05:00
parent 60e2ecda09
commit 707af4f01f
7 changed files with 119 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,77 @@
import requests
import subprocess
import gzip
import urllib.request
import base64
# Variables of the needed elements
extract_id = "506c7250-2365-456d-be91-b1e146a398fe"
auth_token = "g5k8QpUlePaL5UFSz9Kob4nbYHIyEH0W2lhtbrDu"
base_url = "https://analytics.northpass.io/extracts"
encryption_key = "ba6iy6jPmTxlIs73f+7FcXC8FDXt98mW46WbmKpLPsY="
current_dir = "./"
# Set the API endpoint, authentication headers, and other parameters
headers = {
"accept": "application/json",
"X-Api-Key": "g5k8QpUlePaL5UFSz9Kob4nbYHIyEH0W2lhtbrDu",
}
# This first call provides you with the fileID and IV value to download the encrypted file
def get_extract_id(base_url, headers, extract_id, encryption_key):
url = f"{base_url}/{extract_id}/files/latest/"
response = requests.get(url, headers=headers)
data = response.json()
file_id = data["fileId"]
iv = data["initializationVector"]
download_file(base_url, headers, extract_id, file_id, encryption_key, iv)
# This function downloads the file, changes the IV and EK from base64 to Hex, and then decrypts it.
# It then opens and prints the results for verification that the data is human readable.
def download_file(base_url, headers, extract_id, file_id, encryption_key, iv):
url = f"{base_url}/{extract_id}/files/{file_id}/download"
response = requests.get(url, headers=headers)
data = response.json()
download_url = data["url"]
# Downloads the file to the cwd
url_resp = urllib.request.urlretrieve(download_url, "UXDesign_API_Extract.csv.gz")
file_name = url_resp[0]
decrypted_file = "UXDesign_Accessible.csv.gz"
# Base64 > Hex
encryption_key = base64.b64decode(encryption_key).hex()
print(encryption_key)
iv = base64.b64decode(iv).hex()
print(iv)
# Decryption Command as provided in Northpass Documentation
resp = subprocess.run(
[
"openssl",
"enc",
"-aes-256-cbc",
"-d",
"-nosalt",
"-in",
file_name,
"-out",
decrypted_file,
"-K",
encryption_key,
"-iv",
iv,
]
)
print(resp)
# Print data in CSV to ensure it is human readable
with gzip.open(decrypted_file, "rb") as uncompressed:
file = uncompressed.read()
print(file)
if __name__ == "__main__":
get_extract_id(base_url, headers, extract_id, encryption_key)

View File

@ -3,7 +3,7 @@ import glob
import os
from datetime import date
currentdir = "/Users/normrasmussen/Documents/Northpass/Scripts/Walmart_Screenshots/"
currentdir = "/Users/normrasmussen/Documents/Work/Scripts/Walmart_Screenshots/"
def find_pictures(currentdir):
@ -58,8 +58,9 @@ def delete_originals(currentdir):
for file in path:
try:
os.remove(file)
except:
except TypeError as e:
print("Error!")
print(e)
finally:
print("All Done")

View File

@ -14,7 +14,7 @@ const getAllGroups = async (num) => {
await axios({
method: 'get',
url: `https://api.northpass.com/v2/courses?page=${page}&limit=100`,
url: `https://api2.northpass.com/v2/courses?page=${page}&limit=100`,
headers: {
'accept': '*/*',
'x-api-key': apiKey,
@ -61,6 +61,7 @@ async function courseOverview(id, i, num) {
console.log(course)
if (course.includes("undefined")) {
console.log("Error - Undefined UUID. Possibly end of list. Exiting.")
await browser.close();
} else {
await page.setViewport({ width:390, height:844 })
await page.goto(course, {