@@ -74,9 +74,10 @@ def list_(self, category: str | int, amount: int = None) -> list | None:
7474 # /search endpoint
7575 def search (self , query : str | int , amount : int = 1 ) -> dict | None :
7676 """The `/search` endpoint lets you search for a circular by its name or ID"""
77- if query .isdigit () and len (query ) == 4 :
78- query = int (query )
79- elif type (query ) is not str :
77+ if type (query ) is str :
78+ if query .isdigit () and len (query ) == 4 :
79+ query = int (query )
80+ elif type (query ) is not int :
8081 raise ValueError ("Invalid Query. It isn't string" )
8182
8283 params = {'query' : query , 'amount' : amount }
@@ -92,7 +93,7 @@ def search(self, query: str | int, amount: int = 1) -> dict | None:
9293 # /getpng endpoint
9394 def getpng (self , url : str ) -> list | None :
9495 """The `/getpng` endpoint lets you get the pngs from a circular"""
95- if type (url ) != str :
96+ if type (url ) is not str :
9697 raise ValueError ("Invalid URL. It isn't string." )
9798
9899 params = {'url' : url }
@@ -115,15 +116,15 @@ def __init__(
115116 ):
116117 self .api_url = api_url
117118 self .fallback_api_url = fallback_api_url
118- self .category = category
119+ self .category = str ( category ) if type ( category ) is None else category
119120 self .cache_method = cache_method
120121
121122 # Get category names from API
122123 categories = self ._send_api_request ("categories" )
123124
124125 # If this circular checker is supposed to be for a specific category of circulars only
125126 # Check if the category name or id is valid
126- if category is not None :
127+ if category != ' None' :
127128 if type (self .category ) is int :
128129 if not _min_category_id <= self .category :
129130 raise ValueError ("Invalid category Number" )
@@ -182,7 +183,7 @@ def __init__(
182183 cur .execute (
183184 f"""
184185 CREATE TABLE IF NOT EXISTS { self .db_table } (
185- category VARCHAR(15) PRIMARY KEY,
186+ category VARCHAR(15) PRIMARY KEY NOT NULL UNIQUE ,
186187 latest_circular_id INTEGER
187188 )
188189 """
@@ -267,8 +268,8 @@ def _set_cache(self, circular_id: int):
267268 # Method to check for new circulars
268269 def check (self ) -> list [dict ] | list :
269270
270- if cache := self .get_cache () is not None :
271- res = self ._send_api_request (f'new-circulars/{ cache } ' )
271+ if ( cached_circular_id := self .get_cache () ) is not None :
272+ res = self ._send_api_request (f'new-circulars/{ cached_circular_id } ' )
272273 else :
273274 res = self ._send_api_request ('new-circulars/' )
274275 # it's sorted in descending order
@@ -277,6 +278,9 @@ def check(self) -> list[dict] | list:
277278 if len (res ) > 0 :
278279 self ._set_cache (res [0 ]['id' ])
279280
281+ if cached_circular_id is None :
282+ return []
283+
280284 # If this circular-checker is meant for only one category,
281285 # remove circulars of any other category
282286 if self .category :
0 commit comments