Revision: 7278
Author: multichill
Date: 2009-09-19 13:00:22 +0000 (Sat, 19 Sep 2009)
Log Message:
-----------
Fixing pywikipediabot-Bugs-2861515:
* Have to get an edittoken now
* Set the destination filename
Modified Paths:
--------------
trunk/pywikipedia/upload.py
Modified: trunk/pywikipedia/upload.py
===================================================================
--- trunk/pywikipedia/upload.py 2009-09-18 22:45:30 UTC (rev 7277)
+++ trunk/pywikipedia/upload.py 2009-09-19 13:00:22 UTC (rev 7278)
@@ -223,6 +223,12 @@
if self.ignoreWarning:
formdata["wpIgnoreWarning"] = "1"
+ # Get an edit token so we can do the upload
+ formdata["wpEditToken"] = self.targetSite.getToken()
+
+ # Set the new filename
+ formdata["wpDestFile"] = encodedFilename
+
# try to encode the strings to the encoding used by the target site.
# if that's not possible (e.g. because there are non-Latin-1 characters and
# the home Wikipedia uses Latin-1), convert all non-ASCII characters to
Revision: 7271
Author: russblau
Date: 2009-09-17 18:33:18 +0000 (Thu, 17 Sep 2009)
Log Message:
-----------
Fix arg-handling bug.
Modified Paths:
--------------
branches/rewrite/scripts/imageuncat.py
Modified: branches/rewrite/scripts/imageuncat.py
===================================================================
--- branches/rewrite/scripts/imageuncat.py 2009-09-17 18:03:22 UTC (rev 7270)
+++ branches/rewrite/scripts/imageuncat.py 2009-09-17 18:33:18 UTC (rev 7271)
@@ -1267,13 +1267,15 @@
'''
Return a pagegenerator containing all the images edited in a certain timespan.
The delay is the amount of minutes to wait and the block is the timespan to return images in.
- Should probably copied to somewhere else
+ Should probably be copied to somewhere else
+
'''
-
rcstart = site.getcurrenttime() + timedelta(minutes=-delay-block)
rcend = site.getcurrenttime() + timedelta(minutes=-delay)
- gen = site.recentchanges(start=rcstart, end=rcend, reverse=True, namespaces=6, changetype='edit|log', showBot=False)
+ gen = site.recentchanges(start=rcstart, end=rcend, reverse=True,
+ namespaces=6, changetype='edit|log',
+ showBot=False)
# remove 'patrolled' from rcprop since we can't get it
gen.request['rcprop'] = 'title|user|comment|ids'
for p in gen:
@@ -1283,7 +1285,8 @@
'''
Do we want to skip this page?
- If we found a category which is not in the ignore list it means that the page is categorized so skip the page.
+ If we found a category which is not in the ignore list it means
+ that the page is categorized so skip the page.
If we found a template which is in the ignore list, skip the page.
'''
pywikibot.output(u'Working on '+ page.title())
@@ -1324,37 +1327,37 @@
pass
return
-def main(args):
+def main(*args):
'''
Grab a bunch of images and tag them if they are not categorized.
'''
- generator = None;
+ generator = None
genFactory = pagegenerators.GeneratorFactory()
site = pywikibot.getSite(u'commons', u'commons')
- #pywikibot.setSite(site)
- for arg in pywikibot.handleArgs():
+ for arg in pywikibot.handleArgs(*args):
if arg.startswith('-yesterday'):
generator = uploadedYesterday(site)
elif arg.startswith('-recentchanges'):
generator = recentChanges(site=site, delay=120)
else:
genFactory.handleArg(arg)
- print 'bla'
if not generator:
generator = genFactory.getCombinedGenerator()
if not generator:
- pywikibot.output('You have to specify the generator you want to use for the program!')
+ pywikibot.output(
+ u'You have to specify the generator you want to use for the program!')
else:
pregenerator = site.preloadpages(generator)
for page in pregenerator:
print page.title()
- if page.exists() and (page.namespace() == 6) and (not page.isRedirectPage()) :
+ if page.exists() and (page.namespace() == 6) \
+ and (not page.isRedirectPage()) :
if isUncat(page):
addUncat(page)
if __name__ == "__main__":
try:
- main(sys.argv[1:])
+ main()
finally:
pywikibot.stopme()
Revision: 7270
Author: russblau
Date: 2009-09-17 18:03:22 +0000 (Thu, 17 Sep 2009)
Log Message:
-----------
Newimages, Newpages, and Recentchanges page generators; BREAKING CHANGE: command line argument '-new' changed to '-newpages' to avoid ambiguity
Modified Paths:
--------------
branches/rewrite/pywikibot/pagegenerators.py
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/pagegenerators.py
===================================================================
--- branches/rewrite/pywikibot/pagegenerators.py 2009-09-17 17:11:25 UTC (rev 7269)
+++ branches/rewrite/pywikibot/pagegenerators.py 2009-09-17 18:03:22 UTC (rev 7270)
@@ -67,22 +67,12 @@
-filelinks Work on all pages that use a certain image/media file.
Argument can also be given as "-filelinks:filename".
--yahoo Work on all pages that are found in a Yahoo search.
- Depends on python module pYsearch. See yahoo_appid in
- config.py for instructions.
-
-search Work on all pages that are found in a MediaWiki search
across all namespaces.
--google Work on all pages that are found in a Google search.
- You need a Google Web API license key. Note that Google
- doesn't give out license keys anymore. See google_key in
- config.py for instructions.
- Argument can also be given as "-google:searchstring".
-
-namespace -ns Filter the page generator to only yield pages in the
specified namespaces. Separate multiple namespace
- numbers with commas.
+ numbers with commas. Example "-ns:0,2,4"
-interwiki Work on the given page and all equivalent pages in other
languages. This can, for example, be used to fight
@@ -97,15 +87,19 @@
-links Work on all pages that are linked from a certain page.
Argument can also be given as "-links:linkingpagetitle".
--new Work on the 60 newest pages. If given as -new:x, will work
- on the x newest pages.
-
-imagelinks Work on all images that are linked from a certain page.
Argument can also be given as "-imagelinks:linkingpagetitle".
-newimages Work on the 100 newest images. If given as -newimages:x,
will work on the x newest images.
+-newpages Work on the most recent new pages. If given as -newpages:x,
+ will work on the x newest pages.
+
+-recentchanges Work on the pages with the most recent changes. If
+ given as -recentchanges:x, will work on the x most recently
+ changed pages.
+
-ref Work on all pages that link to a certain page.
Argument can also be given as "-ref:referredpagetitle".
@@ -148,6 +142,16 @@
-withoutinterwiki Work on all pages that don't have interlanguage links.
Argument can be given as "-withoutinterwiki:n" where
n is some number (??).
+
+-google Work on all pages that are found in a Google search.
+ You need a Google Web API license key. Note that Google
+ doesn't give out license keys anymore. See google_key in
+ config.py for instructions.
+ Argument can also be given as "-google:searchstring".
+
+-yahoo Work on all pages that are found in a Yahoo search.
+ Depends on python module pYsearch. See yahoo_appid in
+ config.py for instructions.
"""
docuReplacements = {'¶ms;': parameterHelp}
@@ -395,12 +399,17 @@
elif arg.startswith('-newimages'):
limit = arg[11:] or pywikibot.input(
u'How many images do you want to load?')
- gen = NewimagesPageGenerator(number=int(limit))
- elif arg.startswith('-new'):
- if len(arg) >=5:
- gen = NewpagesPageGenerator(number=int(arg[5:]))
+ gen = NewimagesPageGenerator(total=int(limit))
+ elif arg.startswith('-newpages'):
+ if len(arg) >= 10:
+ gen = NewpagesPageGenerator(total=int(arg[10:]))
else:
- gen = NewpagesPageGenerator(number=60)
+ gen = NewpagesPageGenerator(total=60)
+ elif arg.startswith('-recentchanges'):
+ if len(arg) >= 15:
+ gen = RecentChangesPageGenerator(total=int(arg[15:]))
+ else:
+ gen = RecentChangesPageGenerator(total=60)
elif arg.startswith('-imagelinks'):
imagelinkstitle = arg[len('-imagelinks:'):]
if not imagelinkstitle:
@@ -487,10 +496,52 @@
# defaults to namespace 0 because that's how Special:Newpages defaults
if site is None:
site = pywikibot.Site()
- return site.recentchanges(showRedirects=get_redirect, changetype="new",
- namespaces=0, step=step, total=total)
+ for item in site.recentchanges(showRedirects=get_redirect,
+ changetype="new", namespaces=0, step=step, total=total):
+ yield pywikibot.Page(pywikibot.Link(item["title"], site))
+def RecentChangesPageGenerator(start=None, end=None, reverse=False,
+ namespaces=None, pagelist=None,
+ changetype=None, showMinor=None,
+ showBot=None, showAnon=None,
+ showRedirects=None, showPatrolled=None,
+ step=None, total=None, site=None):
+ """Generate pages that are in the recent changes list.
+
+ @param start: Timestamp to start listing from
+ @param end: Timestamp to end listing at
+ @param reverse: if True, start with oldest changes (default: newest)
+ @param limit: iterate no more than this number of entries
+ @param pagelist: iterate changes to pages in this list only
+ @param pagelist: list of Pages
+ @param changetype: only iterate changes of this type ("edit" for
+ edits to existing pages, "new" for new pages, "log" for log
+ entries)
+ @param showMinor: if True, only list minor edits; if False (and not
+ None), only list non-minor edits
+ @param showBot: if True, only list bot edits; if False (and not
+ None), only list non-bot edits
+ @param showAnon: if True, only list anon edits; if False (and not
+ None), only list non-anon edits
+ @param showRedirects: if True, only list edits to redirect pages; if
+ False (and not None), only list edits to non-redirect pages
+ @param showPatrolled: if True, only list patrolled edits; if False
+ (and not None), only list non-patrolled edits
+
+ """
+ if site is None:
+ site = pywikibot.Site()
+ for item in site.recentchanges(start=start, end=end, reverse=reverse,
+ namespaces=namespaces, pagelist=pagelist,
+ changetype=changetype, showMinor=showMinor,
+ showBot=showBot, showAnon=showAnon,
+ showRedirects=showRedirects,
+ showPatrolled=showPatrolled,
+ step=step, total=total):
+ yield pywikibot.Page(pywikibot.Link(item["title"], site))
+
+
def FileLinksGenerator(referredImagePage, step=None, total=None):
return referredImagePage.usingPages(step=step, total=total)
@@ -722,6 +773,16 @@
for i in site.preloadpages(sites[site], step):
yield i
+
+def NewimagesPageGenerator(step=None, total=None, site=None):
+ if site is None:
+ site = pywikibot.Site()
+ for entry in site.logevents(logtype="upload", step=step, total=total):
+ # entry is an UploadEntry object
+ # entry.title() returns a Page object
+ yield entry.title()
+
+
#TODO below
def UnusedFilesGenerator(number=100, repeat=False, site=None, extension=None):
@@ -749,13 +810,6 @@
for page in site.uncategorizedimages(number=number, repeat=repeat):
yield page
-def NewimagesPageGenerator(number = 100, repeat = False, site = None):
- if site is None:
- site = pywikibot.Site()
- for tuple in site.newimages(number, repeat=repeat):
- # tuple is ImagePage, date, user comment
- yield tuple[0]
-
def UnCategorizedPageGenerator(number = 100, repeat = False, site = None):
if site is None:
site = pywikibot.Site()
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2009-09-17 17:11:25 UTC (rev 7269)
+++ branches/rewrite/pywikibot/site.py 2009-09-17 18:03:22 UTC (rev 7270)
@@ -2514,8 +2514,10 @@
def newimages(self, number=100, lestart=None, leend=None, leuser=None,
letitle=None):
"""Yield ImagePages from most recent uploads"""
+ if isinstance(letitle, basestring):
+ letitle = pywikbot.Page(pywikibot.Link(letitle))
return self.logevents(logtype="upload", total=number, start=lestart,
- end=leend, user=leuser, title=letitle)
+ end=leend, user=leuser, page=letitle)
def getImagesFromAnHash(self, hash_found=None):
"""Return all images that have the same hash.