-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
37 lines (31 loc) · 1.1 KB
/
__init__.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
from flask import Flask, render_template
from urllib.parse import quote
from urllib.request import urlopen
import json
# Manually get data from the deviantArt oembed API to build a better and more reliable embed
# Robin Universe w/ tweaks from Dania
# 05 . 04 . 22
# Initialise Flask
app = Flask(__name__)
# Open config.json and load it into a dictionary variable
with open("config.json", "r") as config_file:
config = json.load(config_file)
# Main Function
@app.route("/<path:subpath>")
def fxdeviantart(subpath):
# Original link to submission, to be used for the `url` parameter in the template
origin = "https://deviantart.com/" + subpath
# Get the submission's JSON data
data = json.load(
urlopen(("https://backend.deviantart.com/oembed?url=" + str(quote(origin))))
)
# Return the template with the data
return render_template(
"index.html",
user="by " + data["author_name"],
img=data["url"],
url=origin,
title=data["title"],
site_name=config["siteConfig"]["siteName"],
color=config["siteConfig"]["embedColor"],
)