def rdf_edit(self, resource_id, configuration_name="default-tranformation-configuration"): mapping_name = configuration_name resource_id = resource_id.lower() resource = csv2rdf.ckan.resource.Resource(resource_id) resource.init() rdf_edit = RdfEditTemplate(resource, mapping_name) return self.renderer.render(rdf_edit)
def generate_default_wiki_page(self, resource_id = None): """ """ if(not resource_id): resource_id = self.resource_id resource = csv2rdf.ckan.resource.Resource(resource_id) resource.init() package = csv2rdf.ckan.package.Package(resource.package_name) tabular_file = csv2rdf.tabular.tabularfile.TabularFile(resource_id) page = '{{CSV2RDFHeader}} \n' page += '\n' #link to the publicdata.eu dataset page += '{{CSV2RDFResourceLink | \n' page += 'packageId = '+package.name+' | \n' page += 'packageName = "'+package.title+'" | \n' page += 'resourceId = '+resource.id+' | \n' page += 'resourceName = "'+resource.description+'" | \n' page += '}} \n' page += '\n' #get the header from the csv file header_position = tabular_file.get_header_position() header = tabular_file.extract_header(header_position) #CSV2RDF Template page += '{{RelCSV2RDF|\n' page += 'name = default-tranformation-configuration |\n' page += 'header = '+str(header_position)+' |\n' page += 'omitRows = -1 |\n' page += 'omitCols = -1 |\n' #Split header and create column definition for num, item in enumerate(header): #if(not type(item) is str): item = unidecode(item) page += 'col'+str(num+1)+' = '+item.rstrip()+' |\n' if(num > 500): # too many columns in this csv OR bad format break #Close template page += '}}\n' page += '\n' page = page.encode('utf-8') return page
def download(self): resource = csv2rdf.ckan.resource.Resource(self.id) resource.init() try: r = requests.get(resource.url, timeout=csv2rdf.config.config.ckan_request_timeout) assert r.ok, r file = csv2rdf.database.DatabasePlainFiles(csv2rdf.config.config.resources_path) if(not file.is_exists(self.filename)): file.saveDbaseRaw(self.filename, r.content) logging.info("File %s downloaded and saved successfully" % self.id) else: logging.info("File %s already exists" % self.id) return self.get_csv_file_path() except BaseException as e: logging.warning("Could not download the resource %s " % str(self.id)) logging.warning("Exception occured: %s" % str(e)) return False
def getResourceMetadata(self, resourceId): resource = csv2rdf.ckan.resource.Resource(resourceId) resource.init() return resource.get_metadata()
def getUriByCkanResourceId(self, resource_id): resource = csv2rdf.ckan.resource.Resource(resource_id) resource.init() return json.dumps(resource.url)