mirror of
https://github.com/resf/distro-tools.git
synced 2024-11-17 10:41:28 +00:00
Change User-Agent for rherrata client
This commit is contained in:
parent
b336ffa23c
commit
136f90bd44
@ -18,6 +18,7 @@ class DocumentKind(str, Enum):
|
|||||||
"""
|
"""
|
||||||
The kind of document.
|
The kind of document.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ERRATA = "Errata"
|
ERRATA = "Errata"
|
||||||
|
|
||||||
|
|
||||||
@ -25,6 +26,7 @@ class Distro(str, Enum):
|
|||||||
"""
|
"""
|
||||||
The distribution.
|
The distribution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RHEL = "Red Hat Enterprise Linux"
|
RHEL = "Red Hat Enterprise Linux"
|
||||||
|
|
||||||
|
|
||||||
@ -32,6 +34,7 @@ class Architecture(str, Enum):
|
|||||||
"""
|
"""
|
||||||
The architecture.
|
The architecture.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
X86_64 = "x86_64"
|
X86_64 = "x86_64"
|
||||||
AARCH64 = "aarch64"
|
AARCH64 = "aarch64"
|
||||||
PPC64 = "ppc64"
|
PPC64 = "ppc64"
|
||||||
@ -44,6 +47,7 @@ class PortalProduct:
|
|||||||
"""
|
"""
|
||||||
Red Hat advisory product
|
Red Hat advisory product
|
||||||
"""
|
"""
|
||||||
|
|
||||||
variant: str
|
variant: str
|
||||||
name: str
|
name: str
|
||||||
major_version: int
|
major_version: int
|
||||||
@ -56,6 +60,7 @@ class Advisory(JSONWizard):
|
|||||||
"""
|
"""
|
||||||
An advisory.
|
An advisory.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
documentKind: str = None
|
documentKind: str = None
|
||||||
uri: str = None
|
uri: str = None
|
||||||
view_uri: str = None
|
view_uri: str = None
|
||||||
@ -110,9 +115,7 @@ class Advisory(JSONWizard):
|
|||||||
major_version = int(version)
|
major_version = int(version)
|
||||||
minor_version = None
|
minor_version = None
|
||||||
self.__products.append(
|
self.__products.append(
|
||||||
PortalProduct(
|
PortalProduct(variant, name, major_version, minor_version, arch)
|
||||||
variant, name, major_version, minor_version, arch
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
@ -156,7 +159,7 @@ class API:
|
|||||||
query: str = "*:*",
|
query: str = "*:*",
|
||||||
distro: str = "Red%5C+Hat%5C+Enterprise%5C+Linux%7C%2A%7C%2A%7C%2A",
|
distro: str = "Red%5C+Hat%5C+Enterprise%5C+Linux%7C%2A%7C%2A%7C%2A",
|
||||||
detected_product: str = "rhel",
|
detected_product: str = "rhel",
|
||||||
from_date: str = None
|
from_date: str = None,
|
||||||
) -> list[Advisory]:
|
) -> list[Advisory]:
|
||||||
params = ""
|
params = ""
|
||||||
|
|
||||||
@ -167,7 +170,11 @@ class API:
|
|||||||
params += f"&rows={rows}"
|
params += f"&rows={rows}"
|
||||||
|
|
||||||
# Set sorting
|
# Set sorting
|
||||||
sorting = "portal_publication_date+asc" if sort_asc else "portal_publication_date+desc"
|
sorting = (
|
||||||
|
"portal_publication_date+asc"
|
||||||
|
if sort_asc
|
||||||
|
else "portal_publication_date+desc"
|
||||||
|
)
|
||||||
params += f"&sort={sorting}"
|
params += f"&sort={sorting}"
|
||||||
|
|
||||||
# Set start
|
# Set start
|
||||||
@ -178,7 +185,9 @@ class API:
|
|||||||
|
|
||||||
# Set from-to
|
# Set from-to
|
||||||
if from_date:
|
if from_date:
|
||||||
params += f"&fq=portal_publication_date%3A%5B{quote(from_date)}%20TO%20NOW%5D"
|
params += (
|
||||||
|
f"&fq=portal_publication_date%3A%5B{quote(from_date)}%20TO%20NOW%5D"
|
||||||
|
)
|
||||||
|
|
||||||
# Set document kind
|
# Set document kind
|
||||||
params += f"&fq=documentKind:{kind.value}"
|
params += f"&fq=documentKind:{kind.value}"
|
||||||
@ -189,7 +198,10 @@ class API:
|
|||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(
|
async with session.get(
|
||||||
URL(f"{self.url}?{params}", encoded=True)
|
URL(f"{self.url}?{params}", encoded=True),
|
||||||
|
headers={
|
||||||
|
"User-Agent": "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"
|
||||||
|
},
|
||||||
) as response:
|
) as response:
|
||||||
body = await response.json()
|
body = await response.json()
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
|
Loading…
Reference in New Issue
Block a user