def editorial_publish(guides, endpoint, function_class, user_agent, nailgun_bin, content_generator): """ takes care of publishing the editorial content for the guides. """ # init the nailgun thing for ed content generation. nailguninit(nailgun_bin,content_generator) searches= {} pbar = Bar('extracting editorial content for guides:',max=len(guides)+1) pbar.start() error = False for i, guide in enumerate(guides): jsonguide = None with open(guide,'r') as g: jsonguide = json.load(g) if not jsonguide: logging.error('could not load json from {0}'.format()) error = True continue search = cityinfo.cityinfo(jsonguide) uri = cityres.cityres(search,endpoint) if not uri: logging.error( 'no dbpedia resource was found for {0}'.format(guide)) error = True continue urls = urlinfer.urlinferdef([unquote(uri)]) if len(urls) < 1: logging.error('no wikipedia/wikivoyage urls found/inferred'\ ' for resource {0}'.format(uri)) error = True continue content = editorial_content(urls,function_class,user_agent) if not content: logging.error('no editorial content could be'\ ' generated for {0}'.format(guide)) error = True continue #insert the content into the guide jsonsert.jsonsert(content, guide) logging.info('editorial content for {0} sucessfully'\ ' inserted.'.format(guide)) pbar.next() pbar.finish() return error
def depiction_url(guide_filename, user_agent, classpath, endpoint): """ Uses the description generator to retrieve the depiction url of the guide. """ content = None with open(guide_filename,'r') as guide_file: content = json.load(guide_file, object_pairs_hook = collections.OrderedDict) if not content: logging.error("could not load json guide from {0}."\ " No depiction url can be found".format(guide_filename)) return None search = cityinfo.cityinfo(content) uri = cityres.cityres(search, endpoint) if not uri: logging.error("could not find a dbpedia resource for {0}."\ " No depiction url can be found.".format(guide_filename)) return None unquoted_uri = unquote(uri) # infer the english wikivoyage from the uri. wiki_urls = urlinfer.urlinferwiki([unquoted_uri]) wikivoyage = "wikivoyage" wikipedia = "wikipedia" wikivoyage_urls = [u for u in wiki_urls if wikivoyage in urlparse(u).netloc] wikipedia_urls = [u for u in wiki_urls if wikipedia in urlparse(u).netloc] depiction_url = None if len(wikivoyage_urls) > 0: depiction_url = depiction_source(wikivoyage_urls[0], classpath, user_agent) if len(wikipedia_urls) > 0 and not depiction_url: depiction_url = depiction_source(wikipedia_urls[0], classpath, user_agent) if not depiction_url: logging.error("could not infer a depiction source for {0}.".format(guide_filename)) return depiction_url