本文整理汇总了Python中wikipedia.setSite函数的典型用法代码示例。如果您正苦于以下问题:Python setSite函数的具体用法?Python setSite怎么用?Python setSite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setSite函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
bigcategory = u''
target = u''
generator = None
for arg in wikipedia.handleArgs():
if arg.startswith('-page'):
if len(arg) == 5:
generator = [wikipedia.Page(wikipedia.getSite(), wikipedia.input(u'What page do you want to use?'))]
else:
generator = [wikipedia.Page(wikipedia.getSite(), arg[6:])]
elif arg.startswith('-bigcat'):
if len(arg) == 7:
bigcategory = wikipedia.input(u'What category do you want to split out?')
else:
bigcategory = arg[8:]
elif arg.startswith('-target'):
if len(arg) == 7:
target = wikipedia.input(u'What category is the target category?')
else:
target = arg[8:]
if not bigcategory==u'':
splitOutCategory(bigcategory, target)
else:
if not generator:
generator = pagegenerators.NamespaceFilterPageGenerator(pagegenerators.ReferringPageGenerator(wikipedia.Page(wikipedia.getSite(), u'Template:Intersect categories'), onlyTemplateInclusion=True), [14])
for cat in generator:
intersectCategories(cat)
示例2: main
def main(args):
'''
Main loop. Get a generator and options. Work on all images in the generator.
'''
generator = None
onlyFilter = False
onlyUncat = False
genFactory = pagegenerators.GeneratorFactory()
global search_wikis
global hint_wiki
site = pywikibot.getSite(u'commons', u'commons')
pywikibot.setSite(site)
for arg in pywikibot.handleArgs():
if arg == '-onlyfilter':
onlyFilter = True
elif arg == '-onlyuncat':
onlyUncat = True
elif arg.startswith('-hint:'):
hint_wiki = arg [len('-hint:'):]
elif arg.startswith('-onlyhint'):
search_wikis = arg [len('-onlyhint:'):]
else:
genFactory.handleArg(arg)
generator = genFactory.getCombinedGenerator()
if not generator:
generator = pagegenerators.CategorizedPageGenerator(
catlib.Category(site, u'Category:Media needing categories'),
recurse=True)
initLists()
categorizeImages(generator, onlyFilter, onlyUncat)
pywikibot.output(u'All done')
示例3: main
def main():
countrycode = u''
# Connect database, we need that
(conn, cursor) = connectDatabase()
(conn2, cursor2) = connectDatabase2()
generator = None
genFactory = pagegenerators.GeneratorFactory()
for arg in wikipedia.handleArgs():
if arg.startswith('-countrycode:'):
countrycode = arg [len('-countrycode:'):]
lang = wikipedia.getSite().language()
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
if countrycode:
if not mconfig.countries.get((countrycode, lang)):
wikipedia.output(u'I have no config for countrycode "%s" in language "%s"' % (countrycode, lang))
return False
wikipedia.output(u'Working on countrycode "%s" in language "%s"' % (countrycode, lang))
locateCountry(countrycode, lang, mconfig.countries.get((countrycode, lang)), conn, cursor, conn2, cursor2)
else:
for (countrycode, lang), countryconfig in mconfig.countries.iteritems():
if not countryconfig.get('autoGeocode'):
wikipedia.output(u'"%s" in language "%s" is not supported in auto geocode mode (yet).' % (countrycode, lang))
else:
wikipedia.output(u'Working on countrycode "%s" in language "%s"' % (countrycode, lang))
locateCountry(countrycode, lang, countryconfig, conn, cursor, conn2, cursor2)
示例4: main
def main():
'''
The main loop
'''
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
conn = None
cursor = None
(conn, cursor) = connectDatabase()
imagerecat.initLists()
generator = None;
genFactory = pagegenerators.GeneratorFactory()
mark = True
for arg in wikipedia.handleArgs():
if arg.startswith('-dontmark'):
mark = False
elif arg.startswith('-page'):
if len(arg) == 5:
generator = [wikipedia.Page(wikipedia.getSite(), wikipedia.input(u'What page do you want to use?'))]
else:
generator = [wikipedia.Page(wikipedia.getSite(), arg[6:])]
elif arg.startswith('-yesterday'):
generator = [wikipedia.Page(wikipedia.getSite(), u'Category:Media_needing_categories_as_of_' + getYesterday())]
else:
generator = genFactory.handleArg(arg)
if generator:
for page in generator:
if((page.namespace() == 14) and (page.title().startswith(u'Category:Media needing categories as of'))):
wikipedia.output(u'Working on ' + page.title())
for (image, gals, cats) in getImagesToCategorize(cursor, page.titleWithoutNamespace()):
categorizeImage(image, gals, imagerecat.applyAllFilters(cats))
if (mark):
categoriesChecked(page.title())
示例5: main
def main():
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
# Connect database, we need that
conn = None
cursor = None
(conn, cursor) = connectDatabase()
generator = None
genFactory = pagegenerators.GeneratorFactory()
for arg in wikipedia.handleArgs():
genFactory.handleArg(arg)
generator = genFactory.getCombinedGenerator()
if not generator:
generator = getRijksmonumentWithoutLocation()
# Get a preloading generator with only images
pgenerator = pagegenerators.PreloadingGenerator(pagegenerators.NamespaceFilterPageGenerator(generator, [6]))
for page in pgenerator:
locationTemplate = locateImage(page, conn, cursor)
if locationTemplate:
addLocation(page, locationTemplate)
示例6: main
def main(args):
'''
Grab a bunch of images and tag them if they are not categorized.
'''
generator = None
genFactory = pagegenerators.GeneratorFactory()
site = pywikibot.getSite(u'commons', u'commons')
pywikibot.setSite(site)
for arg in pywikibot.handleArgs():
if arg.startswith('-yesterday'):
generator = uploadedYesterday(site)
elif arg.startswith('-recentchanges'):
generator = recentChanges(site=site, delay=120)
else:
genFactory.handleArg(arg)
if not generator:
generator = genFactory.getCombinedGenerator()
if not generator:
pywikibot.output(
u'You have to specify the generator you want to use for the program!')
else:
pregenerator = pagegenerators.PreloadingGenerator(generator)
for page in pregenerator:
if page.exists() and (page.namespace() == 6) \
and (not page.isRedirectPage()) :
if isUncat(page):
addUncat(page)
示例7: main
def main(args):
"""
Main loop.
"""
workdir = u""
textfile = u""
records = {}
site = wikipedia.getSite(u"commons", u"commons")
wikipedia.setSite(site)
if not (len(args) == 2):
wikipedia.output(u"Too few arguments. Usage: NARA_uploader.py <directory> <textfile>")
sys.exit()
if os.path.isdir(args[0]):
workdir = args[0]
else:
wikipedia.output(u"%s doesn't appear to be a directory. Exiting" % (args[0],))
sys.exit()
textfile = args[1]
records = getRecords(textfile)
# print records
sourcefilenames = glob.glob(workdir + u"/*.TIF")
for sourcefilename in sourcefilenames:
filename = os.path.basename(sourcefilename)
# This will give an ugly error if the id is unknown
if not records.get(filename):
wikipedia.output(u"Can't find %s in %s. Skipping this file." % (filename, textfile))
elif os.path.getsize(sourcefilename) >= 1024 * 1024 * 100:
wikipedia.output(u"%s too big. Skipping this file." % (sourcefilename,))
else:
fileId = records.get(filename)
duplicates = findDuplicateImages(sourcefilename)
if duplicates:
wikipedia.output(u"Found duplicate image at %s" % duplicates.pop())
else:
# No metadata handling. We use a webtool
description = getDescription(fileId)
categories = u"{{Uncategorized-NARA|year=2011|month=September|day=21}}\n"
description = description + categories
print fileId
title = getTitle(fileId, description)
wikipedia.output(title)
wikipedia.output(description)
bot = upload.UploadRobot(
url=sourcefilename.decode(sys.getfilesystemencoding()),
description=description,
useFilename=title,
keepFilename=True,
verifyDescription=False,
)
bot.run()
示例8: main
def main(args):
'''
Main loop.
'''
site = wikipedia.getSite(u'commons', u'commons')
wikipedia.setSite(site)
sourcedir=u'/mnt/user-store/OS_OpenData/1_250_000_Scale_Raster/data/'
destinationdirjpg=u'/mnt/user-store/OS_OpenData/1_250_000_Scale_Raster/outputjpg/'
destinationdirtif=u'/mnt/user-store/OS_OpenData/1_250_000_Scale_Raster/outputtif/'
basefilename=u'Ordnance_Survey_1-250000_-_'
sourcename=u'1:250 000 Scale Colour Raster'
scale=u'250.000'
squares = []
for sourcefilename in glob.glob(sourcedir + u"*.tif"):
square = sourcefilename.replace(sourcedir, u'').replace(u'.tif', u'')
squares.append(square)
for square in squares:
print square
OSlib.processSquare(square, squares, scale, sourcedir, sourcename, basefilename, u'jpg', destinationdirjpg)
OSlib.processSquare(square, squares, scale, sourcedir, sourcename, basefilename, u'tif', destinationdirtif)
'''
示例9: main
def main(args):
'''
Main loop.
'''
site = wikipedia.getSite(u'commons', u'commons')
wikipedia.setSite(site)
conn = None
cursor = None
(conn, cursor) = connectDatabase()
#conn2 = None
#cursor2 = None
#(conn2, cursor2) = connectDatabase2('sql-s2.toolserver.org', u'u_multichill_commons_categories_p')
conn3 = None
cursor3 = None
(conn3, cursor3) = connectDatabase2('commonswiki-p.db.toolserver.org', u'commonswiki_p')
topics = getTopics(cursor)
images = {}
cats = []
for (topic,) in topics:
cats.extend(getCategoriesToSplit(cursor3, topic))
outputCategoriesToSplit(cats)
'''
示例10: main
def main(args):
'''
Main loop.
'''
site = wikipedia.getSite(u'commons', u'commons')
wikipedia.setSite(site)
conn = None
cursor = None
(conn, cursor) = connectDatabase()
conn2 = None
cursor2 = None
(conn2, cursor2) = connectDatabase2('sql-s2.toolserver.org', u'u_multichill_commons_categories_p')
conn3 = None
cursor3 = None
(conn3, cursor3) = connectDatabase2('commonswiki-p.db.toolserver.org', u'commonswiki_p')
topics = getTopics(cursor)
images = {}
for (topic,) in topics:
images[topic] = getImagesWithTopicCount(cursor3, topic)
print images[topic]
outputStats(topics, images)
'''
示例11: main
def main():
'''
The main loop
'''
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
conn = None
cursor = None
(conn, cursor) = connectDatabase()
# Get datetime
date = datetime.utcnow().strftime('%Y%m%d%H%M')
# Get number of uncategorized files
uncatQuery=u"SELECT COUNT(DISTINCT(page_title)) FROM page JOIN categorylinks ON page_id=cl_from WHERE page_namespace=6 AND page_is_redirect=0 AND cl_to LIKE 'Media\_needing\_categories\_as\_of\_%'"
uncatCount = getCount(cursor, uncatQuery)
# Get number of files to be checked
checkQuery=u"SELECT COUNT(DISTINCT(page_title)) FROM page JOIN categorylinks ON page_id=cl_from WHERE page_namespace=6 AND page_is_redirect=0 AND cl_to LIKE 'Media\_needing\_category\_review\_as\_of\_%'"
checkCount = getCount(cursor, checkQuery)
# Get total
totalCount = int(uncatCount) + int(checkCount)
# Update the stats page with this number
updateStats(date, uncatCount, checkCount, totalCount)
示例12: main
def main():
'''
The main loop
'''
wikipedia.setSite(wikipedia.getSite(u'nl', u'wikipedia'))
conn = None
cursor = None
(conn, cursor) = connectDatabase()
items = getNumberOfItems(cursor)
images = getNumberOfImages(cursor)
addresses = {}
names = {}
pages = list(set(items.keys() + images.keys()))
pages.sort()
for key in pages:
print key
page = wikipedia.Page(wikipedia.getSite(), key)
text = page.get()
addresses[key] = getNumberOfAddresses(text)
names[key] = getNumberOfNames(text)
#print key + u' - ' + str(addresses[key]) + u' - ' + str(names[key])
updateStats(pages, items, addresses, names, images)
示例13: main
def main(args):
'''
Main loop.
'''
genFactory = pagegenerators.GeneratorFactory()
start_id = 0
end_id = 0
updaterun = False
site = wikipedia.getSite('commons', 'commons')
wikipedia.setSite(site)
updatePage = wikipedia.Page(site, u'User:BotMultichillT/Air_Force_latest')
interval=100
for arg in wikipedia.handleArgs():
if arg.startswith('-start_id'):
if len(arg) == 9:
start_id = wikipedia.input(u'What is the id of the photo you want to start at?')
else:
start_id = arg[10:]
elif arg.startswith('-end_id'):
if len(arg) == 7:
end_id = wikipedia.input(u'What is the id of the photo you want to end at?')
else:
end_id = arg[8:]
elif arg==u'-updaterun':
updaterun = True
elif arg.startswith('-interval'):
if len(arg) == 9:
interval = wikipedia.input(u'What interval do you want to use?')
else:
interval = arg[10:]
else:
genFactory.handleArg(arg)
generator = genFactory.getCombinedGenerator()
# Do we have a pagenerator?
if generator:
for page in generator:
if page.namespace()==14:
processCategory(page)
# Is updaterun set?
elif updaterun:
start_id = int(updatePage.get())
end_id = start_id + int(interval)
last_id = processPhotos(int(start_id), int(end_id))
comment = u'Worked from ' + str(start_id) + u' to ' + str(last_id)
updatePage.put(str(last_id), comment)
# Do we have a start_id and a end_id
elif int(start_id) > 0 and int(end_id) > 0:
last_id = processPhotos(int(start_id), int(end_id))
# Use the default generator
else:
print "Screw this, will implement later"
示例14: main
def main():
'''
The main loop
'''
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
conn = None
cursor = None
(conn, cursor) = connectDatabase()
for templateTitle in getUncategorizedTemplates(cursor):
tagUncategorized(templateTitle)
示例15: main
def main():
'''
The main loop
'''
wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
conn = None
cursor = None
(conn, cursor) = connectDatabase()
#images = getImagesToCategorize(cursor)
for (image, category) in getImagesToCategorize(cursor):
categorizeImage(image, category)