Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf-8
- import json
- import requests
- import re
- import arcpy
- fc = r'C:\Users\Noah\Desktop\gundog\chandler\test\test_parcels_codes_dissolve.shp'
- arcpy.AddField_management(fc, 'company_id', "TEXT", "", "", "50")
- fields = ['OWNER', 'company_id']
- results =[]
- def hasNumbers(inputString):
- return any(char.isdigit() for char in inputString)
- def get_companies(companies):
- count = 0
- company_no = None
- company_id = ''
- for item in companies:
- company = item['company']
- company_no = company['company_number']
- count += 1
- if company_no is not None and count == 1:
- company_id = company_no
- results.append(company_no)
- else:
- company_id = ''
- print company_id
- return company_id
- stopwords = ['ASSOC', 'HOMEOWNER\'S', 'INC', 'IN', 'ASSN', 'HOA', 'ASSO', 'NO', 'ASS', "THE"]
- jurisdiction_code = 'us_az'
- key = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
- api_key = ''
- if key:
- api_key = '&api_token=' + key + '&per_page=100'
- count = 1
- with arcpy.da.UpdateCursor(fc, fields) as cursor:
- for row in cursor:
- querywords = row[0].split()
- resultwords = [word for word in querywords if word not in stopwords]
- result = ' '.join(resultwords)
- if hasNumbers(result) == True:
- parentsub = re.split(r'(^[^\d]+)', result)[1]
- wildcard = '*' + parentsub.rstrip() + '*'
- else:
- parentsub = result
- wildcard = '*' + parentsub.rstrip() + '*'
- print str(count) + ' ' + wildcard
- PARAMS = {'q': wildcard, 'jurisdiction_code': 'us_az', 'api_token': key}
- URL = "https://api.opencorporates.com/v0.4/companies/search?"
- r = requests.get(url=URL, params=PARAMS)
- print r.url
- data = r.json()
- row[1] = get_companies(data['results']['companies'])
- cursor.updateRow(row)
- count += 1
- print ""
- print "Total matched: " + str(len(results))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement