Started the reorganization of Scripts for github. Some notes changes.

This commit is contained in:
Norm Rasmussen
2023-05-04 16:07:06 -04:00
parent 6a674ca24b
commit 18a266746b
209 changed files with 121 additions and 12181 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,71 @@
from PIL import Image
import glob
import re
import os
from datetime import date
currentdir = "/Users/normrasmussen/Documents/Work/Scripts/Walmart_Screenshots/"
def find_pictures(currentdir):
files = []
listfiles = glob.glob(currentdir + "*.png")
for file in listfiles:
files.append(os.path.basename(file))
# Now file will only show the file name, not the entire path
split_resources(files, currentdir)
def split_resources(files, currentdir):
try:
resource_title = files[0]
resource_title = resource_title[:-6]
files.sort()
new_list = []
for file in files:
if resource_title in file:
new_list.append(file)
for item in new_list:
files.remove(item)
split_resources(files, currentdir)
process_pictures(new_list, resource_title, currentdir)
except IndexError as e:
print(e)
finally:
pass
def process_pictures(new_list, resource_title, currentdir):
resource_title = re.sub(r'[?]', "", resource_title)
today = date.today()
today = today.strftime("%m.%d.%Y")
image_list = []
resource = Image.open(new_list[0])
resource = resource.convert("RGB")
for picture in new_list[1:]:
image = Image.open(picture)
converted = image.convert("RGB")
image_list.append(converted)
# image_list.append(image)
resource.save(
currentdir + f"PDFs/{resource_title}_{today}.pdf",
save_all=True,
append_images=image_list,
)
def delete_originals(currentdir):
path = glob.glob(currentdir + "*.png")
for file in path:
try:
os.remove(file)
except TypeError as e:
print("Error!")
print(e)
finally:
print("All Done")
if __name__ == "__main__":
find_pictures(currentdir)
delete_originals(currentdir)

View File

@ -0,0 +1,94 @@
const puppeteer = require('puppeteer');
const path = require('path')
/*
for (let i=0; i<urls.length; i++){
const url = urls[i];
await page.goto('${url}');
await page.waitForNavigation({ waitUntil: 'networkkidle2' });
}
const url = [
"https://walmart.northpass.com/app/courses/90bbdf4d-c674-403c-93d1-1c2e43364e0e", // Tax Filling FAQs
"https://walmart.northpass.com/app/courses/6b74d176-6027-40f5-af0c-fdee6d4f53bf", // Tips for Claiming your Branch Wallet
"https://walmart.northpass.com/app/courses/5624342f-9927-4704-bc6b-5c84068c0564", // Branch Wallet FAQs
"https://walmart.northpass.com/app/courses/65a83b52-08e9-48ac-b953-59dfa22f7358", // Pointers on Viewing your Earnings
"https://walmart.northpass.com/app/courses/0cd301a1-d98e-4837-ae9a-6fbd6a152aa3", // Curious how trip earnings works?
"https://walmart.northpass.com/app/courses/71a2064f-600d-415b-9b93-0a695793a09b", // Having Issues Confirming your arrival?
"https://walmart.northpass.com/app/courses/f9fea960-9fb3-4d05-858a-ea9a5657e20a", // Not Receiving App Notifications?
"https://walmart.northpass.com/app/courses/dce79912-ffe2-4648-a258-d725dbea6dc4", // Pointers on vehicle details
"https://walmart.northpass.com/app/courses/59a21c93-36ed-4e25-a723-6c8b3e6a80f0", // Pointers on Creating Your Account
"https://walmart.northpass.com/app/courses/17224d43-5acc-4dfb-805b-53f85cafb633", // Pointers on Downloading the App
"https://walmart.northpass.com/app/courses/bb1449eb-9b8d-48b2-9e05-1261171bd0e7", // Reviewing your trips
"https://walmart.northpass.com/app/courses/b30329fa-825f-4447-85f2-6caeea998ec6", // Pointers on Sharing Your Location
"https://walmart.northpass.com/app/courses/6c94e20c-aff7-465a-baaf-c32804fa7c9c", // Turning off Spark Now
"https://walmart.northpass.com/app/courses/2e616785-7ec7-40f0-a6a7-069f3c8c4c02", // Updating Spark Driver App
"https://walmart.northpass.com/app/courses/f3be53c0-cd21-4a2d-97f0-8b84ba030f4a", // Questions about Earnings
"https://walmart.northpass.com/app/courses/e889b1de-6305-424c-b0cd-47e36e798fa3", // Damaged Order or Item
"https://walmart.northpass.com/app/courses/8e20a3e6-37ef-4538-9047-4bcce5666d59", // Error messages & Alerts
]
*/
const apiKey = "6hUfJdAartHTHhHc0WIRZYPWe"
const url = process.argv[2];
if (!url) {
throw "Please provide a URL as the first argument";
}
const uid = "/\?uid\=7b84eae4-fb34-4689-9f33-24071c3e5a41";
const activity = new Array();
const activityLinks = new Array();
var num = 1
/*
function loopUrls() {
for (item of url){
console.log(item)
courseOverview()
}
}*/
async function courseOverview() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const course = url+uid;
await page.setViewport({ width:390, height:844 })
await page.goto(course);
await page.title();
const [getXpath] = await page.$x('/html/body/div[2]/div/div');
// const [getXpath] = await page.$x('//*[@id="course-desktop"]/div/div[3]/div[2]/div[2]/div[2]/ol/li/div');
const resourcetitle = await page.evaluate(name => name.innerText, getXpath);
const resource = resourcetitle.trim();
console.log(resource);
await page.screenshot({path: `${resource}_1.png`, fullPage:true, headless:false});
const hrefs = await page.$$eval('a', as => as.map(a => a.href));
var links = Object.entries(hrefs);
links.forEach(([key, value]) => {
var link = value;
if (link.includes("activities")) {
activity.push(link);
}
});
uniqueLinks = [...new Set(activity)];
for (const link of uniqueLinks) {
num = num+1
const newlink = link+uid;
// console.log(newlink)
screenshots(newlink, resource, num);
}
await browser.close();
}
async function screenshots(newlink, resource, num) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 390, height: 844 })
await page.goto(newlink);
await page.screenshot({path: `${resource}_${num}.png`, fullPage: true, headless: false});
await browser.close();
}
courseOverview();

View File

@ -0,0 +1,122 @@
const puppeteer = require('puppeteer');
const axios = require('axios')
const path = require('path')
const apiKey = "6hUfJdAartHTHhHc0WIRZYPWe"
// Spark Production ^
// const apiKey = "p5fidpuedHaOlPnd8EcpxzQMG"
// Luminate Production ^
const uid = "/\?uid\=7beg87y4-fh24-4929-3rt5-24kdn87s5241";
const groupIds = []
const getAllGroups = async (num) => {
if(num === 1){
}
let page = num;
await axios({
method: 'get',
url: 'https://api2.northpass.com/v2/courses?page=${page}&limit=200',
headers: {
'accept': '*/*',
'x-api-key': apiKey,
'content-type': 'application/json'
}
})
.then(async (res) => {
if (res.data.links.next != null) {
page++;
for (let i = 0; i < res.data.data.length; i++) {
if (res.data.data[i].attributes.status == "live") {
console.log(res.data.data[i].attributes.name)
groupIds.push(res.data.data[i].id)
}
}
//await getAllGroups(page);
} else {
// for (let i = 0; i < res.data.data.length; i++) {
// if (res.data.data[i].attributes.status == "live") {
// console.log(res.data.data[i].attributes.name)
// groupIds.push(res.data.data[i].id)
// }
// }
}
})
.catch(err => {
console.log(err);
})
let i = 0
loopIds(i)
console.log(groupIds)
}
function loopIds(i) {
console.log("Loop Ids Function")
var num = 1
id = groupIds[i]
courseOverview(id, i, num)
}
async function courseOverview(id, i, num) {
console.log("Course Overview Function")
const activity = new Array();
const url = "https://walmart.northpass.com/app/courses/";
const browser = await puppeteer.launch();
const page = await browser.newPage();
const course = url+id+uid;
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, {
waitUntil: 'load',
timeout: 0 });
await page.title();
const [getXpath] = await page.$x('/html/body/div[1]/div');
const resourcetitle = await page.evaluate(name => name.innerText, getXpath);
console.log(resourcetitle)
const resource = resourcetitle.trim();
console.log(resource);
await page.screenshot({path: `${resource}_1.png`, fullPage:true, headless:false});
const hrefs = await page.$$eval('a', as => as.map(a => a.href));
var links = Object.entries(hrefs);
links.forEach(([key, value]) => {
var link = value;
if (link.includes("activities") && (link.includes(id))) {
console.log(link);
activity.push(link);
}
});
setTimeout(() => {
}, 5000);
uniqueLinks = [...new Set(activity)];
for (const link of uniqueLinks) {
num = num+1
const newlink = link+uid;
await page.setViewport({ width: 390, height: 844 })
await page.goto(newlink, {
waitUntil: 'load',
timeout: 0 });
await page.screenshot({path: `${resource}_${num}.png`, fullPage: true, headless: false});
//screenshots(newlink, resource, num, i);
}
await browser.close();
i++;
loopIds(i);
}
}
async function screenshots(newlink, resource, num, i) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await browser.close();
}
getAllGroups();

View File

@ -0,0 +1,15 @@
#! /bin/zsh
jscript=$(node resources_api.js)
render_pdf=$(python3 combine_to_pdf.py)
echo "Loading virtual environment for Python"
. ${PYENV_ROOT}/versions/walmart/bin/activate | awk 'NR==1{print $1,$2,$3}'
echo "First up, Javascript's Pupeteer."
echo "$jscript"
echo "JS Complete. Running Python Script to clean up PDFs."
echo "$render_pdf"
echo "PDFs complete. Shutting down Virtual env."