Skip to content

Commit

Permalink
upped with new xsds, and a few other details.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed May 17, 2024
1 parent abad389 commit 0717f77
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies = [
"pytz==2024.1",
"pyxb==1.2.6", #deprecated
"requests==2.31.0",
"xsdata[cli]==24.5",
"xsdata[cli]==24.2", # TODO upgrading results in Error: Circular Dependencies Found
"isoduration==20.11.0",
"lxml==5.2.2",
"json-stream==2.3.2",
Expand Down
5 changes: 4 additions & 1 deletion src/.xsdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
<Substitution type="package" search="^urn:vpro:gtaa:2017$" replace="thesaurus"/>
<Substitution type="package" search="^urn:vpro:media:search:2012$" replace="media_search"/>
<Substitution type="package" search="^urn:vpro:api:profile:2013$" replace="profile"/>



<Substitution type="package" search="^http://www.w3.org/XML/1998/namespace$" replace="xml"/>

<!--
<Substitution type="class" search="^data$" replace="npoapi.data.poms"/>
<Substitution type="class" search="AndType$" replace="AndTYPE"/>
Expand Down
21 changes: 16 additions & 5 deletions src/npoapi/bin/npo_media_follow_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import os
import time
from datetime import datetime
from datetime import datetime, timedelta
from sys import stdout

import json_stream
Expand All @@ -22,6 +22,8 @@ def __init__(self):
self.client.add_argument("--sleep", type=int, default=5, help="sleep (in seconds) between calls")
self.client.add_argument("--deletes", type=str, default="ID_ONLY")
self.client.add_argument("--tail", action='store_true')
self.client.add_argument("--tail-offset", type=int, default=0, help='extra millis to subtract from tail')

self.client.add_argument('-p', "--properties", type=str, default=None,
help="properties filtering")
self.client.add_argument("--raw", action='store_true', help="No attempts to stream and handle big results. Everything should fit in memory. Simpler, but less efficient.")
Expand All @@ -30,6 +32,8 @@ def __init__(self):

self.args = self.client.parse_args()

self.tail_offset = timedelta(milliseconds = self.args.tail_offset)

since = self.args.since
self.since_file = None
if since is None:
Expand All @@ -56,6 +60,7 @@ def __init__(self):
self.safe_since()
self.check_grow = False
if self.args.change_to_string == "CONCISE":
#self.change_to_string_function = " self.client.actualenv + ':' + str(change.get('publishDate')) + ':' + timestamp_to_string(change.get('publishDate')) + ':' + change.get('id', '') + ':' + title(change) + ':' + reasons(change)"
self.change_to_string_function = " self.client.actualenv + ':' + timestamp_to_string(change.get('publishDate')) + ':' + change.get('id', '') + ':' + title(change) + ':' + reasons(change)"
else:
self.change_to_string_function = self.args.change_to_string
Expand Down Expand Up @@ -140,8 +145,8 @@ def one_call(self):

self.logger.debug("%s One_calling for %s/%s/%s" % (datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ'), self.since['timestamp'], datetime.fromtimestamp(self.since['timestamp'] / 1000).strftime('%Y-%m-%dT%H:%M:%SZ'), self.since['mid']))
response = self.client.changes_raw(
profile=self.args.profile,
since=self.since['timestamp'],
profile = self.args.profile,
since = self.since['timestamp'],
since_mid = self.since['mid'],
properties=self.args.properties,
deletes=self.args.deletes,
Expand All @@ -165,11 +170,18 @@ def one_call(self):
count += 1
c = json_stream.to_standard_types(lazy_change)
new_since = c.get('publishDate')
is_tail = c.get('tail', False)
if is_tail:
if self.tail_offset.total_seconds() > 0:
prev_since = new_since
new_since -= int(self.tail_offset.total_seconds() * 1000)
self.logger.debug("Offsetting since %s -> %s" % (prev_since, new_since))
self.logger.debug("Setting since to %s (%s), (%s ms before now)" % (new_since, str(is_tail), int(datetime.now().timestamp() * 1000 - new_since)))
self.set_since(new_since, c.get('id', None))
if not new_since:
self.logger.error("No publishDate in %s" % c)
break
is_tail = c.get('tail', False)

if not is_tail or self.args.tail:
stdout.write(self.change_to_string(c) + "\n")
stdout.flush()
Expand Down Expand Up @@ -208,6 +220,5 @@ def follow_changes(self):
def media_follow_changes():
FollowChanges().follow_changes()


if __name__ == "__main__":
media_follow_changes()
2 changes: 2 additions & 0 deletions src/npoapi/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
SectionType,
)
from npoapi.data.pageupdate import (
DeleteResult,
EmbedUpdateType,
Image as PageupdateImage,
ImageLocationType as PageupdateImageLocationType,
Expand Down Expand Up @@ -688,6 +689,7 @@
"ReferralType",
"PageRelationType",
"SectionType",
"DeleteResult",
"EmbedUpdateType",
"PageupdateImage",
"PageupdateImageLocationType",
Expand Down
16 changes: 10 additions & 6 deletions src/npoapi/data/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ class ChannelEnum(Enum):
:cvar OU24: PO Out TV.
:cvar RAD1: NPO Radio 1.
:cvar RAD2: NPO Radio 2.
:cvar R2_SJ:
:cvar SENJ:
:cvar RAD3: NPO 3FM.
:cvar R3_KX:
:cvar KXFM:
:cvar R3_AL:
:cvar RAD4: NPO Radio 4.
:cvar R4_CO:
:cvar RAD5: NPO Radio 5.
:cvar R5_ST:
:cvar STNL:
:cvar RAD6: NPO Radio 6.
:cvar REGR: Regional radio combi-channel.
:cvar RFRY: Omrop Fryslân radio.
Expand Down Expand Up @@ -386,6 +386,7 @@ class ChannelEnum(Enum):
:cvar FUNJ: FunX Reggae
:cvar FUNS: FunX SlowJamz
:cvar FUNF: FunX Fissa
:cvar FUNO: FunX Afro
:cvar CLAS: Classic FM.
:cvar BEL1: VRT/Radio 1.
:cvar BEL2: VRT/Radio 2.
Expand Down Expand Up @@ -422,6 +423,7 @@ class ChannelEnum(Enum):
:cvar ALJI: Al Jazeera English
:cvar SPID: Spike Nederland
:cvar PRMT: Paramount Nederland
:cvar BLND: NPO BLend
:cvar XXXX: Test channel. This channel only exist for the sake of testing.
:cvar XXXY: Second test channel. This channel only exist for the sake of testing.
"""
Expand Down Expand Up @@ -649,14 +651,14 @@ class ChannelEnum(Enum):
OU24 = "OU24"
RAD1 = "RAD1"
RAD2 = "RAD2"
R2_SJ = "R2SJ"
SENJ = "SENJ"
RAD3 = "RAD3"
R3_KX = "R3KX"
KXFM = "KXFM"
R3_AL = "R3AL"
RAD4 = "RAD4"
R4_CO = "R4CO"
RAD5 = "RAD5"
R5_ST = "R5ST"
STNL = "STNL"
RAD6 = "RAD6"
REGR = "REGR"
RFRY = "RFRY"
Expand Down Expand Up @@ -695,6 +697,7 @@ class ChannelEnum(Enum):
FUNJ = "FUNJ"
FUNS = "FUNS"
FUNF = "FUNF"
FUNO = "FUNO"
CLAS = "CLAS"
BEL1 = "BEL1"
BEL2 = "BEL2"
Expand Down Expand Up @@ -731,6 +734,7 @@ class ChannelEnum(Enum):
ALJI = "ALJI"
SPID = "SPID"
PRMT = "PRMT"
BLND = "BLND"
XXXX = "XXXX"
XXXY = "XXXY"

Expand Down
10 changes: 9 additions & 1 deletion src/npoapi/data/mediaupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,25 @@ class Meta:
"type": "Attribute",
},
)
id: Optional[int] = field(
default=None,
metadata={
"type": "Attribute",
},
)


class MoveActionTypeType(Enum):
"""
:cvar REFERENCE: 'from' and 'to' refer to mediaobjects in the list by reference (e.g. mid).
:cvar NUMBER: Would refer to the number in the memberref object (presently unsupported)
:cvar NUMBER: Would refer to the number in the memberref object
:cvar REF_ID: Refers to the id of the memberref object
:cvar INDEX: 'from' and 'to' refer to the index (offset 0) of the mediaobject in the list.
"""

REFERENCE = "REFERENCE"
NUMBER = "NUMBER"
REF_ID = "REF_ID"
INDEX = "INDEX"


Expand Down
10 changes: 2 additions & 8 deletions src/npoapi/data/pageupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ class Meta:


@dataclass(slots=True)
class DeleteResult1:
class DeleteResult:
class Meta:
name = "deleteResult"
namespace = "urn:vpro:pages:update:2013"

value: str = field(
default="",
Expand Down Expand Up @@ -307,13 +308,6 @@ class Meta:
)


@dataclass(slots=True)
class Deleteresult(DeleteResult1):
class Meta:
name = "deleteresult"
namespace = "urn:vpro:pages:update:2013"


@dataclass(slots=True)
class Image(ImageUpdateType):
class Meta:
Expand Down
3 changes: 3 additions & 0 deletions src/npoapi/data/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SubtitlesWorkflowEnum(Enum):
FOR_REPUBLICATION = "FOR_REPUBLICATION"
PUBLISHED = "PUBLISHED"
PUBLISH_ERROR = "PUBLISH_ERROR"
MISSING = "MISSING"


class WorkflowEnumType(Enum):
Expand All @@ -88,6 +89,7 @@ class WorkflowEnumType(Enum):
:cvar MERGED:
:cvar IGNORE: This means that the object is ignored for workflow changes. This is mainly usefull during
testing.
:cvar TEMPORARY:
"""

FOR_PUBLICATION = "FOR PUBLICATION"
Expand All @@ -99,6 +101,7 @@ class WorkflowEnumType(Enum):
DELETED = "DELETED"
MERGED = "MERGED"
IGNORE = "IGNORE"
TEMPORARY = "TEMPORARY"


@dataclass(slots=True)
Expand Down
7 changes: 7 additions & 0 deletions src/npoapi/data/xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from enum import Enum

__NAMESPACE__ = "http://www.w3.org/XML/1998/namespace"


class LangValue(Enum):
VALUE = ""
4 changes: 3 additions & 1 deletion src/npoapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ def changes_raw(self, profile=None, order="ASC", stream=False, limit=None,
sinceLong = since


publishedSince = (sinceDate + (("," + str(since_mid)) if since_mid else "")) if sinceDate else None;
self.logger.debug("publishedSince: (%s, %s)" % ( publishedSince, sinceLong))
params = { "profile": profile, "order": order, "max": limit,
"since": sinceLong,
"publishedSince": (sinceDate + (("," + str(since_mid)) if since_mid else "")) if sinceDate else None,
"publishedSince": publishedSince,
"properties": properties,
"deletes": deletes,
"tail": tail,
Expand Down
1 change: 1 addition & 0 deletions src/npoapi/npoapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def stream(self, path: str, params=None, accept=None, data=None, content_type: s
if effective_accept is not None:
req.add_header("Accept", effective_accept)
self.logger.debug("headers: %s" % str(req.headers))
self.logger.debug("url: %s" % url)
return self.get_response(req, url, ignore_not_found=ignore_not_found, timeout=timeout)

def __str__(self) -> str:
Expand Down

0 comments on commit 0717f77

Please sign in to comment.