Finish coding reg

master
Tanner Collin 4 years ago
parent a7ddce7144
commit a363b3f4cd
  1. 82
      t0reg.py

@ -1,61 +1,69 @@
# t0txt - txt.t0.vc
# t0reg - reg.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'
PORT = 5005
URL = 'https://reg.t0.vc'
POST = 'reg'
def help():
registers = {}
def help(nid):
form = (
'<form action="{0}" method="POST" accept-charset="UTF-8">'
'<input name="web" type="hidden" value="true">'
'<textarea name="{1}" cols="60" rows="18"></textarea>'
'<br><button type="submit">Submit</button></form>'.format(URL, POST)
'<input name="{1}">'
'<br><button type="submit">Submit</button></form>'.format(URL, nid)
)
return """
<pre>
txt.t0.vc
reg.t0.vc
NAME
t0txt: command line pastebin.
t0reg: command line key-value registers
USAGE
&lt;command&gt; | curl -F '{0}=&lt;-' {1}
or upload from the web:
{2}
The key {0} was randomly chosen for you.
DESCRIPTION
I got sick of sprunge.us always going down, so I built this
This lets you POST data to a key of your choice.
You can then GET the data at that key.
This is useful for moving data / files between servers.
All the data is stored temporarily.
Make your key random if you don't want people guessing.
EXAMPLES
~$ cat yourfile | curl -F '{0}=&lt;-' {1}
{1}/MOJV
~$ firefox {1}/MOJV
~$ echo "hello world" | curl -F '{0}=&lt;-' {1}
~$ curl {1}/{0}
hello world
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}"
alias push="curl -F '{0}=<-' {1}"
alias pull="curl {1}/{0}"
Now you can pipe directly into push!
Get the data back with pull.
Now you can pipe directly into {0}! Sed removes colours.
To move a file:
~$ cat kitten.jpg | base64 | push
~$ pull | base64 -d > kitten.jpg
SOURCE CODE
https://txt.t0.vc/GPBV
https://github.com/tannercollin/t0txt
https://txt.t0.vc/SBSU
SEE ALSO
https://txt.t0.vc
https://pic.t0.vc
https://url.t0.vc
http://github.com/rupa/sprunge
</pre>""".format(POST, URL, form)
</pre>""".format(nid, URL, form)
def new_id():
return ''.join(random.choice(string.ascii_uppercase) for _ in range(4))
@ -64,35 +72,27 @@ flask_app = Flask(__name__)
@flask_app.route('/', methods=['GET'])
def index():
return '<html><body>{}</body></html>'.format(help())
return '<html><body>{}</body></html>'.format(help(new_id()))
@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))
pairs = [x for x in request.form.items() if x[0] != 'web']
for key, value in pairs:
print('Adding:', key)
registers[key] = value
url = '{}/{}'.format(URL, nid)
if 'web' in request.form:
return redirect(url)
return redirect(URL + '/' + key)
else:
return url + '\n'
return '', 200
except:
abort(400)
@flask_app.route('/<nid>', methods=['GET'])
def get(nid):
@flask_app.route('/<rid>', methods=['GET'])
def get(rid):
try:
with shelve.open(DB) as db:
return db[nid] + '\n', 200, {'Content-Type': 'text/plain; charset=utf-8'}
return registers[rid], 200, {'Content-Type': 'text/plain; charset=utf-8'}
except:
abort(404)

Loading…
Cancel
Save