Skip to content

Instantly share code, notes, and snippets.

@dragere
Created August 8, 2021 15:53
Show Gist options
  • Select an option

  • Save dragere/0111d6935ae0a29ee74f0b1752b9e4f3 to your computer and use it in GitHub Desktop.

Select an option

Save dragere/0111d6935ae0a29ee74f0b1752b9e4f3 to your computer and use it in GitHub Desktop.
TiddlyWiki5 server python script
import sys
from flask import Flask, request, make_response, send_file
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class TiddlyWiki(Resource):
def get(self):
return send_file(file)
def put(self):
f = open(file, "wb")
f.write(request.data)
f.close()
def options(self):
res = make_response()
res.headers['allow'] = "GET,HEAD,POST,OPTIONS,CONNECT,PUT,DAV,dav"
res.headers['x-api-access-type'] = 'file'
res.headers['dav'] = 'tw5/put'
return res
if __name__ == '__main__':
if len(sys.argv) != 2:
raise ValueError('Please provide the file to host')
file = sys.argv[1]
api.add_resource(TiddlyWiki, '/')
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment