Created
December 9, 2019 08:29
-
-
Save i-amgeek/d1032b09d476b1fa2eb6bff073f057f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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