From dd073f7256bd53162e1ee93c6777ba6c7e97f3ca Mon Sep 17 00:00:00 2001 From: jwansek Date: Sat, 6 Mar 2021 19:36:10 +0000 Subject: added getting random anime images --- app.py | 14 +++++++ parser.py | 2 +- services.py | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ static/index.md | 4 +- static/style.css | 8 ++++ templates/random.html | 22 +++++++++++ 6 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 templates/random.html diff --git a/app.py b/app.py index c7d8756..b187f3e 100644 --- a/app.py +++ b/app.py @@ -132,6 +132,20 @@ def serve_image(filename): else: flask.abort(404) +@app.route("/random") +def serve_random(): + try: + tags = flask.request.args['tags'].split(" ") + except KeyError: + flask.abort(400) + + with database.Database() as db: + return flask.render_template( + "random.html", + **get_template_items("random image", db), + sbi = services.get_random_image(tags) + ) + @app.route("/api/") def serve_api_request(infoRequest): if infoRequest == "commits": diff --git a/parser.py b/parser.py index d8dedea..6b5ac18 100644 --- a/parser.py +++ b/parser.py @@ -77,7 +77,7 @@ def parse_asteriscs(test_str): return test_str def parse_links(test_str): - regex = r"(?") + 7 : text.find("")] in ["Error | nitter", "イラストコミュニケーションサービス[pixiv]"] + +if __name__ == "__main__": + sbi = get_random_image(["lio_fotia", "promare"]) + print(sbi.tags) + print(sbi.source) + print(sbi.imurl) + print(sbi.remove_tag("promare")) + diff --git a/static/index.md b/static/index.md index 080a648..e217a94 100644 --- a/static/index.md +++ b/static/index.md @@ -1,3 +1,5 @@ # haii my name is eden and im a 19yo computer science undergraduate. i made my own website to encourage others to do so too. -i'll post my thoughts on here sometimes, and use this site to link to other stuff i host. \ No newline at end of file +i'll post my thoughts on here sometimes, and use this site to link to other stuff i host. + +[click here for a random image of lio fotia](/random?tags=lio_fotia) \ No newline at end of file diff --git a/static/style.css b/static/style.css index 1ac4ec3..26b337c 100644 --- a/static/style.css +++ b/static/style.css @@ -96,6 +96,10 @@ article section table td { text-align: right; } +#randomImage img { + max-width: 65%; +} + aside { width: 30%; padding-left: 15px; @@ -103,6 +107,10 @@ aside { float: right; } +#tags { + font-size: xx-small; +} + .running { background-color: green; padding: 1, 1, 1, 1; diff --git a/templates/random.html b/templates/random.html new file mode 100644 index 0000000..e36bb87 --- /dev/null +++ b/templates/random.html @@ -0,0 +1,22 @@ +{% extends "template.html" %} +{% block content %} + +
+ +

generate another

+

artist link

+
+{% endblock %} \ No newline at end of file -- cgit v1.2.3