purodha(a)svn.wikimedia.org ha scritto:
> Revision: 6942
> Author: purodha
> Date: 2009-06-07 05:24:19 +0000 (Sun, 07 Jun 2009)
>
> Log Message:
> -----------
> Initial version of a recentchenges page generator (via API)
>
[...]
> + def recentchanges(self, number = 100, rcstart = None, rcend = None, rcshow = None, rctype ='edit|new', repeat = False):
> + """
> + Yield ImagePages from APIs, call: action=query&list=recentchanges&rctype=edit|new&rclimit=500
Yield Pages. API. URL may be removed.
> +
> + Options directly from APIs:
API.
> + while True:
> + data = query.GetData(params,
> + useAPI = True, encodeTitle = False)
A site parameter to GetData() call should be added, else it works only
with default family and language.
Probably in query module the old Query API support may be removed, so
'useAPI' parameter becomes useless.
> + try:
> + rcData = data['query']['recentchanges']
> + except KeyError:
> + raise ServerError("The APIs don't return data, the site may be down")
"MediaWiki API doesn't"
Probably this code should be adapted and noved to GetData() function in
query module.
> + for rcItem in rcData:
> + try:
> + comment = rcItem['comment']
> + except KeyError:
> + comment = ''
comment = ''
if 'comment' in rcItem:
comment = ...
> + try:
> + loginfo = rcItem['loginfo']
> + except KeyError:
> + loginfo = ''
as suggested above
> + if not repeat:
> + break
> +
'repeat' parameter should be removed (and the same in others Site methods).
--
Francesco Cosoleto
«Non dee l'uomo, per maggiore amico, dimenticare li servigi ricevuti dal
minore». (Dante Alighieri, Convivio, II, 65)
erwin85(a)svn.wikimedia.org ha scritto:
> Revision: 6937
> Author: erwin85
> Date: 2009-06-04 20:13:15 +0000 (Thu, 04 Jun 2009)
>
> Log Message:
> -----------
> getVersionHistory: "go=first" doesn't seem to do anything. Replaced with "dir=prev".
>
[...]
>
> if reverseOrder:
> - if len(self._versionhistoryearliest) >= revCount:
> - path += '&dir=prev'
> - else:
> - path += '&go=first'
> + path += '&dir=prev'
>
> if startFromPage:
> path += '&offset=' + startFromPage
>
Seems it does something.
>>> import wikipedia
>>> s = wikipedia.getSite('it', 'wikipedia')
>>> p = wikipedia.Page(s, u"Italia")
>>> z = p.getVersionHistory(reverseOrder = True, revCount = 1000)
>>> z[0]
(u'9739640', u'13:28, 8 lug 2007', u'F l a n k e r', u'<a
href="/wiki/Italia#Emblema_della_Repubblica"
title="Italia">\u2192</a>Emblema della Repubblica')
>>> z[999]
(u'24483834', u'21:19, 4 giu 2009', u'Sannita', u'<a
href="/wiki/Wikipedia:Sezione_iniziale#Citazioni_della_sezione_iniziale_o_nell.27incipit"
title="Wikipedia:Sezione
iniziale">Wikipedia:Sezione_iniziale#Citazioni_della_sezione_iniziale_o_nell'incipit</a>')
Updated version:
>>> import wikipedia
>>> s = wikipedia.getSite('it', 'wikipedia')
>>> p = wikipedia.Page(s, u"Italia")
>>> z = p.getVersionHistory(reverseOrder = True, revCount = 1000)
>>> z[0]
(u'3586', u'11:46, 5 ott 2003', u'Pietro', u'Festivit\xe0')
>>> z[999]
(u'8783918', u'18:41, 17 mag 2007', u'84.222.20.9', u'<a
href="/wiki/Italia#Lingue" title="Italia">\u2192</a>Lingue')
--
Francesco Cosoleto
"O cari, chi tra gli Argivi è il migliore, e chi è mediocre
e chi vale pochissimo - poi che non son tutti uguali
gli uomini in guerra - or venne lavoro per tutti.
E lo capite da voi." (Omero)