Browse Source

Log warnings; use rvslots when fetching revision content

tags/v0.3
Ben Kurtovic 5 years ago
parent
commit
f1b93a465a
3 changed files with 23 additions and 7 deletions
  1. +4
    -1
      CHANGELOG
  2. +7
    -5
      earwigbot/wiki/page.py
  3. +12
    -1
      earwigbot/wiki/site.py

+ 4
- 1
CHANGELOG View File

@@ -1,7 +1,8 @@
v0.3 (unreleased): v0.3 (unreleased):


- Added various new features to the WikiProjectTagger task. - Added various new features to the WikiProjectTagger task.
- Copyvio detector: improved sentence splitting algorithm.
- Copyvio detector: improved sentence splitting algorithm; many performance
improvements.
- Improved config file command/task exclusion logic. - Improved config file command/task exclusion logic.
- IRC > !cidr: Added; new command for calculating range blocks. - IRC > !cidr: Added; new command for calculating range blocks.
- IRC > !notes: Improved help and added aliases. - IRC > !notes: Improved help and added aliases.
@@ -13,6 +14,8 @@ v0.3 (unreleased):
- IRC: Try not to join channels before NickServ auth has completed. - IRC: Try not to join channels before NickServ auth has completed.
- IRC: Improved detection of maximum IRC message length. - IRC: Improved detection of maximum IRC message length.
- IRC: Improved some help commands. - IRC: Improved some help commands.
- Wiki: Added logging for warnings.
- Wiki: Updated some deprecated API calls.
- Wiki: Fixed Page.toggle_talk() behavior on mainspace titles with colons. - Wiki: Fixed Page.toggle_talk() behavior on mainspace titles with colons.


v0.2 (released November 8, 2015): v0.2 (released November 8, 2015):


+ 7
- 5
earwigbot/wiki/page.py View File

@@ -264,13 +264,15 @@ class Page(CopyvioMixIn):
if not result: if not result:
query = self.site.api_query query = self.site.api_query
result = query(action="query", prop="revisions", rvlimit=1, result = query(action="query", prop="revisions", rvlimit=1,
rvprop="content|timestamp", titles=self._title)
rvprop="content|timestamp", rvslots="main",
titles=self._title)


res = result["query"]["pages"].values()[0] res = result["query"]["pages"].values()[0]
try: try:
self._content = res["revisions"][0]["*"]
self._basetimestamp = res["revisions"][0]["timestamp"]
except KeyError:
revision = res["revisions"][0]
self._content = revision["slots"]["main"]["*"]
self._basetimestamp = revision["timestamp"]
except (KeyError, IndexError):
# This can only happen if the page was deleted since we last called # This can only happen if the page was deleted since we last called
# self._load_attributes(). In that case, some of our attributes are # self._load_attributes(). In that case, some of our attributes are
# outdated, so force another self._load_attributes(): # outdated, so force another self._load_attributes():
@@ -582,7 +584,7 @@ class Page(CopyvioMixIn):
query = self.site.api_query query = self.site.api_query
result = query(action="query", rvlimit=1, titles=self._title, result = query(action="query", rvlimit=1, titles=self._title,
prop="info|revisions", inprop="protection|url", prop="info|revisions", inprop="protection|url",
rvprop="content|timestamp")
rvprop="content|timestamp", rvslots="main")
self._load_attributes(result=result) self._load_attributes(result=result)
self._assert_existence() self._assert_existence()
self._load_content(result=result) self._load_content(result=result)


+ 12
- 1
earwigbot/wiki/site.py View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Copyright (C) 2009-2017 Ben Kurtovic <ben.kurtovic@gmail.com>
# Copyright (C) 2009-2019 Ben Kurtovic <ben.kurtovic@gmail.com>
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@@ -298,6 +298,17 @@ class Site(object):
e = "API query failed: JSON could not be decoded." e = "API query failed: JSON could not be decoded."
raise exceptions.APIError(e) raise exceptions.APIError(e)


if "warnings" in res:
for name, value in res["warnings"].items():
try:
warning = value["warnings"]
except KeyError:
try:
warning = value["*"]
except KeyError:
warning = value
self._logger.warning("API warning: %s: %s", name, warning)

try: try:
code = res["error"]["code"] code = res["error"]["code"]
info = res["error"]["info"] info = res["error"]["info"]


Loading…
Cancel
Save