12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import csv
- import codecs
- import pandas as pd
- import re
- import os
- import io
- import tokenize
- merged_data = open('ovi_table.csv', 'w')
- csvwriter = csv.writer(merged_data)
- params = ['sigla', 'toponimo', 'TGN', 'ID RESTORE']
- csvwriter.writerow(params)
- def get_IdRestore(tgn):
- link_file = open('/Users/alessiaspadi/Documents/RESTORE/temp_ASPO/Luoghi/Associa/Toponimi.csv')
- reader = csv.DictReader(link_file)
- for row in reader:
- getty = row['TGN']
- id_restore = row['ID RESTORE']
- if tgn == getty:
- return id_restore
- def get_idR(place):
- link_file = open('/Users/alessiaspadi/Documents/RESTORE/temp_ASPO/Luoghi/Associa/Toponimi.csv')
- reader = csv.DictReader(link_file)
- for row in reader:
- name_place = row['TOPONIMO'].lower()
- pp = place.lower()
- if name_place == pp:
- return row['ID RESTORE']
- def get_TGN(aspo):
- link_file = open('/Users/alessiaspadi/Documents/RESTORE/temp_ASPO/Luoghi/Associa/Luoghi_ASPO.csv')
- reader = csv.DictReader(link_file)
- for row in reader:
- getty = row['getty_code']
- id_aspo = row['ID ASPO']
- if aspo == id_aspo:
- return getty
- merge_file = open('/Users/alessiaspadi/Documents/RESTORE/temp_ASPO/Luoghi/Associa/OVI.csv')
- reader = csv.DictReader(merge_file)
- for row in reader:
- line = []
- sigla = row['sigla']
- toponimo = row['toponimo']
- tgn = row['tgn']
- id_restore = get_IdRestore(tgn)
- line.append(sigla)
- line.append(toponimo)
- line.append(tgn)
- if id_restore is not None:
- line.append(id_restore)
- else:
- line.append("")
- csvwriter.writerow(line)
- merged_data.close()
|