-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates version to 0.1.0. Tests API listener and state storage. Minim…
…al documentation.
- Loading branch information
Showing
11 changed files
with
303 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,40 @@ | ||
MediaWiki events | ||
================ | ||
Wiki-tool builders & researchers rely on various sources of information about what's happened and is currently happening in Wikipedia. These data sources tend to be structured in differently and contain incomplete or poorly structured information. Some datasources are queryable, but require complexity to "listen" to ongoing events while others are intended to only be used to "listen" to current events. ''MediaWiki events'' is designed to minimize the frustration involved in process MediaWiki's events. | ||
Wiki-tool builders & researchers rely on various sources of information about what's happened and is currently happening in Wikipedia. These data sources tend to be structured in differently and contain incomplete or poorly structured information. Some datasources are queryable, but require complexity to "listen" to ongoing events while others are intended to only be used to "listen" to current events. ''MediaWiki events'' is designed to minimize the frustration involved in process MediaWiki's events. | ||
|
||
|
||
**Instal with pip:** ``pip install mwevents`` | ||
|
||
**Note:** *Use of this library requires Python 3 or later.* | ||
|
||
**Documentation:** *Comming soon!* | ||
|
||
:Example: | ||
|
||
.. code-block:: python | ||
from mwevents.sources import API | ||
from mwevents import RevisionSaved, PageCreated | ||
api_source = API.from_api_url("http://en.wikipedia.org/w/api.php") | ||
listener = api_source.listener(events={RevisionSaved, PageCreated}) | ||
for event in listener: | ||
if isinstance(event, RevisionSaved): | ||
print(event.revision) | ||
else: # isinstance(event, PageCreated): | ||
print(event.page) | ||
About the author | ||
================ | ||
:name: | ||
Aaron Halfaker | ||
:email: | ||
[email protected] | ||
:website: | ||
http://halfaker.info -- | ||
http://en.wikipedia.org/wiki/User:EpochFail | ||
|
||
Contributors | ||
============ | ||
None yet. See http://github.com/halfak/MediaWiki-events. Pull requests are encouraged. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.3 | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
from .types import * | ||
from .types.events import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
class Source: | ||
|
||
def listen(self, *args, **kwargs): | ||
raise NotImplementedError() | ||
|
||
def query(self, start, end, *args, types=None, **kwargs): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
from jsonable import JSONable | ||
|
||
from .timestamp import Timestamp | ||
|
||
|
||
class StateMarker(JSONable): | ||
__slots__ = ("last_event", "last_rev_id", "last_rc_id", "last_log_id") | ||
def initialize(self, last_event=None, last_rc_id=None, | ||
last_rev_id=None, last_log_id=None): | ||
self.last_event = Timestamp(last_event) \ | ||
if last_event is not None else None | ||
self.last_rc_id = int(last_rc_id) \ | ||
if last_rc_id is not None else None | ||
self.last_rev_id = int(last_rev_id) \ | ||
if last_rev_id is not None else None | ||
self.last_log_id = int(last_log_id) \ | ||
if last_log_id is not None else None | ||
|
||
def update(self, timestamp, rc_id, rev_id, log_id): | ||
self.last_event = timestamp or self.last_event | ||
self.last_rc_id = rc_id or self.last_rc_id | ||
self.last_rev_id = rev_id or self.last_rev_id | ||
self.last_log_id = log_id or self.last_log_id | ||
|
||
def is_after(self, timestamp, rc_id, rev_id, log_id): | ||
timestamp = Timestamp(timestamp) | ||
|
||
return (self.last_event is not None and | ||
timestamp > self.last_event) or\ | ||
( | ||
(self.last_event is None or | ||
timestamp == self.last_event) and | ||
( | ||
(rc_id is not None and | ||
rc_id > (self.last_rc_id or 0)) or\ | ||
(rev_id is not None and | ||
rev_id > (self.last_rev_id or 0)) or\ | ||
(log_id is not None and | ||
log_id > (self.last_log_id or 0)) | ||
) | ||
) |
Oops, something went wrong.