Source code for pywikibot.echo

# -*- coding: utf-8 -*-
"""Classes and functions for working with the Echo extension."""
# (C) Pywikibot team, 2014-2020
# Distributed under the terms of the MIT license.
import pywikibot

from import deprecated

[docs]class Notification: """A notification issued by the Echo extension."""
[docs] def __init__(self, site): """Initialize an empty Notification object.""" = site
[docs] @classmethod def fromJSON(cls, site, data): """ Construct a Notification object from JSON data returned by the API. @rtype: Notification """ 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: = pywikibot.Page(site, data['title']['full']) except KeyError: = None try: notif.agent = pywikibot.User(site, data['agent']['name']) except KeyError: notif.agent = None try: = pywikibot.Timestamp.fromtimestampformat(data['read']) except KeyError: = False notif.content = data.get('*', None) notif.revid = data.get('revid', None) return notif
@property @deprecated('event_id', since='20190106') def id(self): """ DEPRECATED: Return notification id as unicode. @rtype: str """ return str(self.event_id)
[docs] def mark_as_read(self): """Mark the notification as read.""" return