"""Classes and functions for working with the Echo extension."""## (C) Pywikibot team, 2014-2022## Distributed under the terms of the MIT license.#from__future__importannotationsfromtypingimportAnyimportpywikibot
[docs]classNotification:"""A notification issued by the Echo extension."""def__init__(self,site:pywikibot.site.BaseSite)->None:"""Initialize an empty Notification object."""self.site=siteself.event_id:int|None=Noneself.type=Noneself.category=Noneself.timestamp=Noneself.page=Noneself.agent=Noneself.read:bool|None=Noneself.content=Noneself.revid=None
[docs]@classmethoddeffromJSON(cls,# noqa: N802site:pywikibot.site.BaseSite,data:dict[str,Any])->Notification:"""Construct a Notification object from our API's JSON data."""notif=cls(site)notif.event_id=int(data['id'])notif.type=data['type']notif.category=data['category']notif.timestamp=pywikibot.Timestamp.fromtimestampformat(data['timestamp']['mw'])try:notif.page=pywikibot.Page(site,data['title']['full'])exceptKeyError:notif.page=Nonetry:notif.agent=pywikibot.User(site,data['agent']['name'])exceptKeyError:notif.agent=Nonetry:notif.read=pywikibot.Timestamp.fromtimestampformat(data['read'])exceptKeyError:notif.read=Falsenotif.content=data.get('*')notif.revid=data.get('revid')returnnotif
[docs]defmark_as_read(self)->bool:"""Mark the notification as read."""returnself.site.notifications_mark_read(list=self.id)