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())
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())
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.")
def complete_desc_and_upload(filename, pagetitle, code, date): #complete this once if applies to all files description = u"""{{Information |Description = {{en|1=Non-encodable character, coded """ + code + u""" in original Koktai dictionnary}} |Source = https://github.com/g0v/koktai |Author = 吳壽禮 |Date = """ + date + u""" |Permission = {{Cc-by-sa-4.0|吳壽禮}} }} =={{int:license-header}}== CC-BY-SA """ url = filename keepFilename=True #False #set to True to skip double-checking/editing destination filename verifyDescription=False #True #set to False to skip double-checking/editing description => change to bot-mode targetSite = pywikibot.Site('commons', 'commons') bot = UploadRobot(url, description=description, useFilename=pagetitle, keepFilename=keepFilename, verifyDescription=verifyDescription, targetSite = targetSite) bot.upload_image(debug=True)
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.")
def main(): search_term = input("Wikipedia search term: ") if len(search_term) == 0: print("Please enter a search term.") sys.exit(1) print( "Avaiable prefixes:\n1. What is\n2. Who is\n3. The history of\n4. Learn more about" ) prefixes = ["What is", "Who is", "The history of", "Learn more about"] prefix = input("Prefix: ") if not prefix in "1234": print("Please enter a prefix.") sys.exit(1) project_directory = make_project_directory(search_term) prefix = prefixes[int(prefix) - 1] print("[*] Starting search robot...") search_robot = SearchRobot() search_result = search_robot.search(search_term) keywords_list = search_robot.get_keywords(search_result) for i in range(len(search_result)): print("[*] Sentence {0}: {1}".format(i + 1, search_result[i])) print("[*] Keywords: {0}\n".format(keywords_list[i])) print("[*] Starting image robot...") image_robot = ImageRobot(project_directory) images_list = [] print(keywords_list) for keywords in keywords_list: print('here') get_img = image_robot.get_image(keywords, search_term) print(get_img) img = first(get_img) images_list.append(img) print("[*] Image saved in: " + str(img)) print(images_list) print("[*] Renaming images...") images_list = image_robot.rename_files(images_list) print("[*] Converting images to JPG...") image_robot.convert_to_jpg(images_list) print("[*] Resizing images...") image_robot.resize(images_list) print("[*] Starting video robot...") video_robot = VideoRobot(search_result, project_directory, f'{project_directory}\\saida.mkv') video_robot.add_subtitles() video_robot.make_video() video_robot.add_music() print(search_result) print("[*] Backup files saved in: " + project_directory) option = input("Do you want to upload this video? (y/n)") if option in 'YySs': print("[*] Starting upload robot...") upload_robot = UploadRobot() title = prefix + " " + search_term description = "\n\n".join(search_result) keywords = [] for i in keywords_list: keywords += i keywords = ",".join(keywords) args = argparse.Namespace( auth_host_name="localhost", auth_host_port=[8080, 8090], category="27", description=description, file="{}/saida.mkv".format(project_directory), keywords=keywords, logging_level="ERROR", noauth_local_webserver=False, privacy_status="public", title=title) try: youtube = upload_robot.get_authenticated_service(args) print("[*] Uploading video...") try: upload_robot.initialize_upload(youtube, args) except HTTPError as e: error("An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)) except: print("Error: Reached video upload limit per day.") else: play_video(os.path.join(project_directory, "saida.mkv"))
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, 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
filenames.append(directory + image) if not filenames: 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)