示例#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)
示例#2
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
        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
示例#4
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