mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-12 20:13:29 -06:00
hidden.py merge into main, no longer .gitignore (oh god)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,6 +3,5 @@ key
|
|||||||
/key
|
/key
|
||||||
/migrations/*
|
/migrations/*
|
||||||
/venv/*
|
/venv/*
|
||||||
/app/hidden.py
|
|
||||||
/app/__pycache__/*
|
/app/__pycache__/*
|
||||||
/__pycache__/*
|
/__pycache__/*
|
||||||
@@ -15,4 +15,4 @@ login.login_view = 'login'
|
|||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
migrate = Migrate(app, db)
|
migrate = Migrate(app, db)
|
||||||
|
|
||||||
from app import routes, models, hidden
|
from app import routes, models
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
from app import app
|
from app import app
|
||||||
from app.models import User
|
from app.models import User
|
||||||
from app.forms import LoginForm
|
from app.forms import LoginForm
|
||||||
from app.hidden import trap
|
|
||||||
from werkzeug.urls import url_parse
|
from werkzeug.urls import url_parse
|
||||||
from flask import render_template, redirect, url_for, flash, request, jsonify
|
from flask import render_template, redirect, url_for, flash, request, jsonify
|
||||||
from flask_login import current_user, login_user, logout_user, login_required
|
from flask_login import current_user, login_user, logout_user, login_required
|
||||||
|
import requests
|
||||||
|
import xmltodict
|
||||||
|
import base64
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import faker
|
import faker
|
||||||
@@ -12,8 +14,7 @@ import json
|
|||||||
|
|
||||||
fake = faker.Faker()
|
fake = faker.Faker()
|
||||||
|
|
||||||
def strgen(length): return ''.join(
|
def strgen(length): return ''.join(random.choices(list(string.ascii_letters), k=length))
|
||||||
random.choices(list(string.ascii_letters), k=length))
|
|
||||||
|
|
||||||
@app.route('/api')
|
@app.route('/api')
|
||||||
def api():
|
def api():
|
||||||
@@ -75,3 +76,68 @@ def login():
|
|||||||
def logout():
|
def logout():
|
||||||
logout_user()
|
logout_user()
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
def boolparse(string, default=False):
|
||||||
|
# falses = ['false', '0']
|
||||||
|
trues = ['true', '1']
|
||||||
|
if string is None:
|
||||||
|
return default
|
||||||
|
elif string.lower() in trues:
|
||||||
|
return True
|
||||||
|
# elif string.lower() in falses:
|
||||||
|
# return False
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
@app.route(hidden_value)
|
||||||
|
@login_required
|
||||||
|
def hidden():
|
||||||
|
# Handled within request
|
||||||
|
tags = request.args.get('tags') or 'trap'
|
||||||
|
try:
|
||||||
|
page = int(request.args.get('page') or 1) - 1
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return '\"page\" parameter must be Integer.<br>Invalid \"page\" parameter: \"{}\"'.format(request.args.get('page'))
|
||||||
|
# Handled within building
|
||||||
|
try:
|
||||||
|
count = int(request.args.get('count') or 50)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return '\"count\" parameter must be Integer.<br>Invalid \"count\": \"{}\"'.format(request.args.get('count'))
|
||||||
|
base64 = boolparse(request.args.get('base64'))
|
||||||
|
# Handled within Jinja template
|
||||||
|
print(request.args.get('showsample'))
|
||||||
|
showsample = boolparse(request.args.get('showsample'), default=True)
|
||||||
|
showtags = boolparse(request.args.get('showtags'))
|
||||||
|
# Request, Parse & Build Data
|
||||||
|
data = trap(tags, page, count, base64, showsample)
|
||||||
|
print(showsample)
|
||||||
|
return render_template('hidden.html', data=data, base64=base64, showsample=showsample, showtags=showtags)
|
||||||
|
|
||||||
|
def base64ify(url):
|
||||||
|
return base64.b64encode(requests.get(url).content).decode()
|
||||||
|
|
||||||
|
gelbooru_url = "https://gelbooru.com/index.php?page=dapi&s=post&q=index&tags={}&pid={}&limit={}"
|
||||||
|
|
||||||
|
def trap(tags, page, count, base64, showsample):
|
||||||
|
# URL Building & Request
|
||||||
|
temp = gelbooru_url.format(tags, page, count)
|
||||||
|
response = requests.get(temp).text
|
||||||
|
# XML Parsing & Data Building
|
||||||
|
parse = xmltodict.parse(response)
|
||||||
|
build = []
|
||||||
|
|
||||||
|
for index, element in enumerate(parse['posts']['post'][:count]):
|
||||||
|
temp = {
|
||||||
|
'index' : str(index + 1),
|
||||||
|
'real_url' : element['@file_url'],
|
||||||
|
'sample_url' : element['@preview_url'],
|
||||||
|
'tags' : element['@tags']
|
||||||
|
}
|
||||||
|
if base64:
|
||||||
|
if showsample:
|
||||||
|
temp['base64'] = base64ify(temp['sample_url'])
|
||||||
|
else:
|
||||||
|
temp['base64'] = base64ify(temp['real_url'])
|
||||||
|
|
||||||
|
build.append(temp)
|
||||||
|
return build
|
||||||
@@ -3,15 +3,65 @@
|
|||||||
{{ super() }}
|
{{ super() }}
|
||||||
<meta name="referrer" content="no-referrer" />
|
<meta name="referrer" content="no-referrer" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.resize-font {
|
.resize-font {
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
{% endblock head %}
|
{% endblock head %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
|
||||||
<section class="section section-padding">
|
<section class="section section-padding">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="columns is-mobile is-multiline is-centered">
|
<div class="columns is-mobile is-multiline is-centered">
|
||||||
|
<!-- Optiosn Card -->
|
||||||
|
<div class="column is-3">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<div class="card-header-title">
|
||||||
|
Options
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="content word-break resize-font">
|
||||||
|
<form method="GET" action="/hidden43">
|
||||||
|
<div class="field">
|
||||||
|
<label for="tags">Tags</label>
|
||||||
|
<p class="control has-icons-left">
|
||||||
|
<input class="input" type="search" name="tags" />
|
||||||
|
<span class="icon is-small is-left">
|
||||||
|
<i class="fas fa-lock"></i>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<label for="count">Count</label>
|
||||||
|
<p class="control has-icons-left">
|
||||||
|
<input class="input" type="number" min="0" name="count" value="42" />
|
||||||
|
<span class="icon is-small is-left">
|
||||||
|
<i class="fas fa-lock"></i>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="base64">Use base64 encoding?</label>
|
||||||
|
<input type="checkbox" name="base64" />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="showsample">Show sample (thumbnail image)?</label>
|
||||||
|
<input type="checkbox" name="showsample" />
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="showtags">Show tags of image?</label>
|
||||||
|
<input type="checkbox" name="showtags" />
|
||||||
|
</div>
|
||||||
|
<input class="button" type="submit" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- End Options Card -->
|
||||||
{% for image in data %}
|
{% for image in data %}
|
||||||
<!-- Card Content -->
|
<!-- Card Content -->
|
||||||
<div class="column is-3">
|
<div class="column is-3">
|
||||||
|
|||||||
Reference in New Issue
Block a user