-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/julianfl0w/BookOfJulian
- Loading branch information
Showing
7 changed files
with
197 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Use Python with Alpine Linux base image | ||
FROM python:3.9-alpine | ||
|
||
# Set the working directory in the container | ||
WORKDIR / | ||
|
||
# Install dependencies for headless operation | ||
RUN apk add --no-cache \ | ||
chromium \ | ||
chromium-chromedriver \ | ||
&& pip install --no-cache-dir selenium==4.0.0 webdriver_manager | ||
|
||
# Copy the script into the container | ||
COPY verifyCert.py /verifyCert.py | ||
|
||
# Command to run the script | ||
CMD ["python", "/verifyCert.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# URL to test | ||
TEST_URL="https://www.coursera.org/account/accomplishments/verify/GA668424ZUQH" | ||
|
||
# Name of your Docker image | ||
DOCKER_IMAGE="selenium" | ||
|
||
# Run the Docker container and capture the output | ||
output=$(docker run --rm -e TEST_URL="$TEST_URL" "$DOCKER_IMAGE") | ||
|
||
# Check the output | ||
echo "Output received: $output" | ||
|
||
# Parse and check the output here | ||
# Example: using jq to check a JSON output | ||
# echo $output | jq 'Your conditions here' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import json | ||
import os | ||
from selenium import webdriver | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
|
||
# Set up Chrome options for headless operation | ||
chrome_options = Options() | ||
chrome_options.add_argument("--headless") | ||
chrome_options.add_argument("--no-sandbox") | ||
chrome_options.add_argument("--disable-dev-shm-usage") | ||
|
||
def scrape_url(driver, url): | ||
driver.get(url) | ||
name_element = WebDriverWait(driver, 4).until( | ||
EC.presence_of_element_located((By.CSS_SELECTOR, "h3.cds-119 strong")) | ||
) | ||
name = name_element.text if name_element else "Name not found" | ||
|
||
course_name_element = driver.find_element(By.CSS_SELECTOR, "h2.course-name") | ||
course_name = course_name_element.text if course_name_element else "Course name not found" | ||
|
||
return {'name': name, 'course_name': course_name} | ||
|
||
def lambda_handler(event, context): | ||
results = [] | ||
urls = event.get('urls') | ||
if not urls or not isinstance(urls, list): | ||
return { | ||
'statusCode': 400, | ||
'body': json.dumps({'error': 'Missing or invalid URL list'}) | ||
} | ||
|
||
# Initialize the headless browser | ||
with webdriver.Chrome(options=chrome_options) as driver: | ||
for url in urls: | ||
try: | ||
result = scrape_url(driver, url) | ||
results.append(result) | ||
except Exception as e: | ||
results.append({'error': str(e)}) | ||
|
||
return { | ||
'statusCode': 200, | ||
'body': json.dumps(results) | ||
} | ||
|
||
# Main execution for direct run | ||
if __name__ == '__main__': | ||
# Get URL from environment variable | ||
test_url = os.environ.get('TEST_URL') | ||
|
||
if test_url: | ||
# Simulate the event structure for direct invocation | ||
event = {'urls': [test_url]} | ||
result = lambda_handler(event, context=None) | ||
print(json.dumps(result, indent=4)) | ||
else: | ||
print("No URL provided.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters