-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add key based search and list extraction
- Loading branch information
Showing
11 changed files
with
136 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class RegexConstants: | ||
INDEXED_ARRAY = r'\[(\d+)\]' | ||
DICT_ARRAY_SEARCH = r'\[\{(.+\=.+)\}\]' |
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 @@ | ||
from WPTParser.Constants.RegexConstants import RegexConstants as RegexConstants |
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,6 @@ | ||
class DataExtracter(): | ||
|
||
def extract(self): | ||
""" | ||
override for own implementation | ||
""" |
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,9 @@ | ||
from WPTParser.JSONParser.DataExtracter import DataExtracter | ||
|
||
class KeyDataExtracter(DataExtracter): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def extract(self, obj: dict, key: str): | ||
return obj.get(key, None) |
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,12 @@ | ||
from WPTParser.JSONParser.DataExtracter import DataExtracter | ||
|
||
class ListDataExtracter(DataExtracter): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def extract(self, list: list, index: int): | ||
try: | ||
return list[index] | ||
except KeyError as ex: | ||
return None |
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,14 @@ | ||
from WPTParser.JSONParser.DataExtracter import DataExtracter | ||
|
||
class ObjectListDataExtracter(DataExtracter): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def extract(self, obj_list: list, key: str): | ||
key = key.replace(' ', '') | ||
dict_key, dict_value = key.split('=') | ||
for obj in obj_list: | ||
if obj.get(dict_key, None) is not None and obj.get(dict_key) == dict_value: | ||
return obj | ||
return None |
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,15 @@ | ||
import unittest | ||
import os | ||
|
||
from WPTParser import WPTParser | ||
from WPTParser.Fetch import Fetch | ||
|
||
class FetchJSONTest(unittest.TestCase): | ||
|
||
def test_fetch_json(self): | ||
|
||
fetch = Fetch() | ||
self.assertNotEqual(fetch.json(), None) | ||
|
||
if __name__ == "__main__": | ||
unittest.main(verbosity=2) |
Empty file.