Example #1
0
def update():
	scriptpage = Page(site, "User:Legoktm/BOTFAQ/Code/redir.py")
	text = file('redir.py').read()
	text = '<source lang="python">\n' + text + '</sou' + 'rce>' # Split to confuse MW parser
	if scriptpage.get() != text:
    		summary = 'Updating source'
    	scriptpage.put(text, summary)
Example #2
0
 def setUp(self):
     self.w = wiki_handler()
     user_page = self.w.user.getUserPage()
     sandbox = Page(self.w.site, user_page.title()+'/Sandbox')
     self.test_pages = [ Page(self.w.site, sandbox.title()+p) for p in ('/test1', '/test2') ]
     for p in self.test_pages:
         p.put('blablabla')
 def bot_control(self,site):
     import urllib
     from wikipedia import Error, Page
     wt_username = urllib.quote(config.usernames[self.name][site.lang].encode('utf-8'))
     wt_namespace = urllib.quote(self.namespaces[2][site.lang].encode('utf-8'))
     wt_user_run = unicode(wt_namespace) + u':' + unicode(wt_username) + u'/Run'
     wt_page = Page(site, wt_user_run)
     wt_user_run_text = wt_page.get(get_redirect = True)
     wt_namespace = urllib.quote(self.namespaces[4][site.lang].encode('utf-8'))
     wt_script_policy = urllib.quote(self.wt_script_policy[site.lang].encode('utf-8'))
     wt_system_run = unicode(wt_namespace) + u':' + unicode(wt_script_policy) + u'/Run'
     wt_page = Page(site, wt_system_run)
     wt_system_run_text = wt_page.get(get_redirect = True)
     if 'yes' not in wt_user_run_text or 'yes' not in wt_system_run_text:
         raise Error('Bot stopped by /Run page on %s -- %s = %s , %s = %s'
                  % (site.lang, wt_user_run, wt_user_run_text, wt_system_run, wt_system_run_text))
     return True
Example #4
0
 def bot_control(self,site):
     import urllib
     from wikipedia import Error, Page
     wt_username = urllib.quote(config.usernames[self.name][site.lang].encode('utf-8'))
     wt_namespace = urllib.quote(self.namespaces[2][site.lang].encode('utf-8'))
     wt_user_run = unicode(wt_namespace) + u':' + unicode(wt_username) + u'/Run'
     wt_page = Page(site, wt_user_run)
     wt_user_run_text = wt_page.get(get_redirect = True)
     wt_namespace = urllib.quote(self.namespaces[4][site.lang].encode('utf-8'))
     wt_script_policy = urllib.quote(self.wt_script_policy[site.lang].encode('utf-8'))
     wt_system_run = unicode(wt_namespace) + u':' + unicode(wt_script_policy) + u'/Run'
     wt_page = Page(site, wt_system_run)
     wt_system_run_text = wt_page.get(get_redirect = True)
     if 'yes' not in wt_user_run_text or 'yes' not in wt_system_run_text:
         raise Error('Bot stopped by /Run page on %s -- %s = %s , %s = %s'
                  % (site.lang, wt_user_run, wt_user_run_text, wt_system_run, wt_system_run_text))
     return True
Example #5
0
		# Since we have the names of the images in the file, we need to
		# recompute and substitute that at each entry into this loop.
		imgidx = 0
		for i in range(0,len(wikilines)):
			if re_imagematch.search(wikilines[i]):
				wikilines[i] = re_imagematch.sub('[[Image:%s_%s.%s]]' % (outname, imgidx, images[imgidx].extension()), wikilines[i])
				imgidx += 1
		if imgidx != len(images):
			# Mismatch between found images and found image tags
			print "Did not find match for all images!"
			sys.exit(1)

		# Attempt the base page upload
		with IOWrapper("Uploading page..."):
			try:
				p = Page(site, outname)
				p.put(''.join(wikilines), comment='Uploaded by word2mediawiki',
					  minorEdit=True, force=True)
			except PageNotSaved:
				# Ok, failed. So let's retry with another name
				continue

		# Now that the page is created, we will no longer be able to retry
		# with a better name, so let's just abort if things fail from here on.
		# Thus, drop out of the loop
		break

	# Upload the base document, assuming nobody else has uploaded a document
	# between us checking it and actuall uploading.
	with IOWrapper("Uploading base document..."):
		bot = UploadRobot(inputfile,
        SPI_SETDESKWALLPAPER = 20
        ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0,
                                                   "Picture_of_the_day.bmp", 0)
    else:
        gconf.client_get_default().get_string(
            '/desktop/gnome/background/picture_options', 'scaled')
        gconf.client_get_default().get_string(
            '/desktop/gnome/background/picture_filename',
            'Picture_of_the_day.png')


if __name__ == '__main__':
    commons = Site('commons', 'commons')
    date_today = time.strftime('%Y-%m-%d', time.localtime())
    template = 'Template:Potd/%s' % date_today
    templatePage = Page(commons, template)
    image_today = templatePage.get()
    image_name = 'Image:%s' % image_today
    imageURL = ImagePage(commons, image_name)
    featuredImage = imageURL.fileUrl()
    image = featuredImage[27:]

    if sys.platform == 'win32':
        if image.endswith('.svg'):
            sys.exit()  # Windows background don't accept svg files

        ### Install CommonsPictureOfTheDay in registry
        Reg = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
        Key = OpenKey(Reg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0,
                      KEY_WRITE)
        # entry your correct pywikipediabot patch
    draw.text(((write.size[0]-textwidth)/55, (write.size[0]-textheight)/55), text, fill=(120,120,120))
    img.save(outfilename)
    
def set_wallpaper():
    if sys.platform == 'win32':
        SPI_SETDESKWALLPAPER = 20
        ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, "Picture_of_the_day.bmp", 0)
    else:
        gconf.client_get_default().get_string('/desktop/gnome/background/picture_options', 'scaled') 
        gconf.client_get_default().get_string('/desktop/gnome/background/picture_filename', 'Picture_of_the_day.png')

if __name__ == '__main__':
    commons = Site('commons', 'commons')
    date_today = time.strftime('%Y-%m-%d', time.localtime())
    template = 'Template:Potd/%s' % date_today
    templatePage = Page(commons, template)
    image_today = templatePage.get()
    image_name = 'Image:%s'% image_today
    imageURL = ImagePage(commons, image_name)
    featuredImage = imageURL.fileUrl()
    image = featuredImage[27:]

    if sys.platform == 'win32':
        if image.endswith('.svg'):
            sys.exit() # Windows background don't accept svg files

        ### Install CommonsPictureOfTheDay in registry
        Reg = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
        Key = OpenKey(Reg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE)
        # entry your correct pywikipediabot patch
        SetValueEx(Key,"CommonsPictureOfTheDay", 0, REG_SZ, r"C:\pywikipediabot\pywikipedia\CommonsPictureOfTheDay.py")
Example #8
0
	while True:
		if outnamecounter > 0:
			outname = "%s_%s" % (baseoutname, outnamecounter)
		else:
			outname = baseoutname
		outnamecounter += 1
		if outnamecounter > 50:
			print "Tried 50 different names, it's probably something else that's wrong."
			print "Giving up."
			sys.exit(1)

		# Check for existing copy of either a page with this very name, or
		# of one of our attached files. If any of them alerady exist, loop
		# back up and try another name.
		with IOWrapper("Checking whether '%s' exists..." % outname):
			if Page(site, outname).exists():
				print "Page %s already exists, trying another name" % outname
				continue

		with IOWrapper("Checking whether 'File:%s.%s' exists..." % (outname, docextension)):
			if Page(site, "File:%s.%s" % (outname, docextension)).exists():
				print "File %s already exists, trying another name" % ("File:%s.%s" % (outname, docextension))
				continue

		foundany = False
		for i in range(0, len(images)):
			with IOWrapper("Checking whether 'File:%s_%s.%s' exists..." % (outname, i, images[i].extension())):
				if Page(site, "File:%s_%s.%s" % (outname, i, images[i].extension())).exists():
					print "Image %s already exists, trying another name" % ("File:%s_%s.%s" % (outname, i, images[i].extension()))
					foundany = True
					break