diff options
| author | Bobby <[email protected]> | 2023-03-26 02:45:43 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-03-26 02:45:43 -0400 |
| commit | ccbff8abb41a1b0543fcf4ed17ac14a540b14711 (patch) | |
| tree | c1a60499906d636ec06c3b9efc502e0eaeca6bcd /ignis | |
| parent | 27b9fb6a8de18f0aae748ec4572ed449ff445100 (diff) | |
| download | thatcomputerscientist-ccbff8abb41a1b0543fcf4ed17ac14a540b14711.tar.xz thatcomputerscientist-ccbff8abb41a1b0543fcf4ed17ac14a540b14711.zip | |
screenshot api
Diffstat (limited to 'ignis')
| -rw-r--r-- | ignis/urls.py | 3 | ||||
| -rw-r--r-- | ignis/views.py | 38 |
2 files changed, 39 insertions, 2 deletions
diff --git a/ignis/urls.py b/ignis/urls.py index 94de2803..9cea0ad2 100644 --- a/ignis/urls.py +++ b/ignis/urls.py @@ -8,5 +8,6 @@ urlpatterns = [ path('/upload', views.upload_image, name='upload_image'), path('/image/<post_id>/<image_name>', views.get_image, name='get_image'), path('/cover/<str:repository>', views.cover_image, name='cover_image'), - path('/captcha/<str:captcha_string>', views.captcha_image, name='captcha_image') + path('/captcha/<str:captcha_string>', views.captcha_image, name='captcha_image'), + path('/screenshot', views.get_screenshot, name='screenshot') ] diff --git a/ignis/views.py b/ignis/views.py index 1b8b6be1..30263877 100644 --- a/ignis/views.py +++ b/ignis/views.py @@ -3,12 +3,17 @@ from io import BytesIO from django.http import HttpResponse from django.views.decorators.csrf import csrf_exempt from blog.models import Post -from .models import PostImage, RepositoryTitle, CoverImage +from .models import PostImage, RepositoryTitle import json import requests from django.core.files.base import ContentFile from captcha.image import ImageCaptcha from users.tokens import CaptchaTokenGenerator + +from django.http import HttpResponse +from django.views.decorators.cache import never_cache +from selenium import webdriver +import time # from .github import get_cover # Create your views here. @@ -160,3 +165,34 @@ def captcha_image(request, captcha_string): data = imgcaptcha.generate(captcha) return HttpResponse(data, content_type='image/png') + +@never_cache +def get_screenshot(request): + # Configure Selenium WebDriver with headless Chrome options + options = webdriver.FirefoxOptions() + options.headless = True + driver = webdriver.Firefox(options=options) + driver.set_window_size(1280, 1280) + + url = 'https://www.thatcomputerscientist.com' + + # Wait until the page is loaded + driver.get(url) + + time.sleep(5) + + screenshot = driver.get_screenshot_as_png() + screenshot = Image.open(BytesIO(screenshot)) + + # Close the browser + driver.quit() + + # Convert the screenshot to a data URI + output = BytesIO() + screenshot.save(output, format='PNG') + + response = HttpResponse(output.getvalue(), content_type='image/png') + response['Cache-Control'] = 'no-cache, no-store, must-revalidate' + response['Pragma'] = 'no-cache' + response['Expires'] = '0' + return response |
