Пример #1
0
def upload(name):
	descrip = ch2(name)
	if descrip == False:
		return False
	print 'Uploading %s to commons:commons.' %(name.title())
	#wikipedia.showDiff('', descrip)
	time.sleep(20)
	bot = UploadRobot(name.fileUrl(), description=descrip, useFilename=name.fileUrl(), keepFilename=True, verifyDescription=False, targetSite = commons)

	bot.run()
	print '%s was uploaded to commons:commons.' %(name.title())
Пример #2
0
def upload(name):
    descrip = ch2(name)
    if descrip == False:
        return False
    print 'Uploading %s to commons:commons.' % (name.title())
    #wikipedia.showDiff('', descrip)
    time.sleep(20)
    bot = UploadRobot(name.fileUrl(),
                      description=descrip,
                      useFilename=name.fileUrl(),
                      keepFilename=True,
                      verifyDescription=False,
                      targetSite=commons)

    bot.run()
    print '%s was uploaded to commons:commons.' % (name.title())
Пример #3
0
    def run(self, filename):
        with open(filename, 'r') as f:
            source = csv.reader(f, delimiter='\t')
            header = next(source)
            pywikibot.output("Header of the input table: " + ', '.join(header))
            titles = namedtuple('titles', ', '.join(header))
            titles = [titles._make(row) for row in source]

        if not titles:
            pywikibot.output(
                "We were not able to extract the data to work on. Exiting.")
            return

        for row in titles:
            commons = "%s - Musei del cibo - %s - %s.jpg" % (
                row.nome, row.museo, row.inventario)
            description = u"""
{{Musei del cibo
| museo = %s
| inventario = %s
| nome = %s
| ambito = %s
| epoca = %s
| dimensioni = %s
| materia = %s
| descrizione = %s
| provenienza = %s
| note = %s
| bibliografia = %s
}}
""" % (row.museo, row.inventario, row.nome, row.ambito, row.epoca,
            row.dimensioni, row.materia, row.descrizione, row.provenienza, row.note,
            row.biblio)

            try:
                upload = UploadRobot(row.inventario + ".jpg",
                                     description=description,
                                     useFilename=commons,
                                     keepFilename=True,
                                     verifyDescription=False,
                                     ignoreWarning=False,
                                     aborts=True)
                upload.run()
            except:
                pywikibot.output("ERROR: The upload could not be completed.")
Пример #4
0
    def run(self, filename):
        with open(filename, 'r') as f:
            source = csv.reader(f, delimiter='\t')
            header = next(source)
            pywikibot.output("Header of the input table: " + ', '.join(header) )
            titles = namedtuple('titles', ', '.join(header))
            titles = [titles._make(row) for row in source]

        if not titles:
            pywikibot.output("We were not able to extract the data to work on. Exiting.")
            return

        for row in titles:
            commons = "%s - Musei del cibo - %s - %s.jpg" % (row.nome, row.museo, row.inventario)
            description = u"""
{{Musei del cibo
| museo = %s
| inventario = %s
| nome = %s
| ambito = %s
| epoca = %s
| dimensioni = %s
| materia = %s
| descrizione = %s
| provenienza = %s
| note = %s
| bibliografia = %s
}}
""" % (row.museo, row.inventario, row.nome, row.ambito, row.epoca,
    row.dimensioni, row.materia, row.descrizione, row.provenienza, row.note, row.biblio)

            try:
                upload = UploadRobot(row.inventario + ".jpg", description=description,
                                     useFilename=commons, keepFilename=True,
                                     verifyDescription=False, ignoreWarning=False, aborts=True)
                upload.run()
            except:
                pywikibot.output("ERROR: The upload could not be completed.")
Пример #5
0
				# 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,
						  description='Uploaded by word2mediawiki',
						  useFilename="%s.%s" % (outname, docextension),
						  keepFilename=True, verifyDescription=False)
		bot.run()

	# Upload all images (same assumption as for base document)
	for i in range(0,len(images)):
		img = images[i]
		with IOWrapper("Uploading image %s of %s..." % (i+1, len(images))):
			bot = UploadRobot("http://devnull",
							  description="Uploaded by word2mediawiki for inclusion in %s" % outname,
							  useFilename="%s_%s.%s" % (outname, i, img.extension()),
							  keepFilename=True, verifyDescription=False)
			bot._contents = img.buffer
			bot.run()

	# Clean up any old files
	for f in ('%s/converted.wiki' % tempdir, '%s/converted.xml' % tempdir):
		if os.path.exists(f): os.unlink(f)
Пример #6
0
				# 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,
						  description='Uploaded by word2mediawiki',
						  useFilename="%s.%s" % (outname, docextension),
						  keepFilename=True, verifyDescription=False)
		bot.run()

	# Upload all images (same assumption as for base document)
	for i in range(0,len(images)):
		img = images[i]
		with IOWrapper("Uploading image %s of %s..." % (i+1, len(images))):
			bot = UploadRobot("http://devnull",
							  description="Uploaded by word2mediawiki for inclusion in %s" % outname,
							  useFilename="%s_%s.%s" % (outname, i, img.extension()),
							  keepFilename=True, verifyDescription=False)
			bot._contents = img.buffer
			bot.run()

	# Clean up any old files
	for f in ('%s/converted.wiki' % tempdir, '%s/converted.xml' % tempdir):
		if os.path.exists(f): os.unlink(f)
Пример #7
0
		print "ERROR: No files found for record %s, inventory %s" % (data[i]['IDK'], data[i]['INV1N'])
		continue

	for filename in filenames:
		try:
			prefix = "%s %s" % (data[i]['OGTD'], data[i]['OGTT'])
		except:
			prefix = data[i]['OGTD']
		prefix = re.sub('[#<>\[\]|{}/?]', '', prefix)
		commons = u"%s - Museo scienza tecnologia Milano %s" % (prefix, filename.split('/')[-1])
		print commons
		try:
			upload = UploadRobot(filename, description=description,
								useFilename=commons, keepFilename=True,
								verifyDescription=False, ignoreWarning=False, aborts=True)
			upload.run()
			os.remove(filename)
		except:
			pywikibot.output("ERROR: The upload could not be completed.")

"""
# Prepare to write out to CSV: find out what columns we need
fieldnames = {}
header = []
for i in range(0, len(data)-1):
	for key in data[i].iterkeys():
		fieldnames[key] = True
for name in fieldnames.iterkeys():
	header.append(name)
print(header)
Пример #8
0
		print "ERROR: No files found for record %s, inventory %s" % (data[i]['IDK'], data[i]['INV1N'])
		continue

	for filename in filenames:
		try:
			prefix = "%s %s" % (data[i]['OGTD'], data[i]['OGTT'])
		except:
			prefix = data[i]['OGTD']
		prefix = re.sub('[#<>\[\]|{}/?]', '', prefix)
		commons = u"%s - Museo scienza tecnologia Milano %s" % (prefix, filename.split('/')[-1])
		print commons
		try:
			upload = UploadRobot(filename, description=description,
								useFilename=commons, keepFilename=True,
								verifyDescription=False, ignoreWarning=False, aborts=True)
			upload.run()
			os.remove(filename)
		except:
			pywikibot.output("ERROR: The upload could not be completed.")

"""
# Prepare to write out to CSV: find out what columns we need
fieldnames = {}
header = []
for i in range(0, len(data)-1):
	for key in data[i].iterkeys():
		fieldnames[key] = True
for name in fieldnames.iterkeys():
	header.append(name)
print(header)