ilpost-api-wrapper 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ilpost-api-wrapper
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Python wrapper for Il Post newspaper API
5
5
  Author: Antonio Girasella
6
6
  License-Expression: MIT
@@ -13,17 +13,19 @@ _BASE_URL = "https://api.ilpost.org/search/api/site_search/"
13
13
 
14
14
  def _build_filters(
15
15
  content_type: Optional[ContentType] = None,
16
- category: Optional[str] = None,
16
+ category: Optional[Union[str, list[str]]] = None,
17
17
  date_range: Optional[DateRange] = None,
18
18
  ) -> str:
19
19
  parts: list[str] = []
20
20
  if content_type is not None:
21
21
  parts.append(f"ctype:{content_type.value}")
22
22
  if category is not None:
23
- parts.append(f"category:{category}")
23
+ cats = [category] if isinstance(category, str) else category
24
+ for cat in cats:
25
+ parts.append(f"category:{cat}")
24
26
  if date_range is not None:
25
27
  parts.append(f"pub_date:{date_range.value}")
26
- return ",".join(parts)
28
+ return ";".join(parts)
27
29
 
28
30
 
29
31
  class IlPostClient:
@@ -52,7 +54,7 @@ class IlPostClient:
52
54
  hits: int = 10,
53
55
  sort: Union[SortOrder, str] = SortOrder.RELEVANCE,
54
56
  content_type: Optional[ContentType] = None,
55
- category: Optional[str] = None,
57
+ category: Optional[Union[str, list[str]]] = None,
56
58
  date_range: Optional[DateRange] = None,
57
59
  filters: Optional[str] = None,
58
60
  ) -> SearchResult:
@@ -61,7 +63,18 @@ class IlPostClient:
61
63
  Parameters
62
64
  ----------
63
65
  query:
64
- Search term.
66
+ Search term. Supports:
67
+
68
+ - Exact phrase: ``'"goffredo fofi"'``
69
+ - Boolean OR: ``"fofi | berlusconi"`` (``|`` and ``OR`` both work)
70
+ - Boolean AND: ``"fofi AND berlusconi"`` or just ``"fofi berlusconi"``
71
+ - Boolean NOT: ``"berlusconi NOT fininvest"``
72
+
73
+ The following syntax does **not** work and should be avoided:
74
+
75
+ - Field prefix (``title:fofi``, ``content:fofi``) — treated as literal tokens
76
+ - Boost operator (``berlusconi^10``) — the numeric value becomes a search token
77
+ - Proximity queries (``"goffredo fofi"~5``) — inflates results unpredictably
65
78
  page:
66
79
  1-based page number (default: 1).
67
80
  hits:
@@ -73,15 +86,17 @@ class IlPostClient:
73
86
  Filter by content type: ``ContentType.ARTICLES``, ``ContentType.PODCASTS``,
74
87
  or ``ContentType.NEWSLETTERS``.
75
88
  category:
76
- Filter articles by editorial category (e.g. ``"politica"``, ``"cultura"``).
77
- Only meaningful when ``content_type=ContentType.ARTICLES`` or no content
78
- type filter is set.
89
+ Filter articles by editorial category. Pass a single string
90
+ (e.g. ``"politica"``) or a list to AND multiple categories together
91
+ (e.g. ``["cultura", "libri"]``). Only meaningful when
92
+ ``content_type=ContentType.ARTICLES`` or no content type filter is set.
79
93
  date_range:
80
94
  Filter by publication date: ``DateRange.ALL_TIME``, ``DateRange.PAST_YEAR``,
81
95
  or ``DateRange.PAST_30_DAYS``.
82
96
  filters:
83
- Raw pre-encoded filter string (e.g. ``"ctype:articoli,pub_date:ultimo_anno"``).
84
- When provided, overrides ``content_type``, ``category``, and ``date_range``.
97
+ Raw pre-encoded filter string (e.g. ``"ctype:articoli;pub_date:ultimo_anno"``).
98
+ Filters are separated by ``;``. When provided, overrides ``content_type``,
99
+ ``category``, and ``date_range``.
85
100
 
86
101
  Returns
87
102
  -------
@@ -110,7 +125,7 @@ class IlPostClient:
110
125
  page: int = 1,
111
126
  hits: int = 10,
112
127
  sort: Union[SortOrder, str] = SortOrder.RELEVANCE,
113
- category: Optional[str] = None,
128
+ category: Optional[Union[str, list[str]]] = None,
114
129
  date_range: Optional[DateRange] = None,
115
130
  ) -> SearchResult:
116
131
  """Search articles only. Convenience wrapper around :meth:`search`."""
@@ -169,7 +184,7 @@ class IlPostClient:
169
184
  hits: int = 10,
170
185
  sort: Union[SortOrder, str] = SortOrder.RELEVANCE,
171
186
  content_type: Optional[ContentType] = None,
172
- category: Optional[str] = None,
187
+ category: Optional[Union[str, list[str]]] = None,
173
188
  date_range: Optional[DateRange] = None,
174
189
  max_pages: Optional[int] = None,
175
190
  ):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ilpost-api-wrapper
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Python wrapper for Il Post newspaper API
5
5
  Author: Antonio Girasella
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ilpost-api-wrapper"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "Python wrapper for Il Post newspaper API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"