Completed the playwright walmart screenshots script. Uploaded another Chubb CSV.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
<script>
|
||||
const courseDefaultPageTitle = document.title.split(" | ")
|
||||
const courseDefaultPageTitle = document.title
|
||||
const courseName = '{{course.name}}'
|
||||
document.title = `${courseName} | ${courseDefaultPageTitle[1]}`
|
||||
const courseDescription = '{{course.short_description}}'
|
||||
@ -10,22 +10,22 @@
|
||||
<script> window.location.replace('/learners/sign_in')</script>
|
||||
{% else %}
|
||||
{% include "header" %}
|
||||
|
||||
|
||||
{% if course.ribbon == "VIDEO" %}
|
||||
{% include "video_tutorial_cover" %}
|
||||
{% else %}
|
||||
{% include "course_cover" %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% include "footer" %}
|
||||
|
||||
|
||||
{% if current_person.signed_in? == false and current_school.sso_active? %}
|
||||
<script>
|
||||
const redirectionLink = 'https://user-learn.pipedrive.com/app/courses/{{ course.properties.second_school_course_uuid }}'
|
||||
document.querySelector('#redirect-between-academies').setAttribute('href', redirectionLink)
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
|
||||
{% if current_person.signed_in? and current_school.properties.sandbox == false %}
|
||||
<script>
|
||||
function setupLatestCourses() {
|
||||
|
||||
@ -11,7 +11,7 @@ HEADERS = {
|
||||
"X-Api-Key": APIKEY,
|
||||
}
|
||||
BASEURL = "https://api.northpass.com/v2/"
|
||||
IMPORTFILE = "/Users/normrasmussen/Downloads/cisa-11425.csv"
|
||||
IMPORTFILE = "/Users/normrasmussen/Downloads/cisa-12825.csv"
|
||||
|
||||
|
||||
def bulk_invite_and_group():
|
||||
|
||||
@ -1,6 +1,17 @@
|
||||
import re
|
||||
import sys
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright, expect
|
||||
from PIL import Image
|
||||
import glob
|
||||
import re
|
||||
import os
|
||||
from datetime import date
|
||||
|
||||
|
||||
BASEURL = "https://walmart.northpass.com/app/courses/"
|
||||
USERID = "?uid=7beg87y4-fh24-4929-3rt5-24kdn87s5241"
|
||||
COURSEID = sys.argv[1]
|
||||
DIR = "./"
|
||||
|
||||
def run(playwright: Playwright):
|
||||
print("running")
|
||||
@ -10,16 +21,86 @@ def run(playwright: Playwright):
|
||||
viewport={ 'width': 390, 'height': 844 }
|
||||
)
|
||||
page = context.new_page()
|
||||
BASEURL = "https://walmart.northpass.com/app/courses/"
|
||||
USERID = "?uid=7beg87y4-fh24-4929-3rt5-24kdn87s5241"
|
||||
COURSEID = sys.argv[1]
|
||||
print(COURSEID)
|
||||
print(USERID)
|
||||
example = page.goto(f"{BASEURL}{COURSEID}{USERID}")
|
||||
page.screenshot(path="/Users/normrasmussen/Downloads/screenshot1.png", full_page=True)
|
||||
page.locator('#course-mobile > div.np-top-cta.stick-to-bottom > a').click()
|
||||
page.screenshot(path="/Users/normrasmussen/Downloads/screenshot2.png").mask(['#activity-b4be181e-d2ea-46f8-bb1a-cd316c590fcf > div.Wrapper-h8th5y-0.evldAo.footer__wrapper > div > footer'])
|
||||
screen_num = 0
|
||||
|
||||
# Navigate to and screenshot the title page
|
||||
page.goto(f"{BASEURL}{COURSEID}{USERID}")
|
||||
course_name = page.locator('.header-title').evaluate("node => node.innerText")
|
||||
print(course_name)
|
||||
|
||||
# Extract all hrefs from the course outline
|
||||
course_links = page.locator('.np-course-outline-content-section a').evaluate_all('elements => elements.map(el => el.href)')
|
||||
page.screenshot(path=f"{DIR}-{course_name}_{screen_num}.png", full_page=True)
|
||||
|
||||
print("Course outline links:")
|
||||
for idx, link in enumerate(course_links):
|
||||
screen_num += 1
|
||||
print(f"{idx + 1}. {link}")
|
||||
page.goto(f"{link}")
|
||||
page.screenshot(path=f"{DIR}-{course_name}_{screen_num}.png", full_page=True)
|
||||
browser.close()
|
||||
# find_pictures()
|
||||
|
||||
|
||||
def find_pictures(DIR):
|
||||
files = []
|
||||
listfiles = glob.glob(DIR + "*.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, DIR)
|
||||
|
||||
|
||||
def split_resources(files, DIR):
|
||||
try:
|
||||
resource_title = files[0][:-6]
|
||||
# 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, DIR)
|
||||
process_pictures(new_list, resource_title, DIR)
|
||||
except IndexError as e:
|
||||
print(e)
|
||||
finally:
|
||||
pass
|
||||
|
||||
|
||||
def process_pictures(new_list, resource_title, DIR):
|
||||
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(
|
||||
DIR + f"PDFs/{resource_title}_{today}.pdf",
|
||||
save_all=True,
|
||||
append_images=image_list,
|
||||
)
|
||||
|
||||
|
||||
def delete_originals(DIR):
|
||||
path = glob.glob(DIR + "*.png")
|
||||
for file in path:
|
||||
try:
|
||||
os.remove(file)
|
||||
except TypeError as e:
|
||||
print("Error!")
|
||||
print(e)
|
||||
print("All Done")
|
||||
|
||||
|
||||
with sync_playwright() as playwright:
|
||||
run(playwright)
|
||||
find_pictures(DIR)
|
||||
delete_originals(DIR)
|
||||
|
||||
Reference in New Issue
Block a user