-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.py
36 lines (27 loc) · 1.12 KB
/
scraper.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
import scraperwiki
import xlrd
#cribbing https://scraperwiki.com/docs/python/python_excel_guide/
def cellval(cell):
if cell.ctype == xlrd.XL_CELL_EMPTY: return None
return cell.value
def dropper(table):
if table!='':
try: scraperwiki.sqlite.execute('drop table "'+table+'"')
except: pass
def reGrabber():
#dropper('GPpracticeLookup')
url='https://indicators.ic.nhs.uk/download/GP%20Practice%20data/summaries/demography/Practice%20Addresses%20Final.xls'
xlbin = scraperwiki.scrape(url)
book = xlrd.open_workbook(file_contents=xlbin)
sheet = book.sheet_by_index(0)
keys = sheet.row_values(8)
keys[1] = keys[1].replace('.', '')
print keys
for rownumber in range(9, sheet.nrows):
# create dictionary of the row values
values = [ cellval(c) for c in sheet.row(rownumber) ]
data = dict(zip(keys, values))
#print data
scraperwiki.sqlite.save(table_name='GPpracticeLookup',unique_keys=['Practice Code'], data=data)
#Uncomment the next line if you want to regrab the data from the original spreadsheet
#reGrabber()