Skip to content

Instantly share code, notes, and snippets.

@gnardini
Created August 31, 2017 20:43
Show Gist options
  • Save gnardini/240687da6e5096b3f0b11e3a63a7d953 to your computer and use it in GitHub Desktop.
Save gnardini/240687da6e5096b3f0b11e3a63a7d953 to your computer and use it in GitHub Desktop.
from flask import Flask, request
import os
from os.path import expanduser
app = Flask(__name__)
def expand(path):
if path.startswith('~'):
path = path[1:]
path = expanduser("~") + path
return path
@app.route("/fetch")
def fetch_shows():
dir = request.args.get('directory')
dir = expand(dir)
dirs = filter(lambda x: not x.startswith('.'), os.listdir(dir))
return str(list(dirs))
@app.route("/open")
def open():
file = request.args.get('file')
file = expand(file)
# os.startfile(file)
os.system('open %s' % file)
return "{\"result\": \"OK\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment