aboutsummaryrefslogtreecommitdiff
path: root/ignis
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-03-26 03:12:04 -0400
committerBobby <[email protected]>2023-03-26 03:12:04 -0400
commit28ecc22d607bebbca6637733e73365fcb28d4225 (patch)
treeee46d39fed12a946a51660c6dc3c49aab1716a34 /ignis
parentb7c82d55d3a5efcb025a34579d5d98877a9e9ba4 (diff)
downloadthatcomputerscientist-28ecc22d607bebbca6637733e73365fcb28d4225.tar.xz
thatcomputerscientist-28ecc22d607bebbca6637733e73365fcb28d4225.zip
Fix: Self Screenshot
Diffstat (limited to 'ignis')
-rw-r--r--ignis/views.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/ignis/views.py b/ignis/views.py
index a6f02c95..965e6498 100644
--- a/ignis/views.py
+++ b/ignis/views.py
@@ -12,6 +12,11 @@ from users.tokens import CaptchaTokenGenerator
from django.http import HttpResponse
from django.views.decorators.cache import never_cache
+from PIL import Image
+from io import BytesIO
+from selenium import webdriver
+import time
+import os
# from .github import get_cover
# Create your views here.
@@ -166,6 +171,29 @@ def captcha_image(request, captcha_string):
@never_cache
def get_screenshot(request):
+ # check if screenshot exists
+ if not os.path.exists('siteshot.png'):
+ 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()
+
+ # Save as 'siteshot.png'
+ screenshot.save('siteshot.png', 'PNG')
+
+
# open file called 'siteshot.png' in the root directory
with open('siteshot.png', 'rb') as f:
image = f.read()
@@ -173,7 +201,7 @@ def get_screenshot(request):
image = Image.open(BytesIO(image))
output = BytesIO()
image.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'