-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
59 lines (47 loc) · 1.36 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
@author: ToshY
"""
import base64
from dataclasses import dataclass
from wsgiref.simple_server import make_server
import falcon
import cloudscraper
import validators
from src.banner import banner
@dataclass
class ImageResource:
"""
ImageResource
"""
def on_get(self, req, resp):
"""
GET method for requesting image from URL
:param req:
:param resp:
:return:
"""
image_url = req.get_param("url") or ""
if not validators.url(image_url):
# pylint: disable=maybe-no-member
raise falcon.HTTPBadRequest(
title="Invalid URL",
description=(
f"The supplied URL `{image_url}` is invalid"
),
)
result = scraper.get(image_url).content
b64_image = base64.b64encode(result).decode("utf-8")
# pylint: disable=maybe-no-member
resp.status = falcon.HTTP_200
resp.content_type = falcon.MEDIA_TEXT
resp.text = b64_image
app = falcon.App()
image_endpoint = ImageResource()
app.add_route("/image", image_endpoint)
if __name__ == "__main__":
banner("cloudscraper")
scraper = cloudscraper.create_scraper()
with make_server("", 8000, app) as httpd:
print("Serving on port 8000...")
# Serve until process is killed
httpd.serve_forever()