memex-in's picture
Create app.py
9305c51 verified
raw
history blame
1.21 kB
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from PIL import Image
from ascii_magic import from_image_file, to_terminal
def capture_screenshot(url, output_path='screenshot.png'):
# Set up headless Chrome
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--window-size=1920,1080')
# Initialize WebDriver
driver = webdriver.Chrome(options=chrome_options)
driver.get(url)
# Save screenshot
driver.save_screenshot(output_path)
driver.quit()
def convert_to_ascii(image_path):
# Convert image to ASCII art
output = from_image_file(image_path, columns=100, char='#')
to_terminal(output)
if __name__ == '__main__':
url = input("Enter the website URL (e.g., https://example.com): ").strip()
screenshot_file = 'screenshot.png'
print(f"\nCapturing screenshot of {url}...")
capture_screenshot(url, screenshot_file)
print("\nConverting screenshot to ASCII art:\n")
convert_to_ascii(screenshot_file)
# Optional: Remove the screenshot file after conversion
os.remove(screenshot_file)