found = False
                for i in range(19, 0, -1):
                    time.sleep(i / 3)
                    params = '?action=wbsearchentities&search=' + URLEncoder.encode(
                        name, "UTF-8") + '&language=en&format=json'
                    url = baseurl + 'api.php' + params
                    r1 = HttpClient.create(URL(url), "GET")
                    r2 = r1.setHeader("Content-Type",
                                      "application/x-www-form-urlencoded"
                                      ).connect().fetchContent()
                    #print dir(r2)
                    print i, r2
                    Q_school = QinJSONRE.search(r2)
                    if Q_school:
                        print Q_school.group('qid')
                        break
                    else:
                        print 'not found yet'

                break
            else:
                print 'already in Wikidata'
        newSchool = Node(element)
        newSchool.put('wikidata', Q_school.group('qid'))
        newSchool.put('isced:level', isced)

        CommandsList = [Command.ChangeCommand(element, newSchool)]
        Main.main.undoRedo.add(
            Command.SequenceCommand(
                "Add wikidata and isced:level tags to school", CommandsList))
     itemDocuments = wbsea.WbSearchEntities(searchString = name)
     if 'success' in itemDocuments and itemDocuments['search']:
         for res in itemDocuments['search']:
             print res
             if 'description' in res and res['description'] == description:
                 Q_school = res['id']
                 print Q_school
                 if type=='node':
                     newSchool = Node(element)
                 elif type=='way':
                     newSchool = Way(element)
                 else:
                     newSchool = Relation(element)
                 dirty =False
                 if newSchool.get('wikidata') != Q_school:
                     newSchool.put('wikidata', Q_school); dirty=True
                 for tag in tagsToSet:
                     if tagsToSet[tag]: newSchool.put(tag, tagsToSet[tag]); dirty=True
                 if dirty:
                     CommandsList=[Command.ChangeCommand( element, newSchool)]
                     Main.main.undoRedo.add(Command.SequenceCommand("Add wikidata and isced:level tags to school", CommandsList))
                 found = True
                 break
         if found: break
     else:
         print 'not found yet'
 if element.isNew(): noNewSchools=False
 if Q_school:
     wbdf = WikibaseDataFetcher.getWikidataDataFetcher()
     wikidataCoords = wbdf.getEntityDocument(Q_school)
     # print dir(wikidataCoords)
                
                found = False
                for i in range(19, 0, -1):
                    time.sleep(i/3)
                    params  = '?action=wbsearchentities&search=' + URLEncoder.encode(name, "UTF-8") + '&language=en&format=json'
                    url = baseurl + 'api.php' + params
                    r1 = HttpClient.create(URL(url), "GET")
                    r2 = r1.setHeader("Content-Type", "application/x-www-form-urlencoded").connect().fetchContent()
                    #print dir(r2)
                    print i, r2
                    Q_school = QinJSONRE.search(r2)
                    if Q_school:
                        print Q_school.group('qid')
                        break
                    else:
                        print 'not found yet'

                break
            else:
                print 'already in Wikidata'
        newSchool = Node(element)
        newSchool.put('wikidata', Q_school.group('qid'))
        newSchool.put('isced:level', isced)

        CommandsList=[Command.ChangeCommand( element, newSchool)]
        Main.main.undoRedo.add(Command.SequenceCommand("Add wikidata and isced:level tags to school", CommandsList))




     # pprint.pprint(result)
     if 'success' in result and result['search']:
         for res in result['search']:
             print res
             if 'description' in res and res['description'] == description:
                 Q_school = res['id']
                 print Q_school
                 if type=='node':
                     newSchool = Node(element)
                 elif type=='way':
                     newSchool = Way(element)
                 else:
                     newSchool = Relation(element)
                 dirty =False
                 if newSchool.get('wikidata') != Q_school:
                     newSchool.put('wikidata', Q_school); dirty=True
                 if not(isced_level) and isced and newSchool.get('isced:level') != isced_level:
                     newSchool.put('isced:level', isced); dirty=True
                 if dirty:
                     CommandsList=[Command.ChangeCommand( element, newSchool)]
                     Main.main.undoRedo.add(Command.SequenceCommand("Add wikidata and isced:level tags to school", CommandsList))
                 found = True
                 break
         if found: break
     else:
         print 'not found yet'
 if element.isNew(): noNewSchools=False
 if Q_school:
     wikidataCoords = wd.fetchCoordinates(Q_school)
     print wikidataCoords
     if not(wikidataCoords['claims']):
コード例 #5
0
    if not(selectedNodes or selectedWays or selectedRelations):
        JOptionPane.showMessageDialog(Main.parent, "Please select some node, way, or relation.")
    else:
    
        if (selectedNodes):

	        for node in selectedNodes:
	        	nodeChanged = False
	        	oldname = node.get('name')
	        	if not(oldname): oldname = ''
	        	if pattern.match(oldname):
	        		newNode = Node(node)
	        		newname = oldname
		        	newname = re.sub("^E","e", newname)
		        	newname = re.sub("^L","l", newname)
		        	newname = re.sub("^S","s", newname)
		        	newNode.put("name", newname)
		        	if (forceNameCA): newNode.put("name:ca", newname)
		        	
		        	commandsList.append(Command.ChangeCommand(node, newNode))
		        	Main.main.undoRedo.add(Command.SequenceCommand("Changed name "+oldname, commandsList))
		        	commandsList = []
		
        if (selectedWays):
			JOptionPane.showMessageDialog(Main.parent, "You have selected some way.")
        if (selectedRelations):
	    	JOptionPane.showMessageDialog(Main.parent, "You have selected some relation.")
			


コード例 #6
0
 if 'success' in result and result['search']:
     for res in result['search']:
         print res
         if 'description' in res and res[
                 'description'] == description:
             Q_school = res['id']
             print Q_school
             if type == 'node':
                 newSchool = Node(element)
             elif type == 'way':
                 newSchool = Way(element)
             else:
                 newSchool = Relation(element)
             dirty = False
             if newSchool.get('wikidata') != Q_school:
                 newSchool.put('wikidata', Q_school)
                 dirty = True
             if not (isced_level) and isced and newSchool.get(
                     'isced:level') != isced_level:
                 newSchool.put('isced:level', isced)
                 dirty = True
             if dirty:
                 CommandsList = [
                     Command.ChangeCommand(element, newSchool)
                 ]
                 Main.main.undoRedo.add(
                     Command.SequenceCommand(
                         "Add wikidata and isced:level tags to school",
                         CommandsList))
             found = True
             break
コード例 #7
0
            Main.parent, "Please select some node, way, or relation.")
    else:

        if (selectedNodes):

            for node in selectedNodes:
                nodeChanged = False
                oldname = node.get('name')
                if not (oldname): oldname = ''
                if pattern.match(oldname):
                    newNode = Node(node)
                    newname = oldname
                    newname = re.sub("^E", "e", newname)
                    newname = re.sub("^L", "l", newname)
                    newname = re.sub("^S", "s", newname)
                    newNode.put("name", newname)
                    if (forceNameCA): newNode.put("name:ca", newname)

                    commandsList.append(Command.ChangeCommand(node, newNode))
                    Main.main.undoRedo.add(
                        Command.SequenceCommand("Changed name " + oldname,
                                                commandsList))
                    commandsList = []

        if (selectedWays):
            JOptionPane.showMessageDialog(Main.parent,
                                          "You have selected some way.")
        if (selectedRelations):
            JOptionPane.showMessageDialog(Main.parent,
                                          "You have selected some relation.")