]> git.rocketbowman.com Git - nom.git/commitdiff
convert dataclasses to pydantic BaseModels
authorKyle Bowman <kyle+github@rocketbowman.com>
Mon, 20 Jan 2025 21:33:48 +0000 (16:33 -0500)
committerKyle Bowman <kyle+github@rocketbowman.com>
Mon, 20 Jan 2025 21:35:08 +0000 (16:35 -0500)
requirements.txt
src/nom/base.py
src/nom/entry.py
src/nom/feed.py

index cff1edf90d240d4e0c3d6aa21a9ba5aa49240927..4cd8502eee120be475c69db3d493600323c0e589 100644 (file)
@@ -1,7 +1,18 @@
+annotated-types==0.7.0
 certifi==2024.12.14
 charset-normalizer==3.4.1
-feedparser==6.0.11
+feedparser==6.0.0
 idna==3.10
+iniconfig==2.0.0
+# Editable Git install (nom==0.0.1) with either a deleted local remote or invalid URI:
+# 'git@goddard.local:/srv/git/nom.git'
+-e /home/kyle/projects/nom
+packaging==24.2
+pluggy==1.5.0
+pydantic==2.10.5
+pydantic_core==2.27.2
+pytest==8.3.4
 requests==2.32.3
 sgmllib3k==1.0.0
+typing_extensions==4.12.2
 urllib3==2.3.0
index bcbbc4103e0cec0a8fa5043417814947ade41ab8..c8b3c14e89480b42513e572a422f4d8897910401 100644 (file)
@@ -2,11 +2,12 @@ from abc import abstractmethod
 from csv import DictReader, DictWriter, excel_tab
 from copy import copy
 from pathlib import Path
+from pydantic import BaseModel
 
 from nom.utils import NomError
 
 
-class NomListItem:
+class NomListItem(BaseModel):
 
     @abstractmethod
     def __hash__(self):
@@ -15,7 +16,7 @@ class NomListItem:
     
     @classmethod
     def get_fieldnames(cls):
-        return cls.__dataclass_fields__.keys()
+        return cls.__fields__.keys()
     
     # TODO: What if there's a pipe in one of the fields? 
     def to_str(self, delimiter: str ='|'):
index 3ef20d84f57bf148780604fefe83eaff1d3881a4..7116944adebb40e9074e1a4aca238de623341785 100644 (file)
@@ -1,4 +1,3 @@
-from dataclasses import dataclass
 from pathlib import Path
 from typing import Optional
 
@@ -7,7 +6,6 @@ from nom.base import NomList, NomListItem
 
 
 # TODO: Use proper types, not strings. (Pydantic?)
-@dataclass 
 class EntryListItem(NomListItem):
     title: str
     url: str  
index 923f9dece94f52a42b6ad8f49799b0cfc243b353..b4324d2ed4161bc0521cca5e258f21961d8f8c48 100644 (file)
@@ -1,7 +1,6 @@
 import os
 from pathlib import Path
 from typing import Optional
-from dataclasses import dataclass
 
 import feedparser
 import requests
@@ -16,20 +15,24 @@ class Feed:
     def __init__(self, feedparsable):
         d = feedparser.parse(feedparsable)
         self.name       = d.feed.title
-        self.url        = d.feed.link # how is this different from d.feed.link?
+        self.url        = d.feed.link 
         self.entries    = d.entries 
     
     def to_entrylist(self)->EntryList:
         items = []
         for e in self.entries:
             entry = EntryListItem(
-                e.title, e.link, e.updated, 
-                self.url, "no alias", "False", "no summary")
+                title=e.title, 
+                url=e.link, 
+                date=e.updated, 
+                feed_url=self.url, 
+                feed_alias="no alias", 
+                viewed="False", 
+                summary="no summary")
             items.append(entry)
         return EntryList(items=items)
 
 
-@dataclass
 class FeedListItem(NomListItem):
     url: str