From 7b578119b89f68c6c54ef367816e20a02f7a9b5b Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 7 Aug 2019 21:01:29 +0000 Subject: [PATCH] Move t0txt to its own git repo --- .gitignore | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++ data/.gitkeep | 0 t0txt.py | 98 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 .gitignore create mode 100644 data/.gitkeep create mode 100644 t0txt.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10bad72 --- /dev/null +++ b/.gitignore @@ -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/* diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/t0txt.py b/t0txt.py new file mode 100644 index 0000000..1ee88cd --- /dev/null +++ b/t0txt.py @@ -0,0 +1,98 @@ +# t0txt - txt.t0.vc +# MIT License + +import random +import shelve +import string + +from flask import abort, Flask, request, redirect + +DB = 'data/t0txt' +PORT = 5002 +URL = 'https://txt.t0.vc' +POST = 'txt' + +def help(): + form = ( + '
' + '' + '' + '
'.format(URL, POST) + ) + return """ +
+                        txt.t0.vc
+NAME
+    t0txt: command line pastebin.
+
+USAGE
+    <command> | curl -F '{0}=<-' {1}
+    or upload from the web:
+
+{2}
+
+DESCRIPTION
+    I got sick of sprunge.us always going down, so I built this
+
+EXAMPLES
+    ~$ cat yourfile | curl -F '{0}=<-' {1}
+       {1}/MOJV
+    ~$ firefox {1}/MOJV
+
+    Add this to your .bashrc:
+
+    alias {0}=" \\
+    sed -r 's/\x1B\[([0-9]{{1,2}}(;[0-9]{{1,2}})?)?[m|K]//g' \\
+    | curl -F '{0}=<-' {1}"
+
+    Now you can pipe directly into {0}! Sed removes colours.
+
+SOURCE CODE
+    https://txt.t0.vc/GPBV
+
+SEE ALSO
+    https://pic.t0.vc
+    https://url.t0.vc
+    http://github.com/rupa/sprunge
+
""".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 '{}'.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() + + txt = request.form['txt'] + if not txt: raise + db[nid] = txt + + print('Adding note {}:\n{}'.format(nid, txt)) + + url = '{}/{}'.format(URL, nid) + if 'web' in request.form: + return redirect(url) + else: + return url + '\n' + except: + abort(400) + +@flask_app.route('/', methods=['GET']) +def get(nid): + try: + with shelve.open(DB) as db: + return db[nid] + '\n', 200, {'Content-Type': 'text/plain; charset=utf-8'} + except: + abort(404) + +flask_app.run(port=PORT)