memex-in commited on
Commit
9305c51
·
verified ·
1 Parent(s): e3e2680

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from selenium import webdriver
3
+ from selenium.webdriver.chrome.options import Options
4
+ from PIL import Image
5
+ from ascii_magic import from_image_file, to_terminal
6
+
7
+ def capture_screenshot(url, output_path='screenshot.png'):
8
+ # Set up headless Chrome
9
+ chrome_options = Options()
10
+ chrome_options.add_argument('--headless')
11
+ chrome_options.add_argument('--disable-gpu')
12
+ chrome_options.add_argument('--window-size=1920,1080')
13
+
14
+ # Initialize WebDriver
15
+ driver = webdriver.Chrome(options=chrome_options)
16
+ driver.get(url)
17
+
18
+ # Save screenshot
19
+ driver.save_screenshot(output_path)
20
+ driver.quit()
21
+
22
+ def convert_to_ascii(image_path):
23
+ # Convert image to ASCII art
24
+ output = from_image_file(image_path, columns=100, char='#')
25
+ to_terminal(output)
26
+
27
+ if __name__ == '__main__':
28
+ url = input("Enter the website URL (e.g., https://example.com): ").strip()
29
+ screenshot_file = 'screenshot.png'
30
+
31
+ print(f"\nCapturing screenshot of {url}...")
32
+ capture_screenshot(url, screenshot_file)
33
+
34
+ print("\nConverting screenshot to ASCII art:\n")
35
+ convert_to_ascii(screenshot_file)
36
+
37
+ # Optional: Remove the screenshot file after conversion
38
+ os.remove(screenshot_file)