-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import re | ||
import os | ||
from six.moves.urllib import parse, request | ||
|
||
from akagi.content import Content | ||
from akagi.iterator import Iterator | ||
|
||
|
||
class URLContent(Content): | ||
is_local = False | ||
|
||
def __init__(self, urlstr, file_format='csv'): | ||
self._url = parse.urlparse(urlstr) | ||
self.file_format = file_format | ||
self.iterator_class = Iterator.get_iterator_class(file_format) | ||
|
||
def __iter__(self): | ||
return self.iterator_class(self) | ||
|
||
@property | ||
def key(self): | ||
return os.path.join(self._url.netloc, re.sub(r'^/', '', self._url.path)) | ||
|
||
@property | ||
def _body(self): | ||
return request.urlopen(self._url.geturl()) |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from akagi.data_source import DataSource | ||
|
||
from akagi.data_file import data_files_for_urls | ||
|
||
|
||
class URLDataSource(DataSource): | ||
'''URLDataSource replesents a set of files on remote location. | ||
''' | ||
|
||
@classmethod | ||
def for_urls(cls, urls, file_format='csv', no_cache=False): | ||
return URLDataSource(urls, file_format=file_format, no_cache=no_cache) | ||
|
||
def __init__(self, urls, file_format='csv', no_cache=False): | ||
self._urls = urls | ||
self._file_format = file_format | ||
|
||
@property | ||
def data_files(self): | ||
return data_files_for_urls(self._urls, self._file_format) |