Skip to content

Instantly share code, notes, and snippets.

@hughdbrown
Created June 21, 2017 03:53
Show Gist options
  • Save hughdbrown/e2cc866bfb2ff49c4822579d16aeda04 to your computer and use it in GitHub Desktop.
Save hughdbrown/e2cc866bfb2ff49c4822579d16aeda04 to your computer and use it in GitHub Desktop.
Flask proxy to serve MLB files locally. I have them all stored on disk. Why go to the internet for this?
#!/usr/bin/env python
from hashlib import sha1
import os
import os.path
from flask import (
Flask,
send_from_directory,
)
print("Creating app")
app = Flask(__name__)
print("Getting env var")
MLB_CACHEDIR = os.environ.get(
"MLB_CACHEDIR",
os.path.join(os.path.expanduser("~/workspace/mlb"), "cachedir")
)
print(MLB_CACHEDIR)
@app.route('/<path:path>', methods=['GET'])
def index(path):
remap_path = "http://gd2.mlb.com/" + path
sha_path = sha1(remap_path).hexdigest()
print("Getting: {0} | {1}".format(remap_path, sha_path))
return send_from_directory(MLB_CACHEDIR, sha_path)
if __name__ == '__main__':
print("Starting app...")
app.run(debug=True, host='0.0.0.0', port=80)
print("Ending app")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment