-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpi-downloader.py
executable file
·37 lines (30 loc) · 1.25 KB
/
hpi-downloader.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
#!/usr/bin/env python3
import argparse
from urllib import request
from datetime import datetime
published = datetime.strptime('2019-02', '%Y-%m')
base_url = 'http://publicdata.landregistry.gov.uk/market-trend-data/house-price-index-data/'
types = {
'hpi-full': 'UK-HPI-full-file-2019-02.csv',
'avg-price': 'Average-prices',
'avg-by-property': 'Average-prices-Property-Type',
'sales': 'Sales',
'cash-mortgage-sales': 'Cash-mortgage-sales',
'ftb-and-foc': 'First-Time-Buyer-Former-Owner-Occupied',
'new-build-and-resold': 'New-and-Old',
'index': 'Indices',
'index-seasonal': 'Indices-seasonally-adjusted',
'avg-seasonal': 'Average-price-seasonally-adjusted',
'reposessions': 'Repossession'
}
parser = argparse.ArgumentParser()
parser.add_argument('type', help='Which data to download', choices=types.keys())
parser.add_argument('-p', '--published', help='The published date in YYYY-MM to get the files from, defaults to 2019-02')
args = parser.parse_args()
if args.published:
published = datetime.strptime(args.published, '%Y-%m')
filename = types[args.type] + '-' + published.strftime('%Y-%m') + '.csv'
try:
request.urlretrieve(base_url+filename, filename)
except request.HTTPError as e:
print('Error getting file -', e)