This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from dialect-map/dm-io-0.5.0
- Loading branch information
Showing
12 changed files
with
132 additions
and
88 deletions.
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 |
---|---|---|
|
@@ -4,5 +4,5 @@ pytz==2021.3 | |
feedparser==6.0.8 | ||
|
||
# Private packages | ||
git+ssh://[email protected]/dialect-map/dialect-map-io.git@v0.4.0#egg=dialect-map-io[gcp] | ||
git+ssh://[email protected]/dialect-map/dialect-map-io.git@v0.5.1#egg=dialect-map-io[gcp] | ||
git+ssh://[email protected]/dialect-map/[email protected]#egg=dialect-map-schemas |
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
|
||
from .content import * | ||
from .metadata import * | ||
|
||
from .helpers import init_source_cls |
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,53 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from urllib.request import Request as URI | ||
|
||
from dialect_map_io import BaseHandler | ||
from dialect_map_io import ArxivAPIHandler | ||
from dialect_map_io import JSONFileHandler | ||
|
||
from .metadata import * | ||
from ..parsers import FeedMetadataParser | ||
from ..parsers import JSONMetadataParser | ||
|
||
|
||
SOURCE_TYPE_API = "api" | ||
SOURCE_TYPE_FILE = "file" | ||
|
||
SOURCE_TYPE_MAPPINGS = { | ||
SOURCE_TYPE_API: { | ||
"handler_cls": ArxivAPIHandler, | ||
"parser_cls": FeedMetadataParser, | ||
"source_cls": ArxivMetadataSource, | ||
}, | ||
SOURCE_TYPE_FILE: { | ||
"handler_cls": JSONFileHandler, | ||
"parser_cls": JSONMetadataParser, | ||
"source_cls": JSONMetadataSource, | ||
}, | ||
} | ||
|
||
|
||
def init_source_cls(uri: URI, handler: BaseHandler) -> BaseMetadataSource: | ||
""" | ||
Returns a source class depending on the provided URI | ||
:param uri: URI to get the source class from | ||
:param handler: handler to get the metadata from | ||
:return: source class | ||
""" | ||
|
||
if uri.type in {"file"}: | ||
classes = SOURCE_TYPE_MAPPINGS[SOURCE_TYPE_FILE] | ||
kwargs = {"file_path": uri.selector} | ||
elif uri.type in {"http", "https"}: | ||
classes = SOURCE_TYPE_MAPPINGS[SOURCE_TYPE_API] | ||
kwargs = {} | ||
else: | ||
raise ValueError("Source not specified for the provided URI") | ||
|
||
handler_cls = classes["handler_cls"] | ||
parser_cls = classes["parser_cls"] | ||
source_cls = classes["source_cls"] | ||
|
||
assert isinstance(handler, handler_cls) | ||
return source_cls(handler=handler, parser=parser_cls(), **kwargs) |
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
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
Oops, something went wrong.