-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_fetcher.py
33 lines (29 loc) · 1.09 KB
/
data_fetcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
import os
class data_fetcher:
def store_object_locally(self, object, title, local_destination):
try:
outputWriter = open(local_destination + title, 'wb')
outputWriter.write(object)
outputWriter.close()
except Exception:
raise IOError("Unable to write object to " + str(local_destination) + ".")
def get_object_from_url(self, url):
try:
object = requests.get(str(url))
return object.content
except:
raise IOError("Unable to fetch object at " + str(url))
def get_list_objects(self, url_list):
return_array = []
try:
for url in url_list:
return_array.append(self.get_object_from_url(url))
except:
raise Exception("Failed to get objects in list")
return return_array
def store_objects_locally(self, title_list, object_list, local_destination):
i = 0
for object in object_list:
self.store_object_locally(object, str(title_list[i]), local_destination)
i += 1