Skip to content

Instantly share code, notes, and snippets.

@i-amgeek
Created December 9, 2019 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i-amgeek/d1032b09d476b1fa2eb6bff073f057f0 to your computer and use it in GitHub Desktop.
Save i-amgeek/d1032b09d476b1fa2eb6bff073f057f0 to your computer and use it in GitHub Desktop.
import shutil
import requests
import uuid
def load_file(path):
'''
Returns path of input file. If given parameter 'path' is an url,
first downloads the file
'''
if path.startswith(('https://', 'http://')):
fileName = path.split('/')[-1]
filePath = 'data/input/'
data = requests.get(path)
open(filePath+fileName, 'wb') as f: f.write(data)
return filePath+fileName
else:
path = path.replace('file://', '')
return path
def expose_file(path):
'''
Saves file to make it accessible to API.
'''
fileExtension = path.split('.')[-1]
filePath = 'data/ouput/'
fileName = uuid.uuid4().hex + fileExtension
new_path = filePath+fileName
shutil.move(path, new_path)
return new_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment