-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixCoordsFromFile.py
62 lines (46 loc) · 1.55 KB
/
fixCoordsFromFile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from bs4 import BeautifulSoup
import pywikibot, requests, re, os, json, urllib.parse, sys
from urllib import parse
import pymysql, os
import pywikibot
from pywikibot import pagegenerators
from pywikibot.exceptions import CoordinateGlobeUnknownException
site = pywikibot.Site('wikidata', 'wikidata')
repo = site.data_repository()
prop = 'P625'
#os.chdir(r'projects/vkFIX')
def one_item(article):
item = pywikibot.ItemPage(repo,article[0])
claims = item.get()['claims']
if prop not in claims:
return
coord_lat = float(article[1])
coord_long = float(article[2])
precision = 0.00027777777777778#1/100000
target = pywikibot.Coordinate(coord_lat, coord_long, precision=precision, globe_item='http://www.wikidata.org/entity/Q2')
for one in claims[prop]:
#one = pywikibot.Claim(repo, prop)
one.changeTarget(target)
return
pywikibot.output(u'Adding %s, %s to %s' % (coord_lat,
coord_long,
item.title()))
#try:
#item.addClaim(newclaim)
#importedEnWikipedia = pywikibot.Claim(repo, u'P248')
#enWikipedia = pywikibot.ItemPage(repo, wikiitem)
#$importedEnWikipedia.setTarget(enWikipedia)
#newclaim.addSources([importedEnWikipedia])
#except CoordinateGlobeUnknownException as e:
# pywikibot.output(u'Skipping unsupported globe: %s' % e.args)
#
file = eval(open("toWDcdffdfdfdoordsAREAfix.txt", "r", encoding='utf-8').read())
counter = 0
for one in file:
one_item(one)
counter += 1
if counter % 50 == 0:
print(counter)
sys.stdout.flush()
#
print('done')