Completed the playwright walmart screenshots script. Uploaded another Chubb CSV.
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
const courseDefaultPageTitle = document.title.split(" | ")
|
const courseDefaultPageTitle = document.title
|
||||||
const courseName = '{{course.name}}'
|
const courseName = '{{course.name}}'
|
||||||
document.title = `${courseName} | ${courseDefaultPageTitle[1]}`
|
document.title = `${courseName} | ${courseDefaultPageTitle[1]}`
|
||||||
const courseDescription = '{{course.short_description}}'
|
const courseDescription = '{{course.short_description}}'
|
||||||
@ -10,22 +10,22 @@
|
|||||||
<script> window.location.replace('/learners/sign_in')</script>
|
<script> window.location.replace('/learners/sign_in')</script>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% include "header" %}
|
{% include "header" %}
|
||||||
|
|
||||||
{% if course.ribbon == "VIDEO" %}
|
{% if course.ribbon == "VIDEO" %}
|
||||||
{% include "video_tutorial_cover" %}
|
{% include "video_tutorial_cover" %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% include "course_cover" %}
|
{% include "course_cover" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% include "footer" %}
|
{% include "footer" %}
|
||||||
|
|
||||||
{% if current_person.signed_in? == false and current_school.sso_active? %}
|
{% if current_person.signed_in? == false and current_school.sso_active? %}
|
||||||
<script>
|
<script>
|
||||||
const redirectionLink = 'https://user-learn.pipedrive.com/app/courses/{{ course.properties.second_school_course_uuid }}'
|
const redirectionLink = 'https://user-learn.pipedrive.com/app/courses/{{ course.properties.second_school_course_uuid }}'
|
||||||
document.querySelector('#redirect-between-academies').setAttribute('href', redirectionLink)
|
document.querySelector('#redirect-between-academies').setAttribute('href', redirectionLink)
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if current_person.signed_in? and current_school.properties.sandbox == false %}
|
{% if current_person.signed_in? and current_school.properties.sandbox == false %}
|
||||||
<script>
|
<script>
|
||||||
function setupLatestCourses() {
|
function setupLatestCourses() {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ HEADERS = {
|
|||||||
"X-Api-Key": APIKEY,
|
"X-Api-Key": APIKEY,
|
||||||
}
|
}
|
||||||
BASEURL = "https://api.northpass.com/v2/"
|
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():
|
def bulk_invite_and_group():
|
||||||
|
|||||||
@ -1,6 +1,17 @@
|
|||||||
import re
|
import re
|
||||||
import sys
|
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):
|
def run(playwright: Playwright):
|
||||||
print("running")
|
print("running")
|
||||||
@ -10,16 +21,86 @@ def run(playwright: Playwright):
|
|||||||
viewport={ 'width': 390, 'height': 844 }
|
viewport={ 'width': 390, 'height': 844 }
|
||||||
)
|
)
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
BASEURL = "https://walmart.northpass.com/app/courses/"
|
screen_num = 0
|
||||||
USERID = "?uid=7beg87y4-fh24-4929-3rt5-24kdn87s5241"
|
|
||||||
COURSEID = sys.argv[1]
|
# Navigate to and screenshot the title page
|
||||||
print(COURSEID)
|
page.goto(f"{BASEURL}{COURSEID}{USERID}")
|
||||||
print(USERID)
|
course_name = page.locator('.header-title').evaluate("node => node.innerText")
|
||||||
example = page.goto(f"{BASEURL}{COURSEID}{USERID}")
|
print(course_name)
|
||||||
page.screenshot(path="/Users/normrasmussen/Downloads/screenshot1.png", full_page=True)
|
|
||||||
page.locator('#course-mobile > div.np-top-cta.stick-to-bottom > a').click()
|
# Extract all hrefs from the course outline
|
||||||
page.screenshot(path="/Users/normrasmussen/Downloads/screenshot2.png").mask(['#activity-b4be181e-d2ea-46f8-bb1a-cd316c590fcf > div.Wrapper-h8th5y-0.evldAo.footer__wrapper > div > footer'])
|
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()
|
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:
|
with sync_playwright() as playwright:
|
||||||
run(playwright)
|
run(playwright)
|
||||||
|
find_pictures(DIR)
|
||||||
|
delete_originals(DIR)
|
||||||
|
|||||||
Reference in New Issue
Block a user