diff options
| author | Bobby <[email protected]> | 2022-11-22 07:04:45 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-11-22 07:04:45 -0500 |
| commit | 78459b8007e4776f57cca72ff2040921d61661cd (patch) | |
| tree | 5b8f7e702ba260d9d2fe8bfe29c6dad37342b57e /ignis/github.py | |
| parent | 0c6507767655598026102c4adb0bca2d2abc732f (diff) | |
| download | thatcomputerscientist-78459b8007e4776f57cca72ff2040921d61661cd.tar.xz thatcomputerscientist-78459b8007e4776f57cca72ff2040921d61661cd.zip | |
some changes for repo section
Diffstat (limited to 'ignis/github.py')
| -rw-r--r-- | ignis/github.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/ignis/github.py b/ignis/github.py new file mode 100644 index 00000000..a4cae4bf --- /dev/null +++ b/ignis/github.py @@ -0,0 +1,42 @@ +import requests +from dotenv import load_dotenv +import os +from selenium import webdriver +from selenium.webdriver.chrome.options import Options as ChromeOptions +from selenium.webdriver.firefox.options import Options as FirefoxOptions +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +from io import BytesIO +from PIL import Image + +load_dotenv() + +def get_cover(url): + image = requests.get(url).content + chrome_options = ChromeOptions() + chrome_options.add_argument("--headless") + chrome_options.add_argument("--disable-gpu") + + firefox_options = FirefoxOptions() + firefox_options.add_argument("--headless") + + driver = webdriver.Chrome(options=chrome_options) if os.getenv("ENVIRONMENT") == 'development' else webdriver.Firefox(options=firefox_options) + + driver.get(url) + try: + # take screenshot of page - 1280x640 + WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.TAG_NAME, 'svg')) + ) + driver.set_window_size(1280, 640) + image = driver.get_screenshot_as_png() + finally: + driver.quit() + + # resize image to 640x320 + image = Image.open(BytesIO(image)) + image = image.resize((640, 320)) + output = BytesIO() + image.save(output, format='PNG') + return output.getvalue() |
