Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import pwb
- import pywikibot
- import sys
- import codecs
- import json
- import re
- try:
- f2 = codecs.open('CSV_OSM.txt', 'ab', 'utf8')
- except (OSError, IOError) as e:
- print u'Problemes per obrir l\'arxiu %s' % arxiu
- exit(0)
- #"ARTICLEVIQUIPEDIA" P402 "NUMIDENTIFCADOROSM" S143 Q936
- def main():
- try:
- f = codecs.open("JSONOSM.json", 'r', 'utf8')
- except (OSError, IOError) as e:
- print u'Problemes per obrir l\'arxiu %s' % arxiu
- exit(0)
- txt = f.read()
- f.close()
- jsonObject = json.loads(txt)
- for item in jsonObject['elements']:
- identificador = ""
- article = ""
- element = ""
- auxiliar = ""
- linia = ""
- if item['type'] == "relation":
- identificador = item['id']
- if identificador:
- if item['tags']:
- try:
- article = item['tags']['wikipedia']
- except:
- element = item['tags']['name']
- print u"L\'element %s no té el tag Wikipedia" % (element)
- if article:
- auxiliar = re.sub(u'(.*?):', '', article)
- #auxiliar = re.findall(u'ca\:(.*?)', article)
- linia = u"%s\tP402\t\"%s\"\tS143\tQ936\n" % (auxiliar, identificador)
- f2.write(linia)
- if __name__ == '__main__':
- main()
- f2.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement