-
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.
- Loading branch information
1 parent
b0ee06d
commit 7ef9aa0
Showing
3 changed files
with
70 additions
and
35 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 |
---|---|---|
|
@@ -142,3 +142,4 @@ dmypy.json | |
*.bk | ||
cnt/* | ||
tar/ | ||
cer-feeds.json |
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,37 @@ | ||
"""Helpers for processing feed specification data.""" | ||
|
||
# pylint: disable=E0611,R0902 | ||
|
||
import json | ||
import logging | ||
|
||
from pydantic.dataclasses import dataclass | ||
from pydantic.tools import parse_obj_as | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@dataclass | ||
class FeedSpec: | ||
pair: str | ||
label: str | ||
interval: int | ||
deviation: int | ||
source: str | ||
calculation: str | ||
status: str | ||
type: str = "CER" | ||
|
||
|
||
async def read_feeds_file(feeds_file: str) -> list[FeedSpec]: | ||
""" "Read feed data into memory for use in the script.""" | ||
feed_dict = None | ||
with open(feeds_file, "r", encoding="utf-8") as json_feeds: | ||
feed_dict = json.loads(json_feeds.read()) | ||
logger.info("cer-feeds version: %s", feed_dict["meta"]["version"]) | ||
logger.info("number of feeds: %s", len(feed_dict["feeds"])) | ||
feeds = [] | ||
for item in feed_dict["feeds"]: | ||
feed = parse_obj_as(FeedSpec, item) | ||
feeds.append(feed) | ||
return feeds |