Move t0url to its own git repo
This commit is contained in:
+108
@@ -0,0 +1,108 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
.hypothesis/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# celery beat schedule file
|
||||||
|
celerybeat-schedule
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
|
||||||
|
# Editor
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# DB
|
||||||
|
db.sqlite3
|
||||||
|
|
||||||
|
data/*
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
# t0url - url.t0.vc
|
||||||
|
# MIT License
|
||||||
|
|
||||||
|
import random
|
||||||
|
import shelve
|
||||||
|
import string
|
||||||
|
import validators
|
||||||
|
|
||||||
|
from flask import abort, Flask, request, redirect
|
||||||
|
|
||||||
|
DB = 'data/t0url'
|
||||||
|
PORT = 5004
|
||||||
|
DOMAIN = 'url.t0.vc'
|
||||||
|
URL = 'https://' + DOMAIN
|
||||||
|
POST = 'url'
|
||||||
|
|
||||||
|
def help():
|
||||||
|
form = (
|
||||||
|
'<form action="{0}" method="POST" accept-charset="UTF-8">'
|
||||||
|
'<input name="web" type="hidden" value="true">'
|
||||||
|
'<input name="{1}">'
|
||||||
|
'<br><button type="submit">Submit</button></form>'.format(URL, POST)
|
||||||
|
)
|
||||||
|
return """
|
||||||
|
<pre>
|
||||||
|
url.t0.vc
|
||||||
|
NAME
|
||||||
|
t0url: command line short URL.
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
<command> | curl -F '{0}=<-' {1}
|
||||||
|
or upload from the web:
|
||||||
|
|
||||||
|
{2}
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
~$ cat yourfile | curl -F '{0}=<-' {1}
|
||||||
|
{1}/VFAR
|
||||||
|
~$ firefox {1}/VFAR
|
||||||
|
|
||||||
|
Add this to your .bashrc:
|
||||||
|
|
||||||
|
alias {0}="curl -F '{0}=<-' {1}"
|
||||||
|
|
||||||
|
Now you can pipe a URL directly into {0}!
|
||||||
|
|
||||||
|
SOURCE CODE
|
||||||
|
https://txt.t0.vc/RWFA
|
||||||
|
|
||||||
|
SEE ALSO
|
||||||
|
https://txt.t0.vc
|
||||||
|
https://pic.t0.vc
|
||||||
|
</pre>""".format(POST, URL, form)
|
||||||
|
|
||||||
|
def new_id():
|
||||||
|
return ''.join(random.choice(string.ascii_uppercase) for _ in range(4))
|
||||||
|
|
||||||
|
flask_app = Flask(__name__)
|
||||||
|
|
||||||
|
@flask_app.route('/', methods=['GET'])
|
||||||
|
def index():
|
||||||
|
return '<html><body>{}</body></html>'.format(help())
|
||||||
|
|
||||||
|
@flask_app.route('/', methods=['POST'])
|
||||||
|
def new():
|
||||||
|
try:
|
||||||
|
with shelve.open(DB) as db:
|
||||||
|
nid = new_id()
|
||||||
|
while nid in db:
|
||||||
|
nid = new_id()
|
||||||
|
|
||||||
|
url = request.form['url'].strip()
|
||||||
|
|
||||||
|
if not url: raise
|
||||||
|
if DOMAIN in url: raise
|
||||||
|
if not url.startswith('http'):
|
||||||
|
url = 'http://' + url
|
||||||
|
if not validators.url(url): raise
|
||||||
|
|
||||||
|
db[nid] = url
|
||||||
|
|
||||||
|
print('Adding url {}:\n{}'.format(nid, url))
|
||||||
|
|
||||||
|
return '{}/{}'.format(URL, nid) + '\n'
|
||||||
|
except:
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
@flask_app.route('/<nid>', methods=['GET'])
|
||||||
|
def get(nid):
|
||||||
|
try:
|
||||||
|
with shelve.open(DB) as db:
|
||||||
|
return redirect(db[nid])
|
||||||
|
except:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
flask_app.run(port=PORT)
|
||||||
Reference in New Issue
Block a user