def get_all_obs():
	query= "SELECT distinct ?a where {\
		 ?a <http://www.w3.org/1999/02/22-rdf-syntax-ns%23type> <http://purl.oclc.org/NET/ssnx/ssn%23Station> . }"

	url = ENDPOINT_URL + query + "&output=csv"
	
	print "connecting..."
	a = urllib.urlopen(url)
	print "ok"
	f = open("hola.csv", 'a')
	f.write(a.read())
	f.close()

	i = 0
	dale = False
	vm = VirtuosoManager(VIRTUOSO_URL)
	with open('hola.csv', 'r') as stdoc:
		reader = csv.reader(stdoc)
		for details in reader:
			#if details[0] == "http://dev.morelab.deusto.es/bizkaisense/resource/station/EUROPA/PM10/01012010/21":
			#	dale = True
			if i > 0:
				dale = True
			if dale:
				query = 'DELETE DATA {<' + details[0] + '> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.oclc.org/NET/ssnx/ssn#Station> }'
				vm.update(query, RESOURCE_URI)
				query = 'INSERT DATA {<' + details[0] + '> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.oclc.org/NET/ssnx/ssn#Observation> }'
				vm.update(query, RESOURCE_URI)
				print str(i) + ' - ' + details[0]
			i += 1
def get_all_obs():
    query = "SELECT distinct ?a where {\
		 ?a <http://www.w3.org/1999/02/22-rdf-syntax-ns%23type> <http://purl.oclc.org/NET/ssnx/ssn%23Station> . }"

    url = ENDPOINT_URL + query + "&output=csv"

    print "connecting..."
    a = urllib.urlopen(url)
    print "ok"
    f = open("hola.csv", 'a')
    f.write(a.read())
    f.close()

    i = 0
    dale = False
    vm = VirtuosoManager(VIRTUOSO_URL)
    with open('hola.csv', 'r') as stdoc:
        reader = csv.reader(stdoc)
        for details in reader:
            #if details[0] == "http://dev.morelab.deusto.es/bizkaisense/resource/station/EUROPA/PM10/01012010/21":
            #	dale = True
            if i > 0:
                dale = True
            if dale:
                query = 'DELETE DATA {<' + details[
                    0] + '> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.oclc.org/NET/ssnx/ssn#Station> }'
                vm.update(query, RESOURCE_URI)
                query = 'INSERT DATA {<' + details[
                    0] + '> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.oclc.org/NET/ssnx/ssn#Observation> }'
                vm.update(query, RESOURCE_URI)
                print str(i) + ' - ' + details[0]
            i += 1
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
logger.info('Empieza la fiesta')

horarias = codecs.open(HORARIAS_FILE, 'r', "iso-8859-15")
mediciones = codecs.open(MEDICIONES_FILE, 'r', "iso-8859-15")

mediciones_dict = {}

for line in mediciones.readlines():
    line_list = line.split(';')
    mediciones_dict[line_list[1]] = line_list



vm = VirtuosoManager(HOST)

out = open(OUT_FILE, 'w')

set_estaciones = Set()
#set_props = Set()

for line in horarias.readlines():
    line_list = line.split(';')
    #print line_list
    identifier = mediciones_dict[line_list[0]][0]
    identifier = identifier.encode('utf-8').replace('Ñ', 'N')
    query = 'SELECT ?s WHERE { ?s dc:identifier "' + identifier + '" . ?s rdf:type ssn:Sensor}'
    uri_list = get_uris_from_xml(vm.select(query, 'application/sparql-results+xml', ))
    if len(uri_list) > 0:
        
Beispiel #4
0
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
logger.info('Empieza la fiesta')

horarias = codecs.open(HORARIAS_FILE, 'r', "iso-8859-15")
mediciones = codecs.open(MEDICIONES_FILE, 'r', "iso-8859-15")

mediciones_dict = {}

for line in mediciones.readlines():
    line_list = line.split(';')
    mediciones_dict[line_list[1]] = line_list

vm = VirtuosoManager(HOST)

out = open(OUT_FILE, 'w')

set_estaciones = Set()
#set_props = Set()

for line in horarias.readlines():
    line_list = line.split(';')
    #print line_list
    identifier = mediciones_dict[line_list[0]][0]
    identifier = identifier.encode('utf-8').replace('Ñ', 'N')
    query = 'SELECT ?s WHERE { ?s dc:identifier "' + identifier + '" . ?s rdf:type ssn:Sensor}'
    uri_list = get_uris_from_xml(
        vm.select(
            query,