-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
64 lines (43 loc) · 1.51 KB
/
app.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# %%
import pandas as pd
import pyodbc
import requests
import json
import time
import io
from datetime import datetime
import creds
# %%
import os
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
KVUri = f"https://keyvaultproperty.vault.azure.net"
credential = DefaultAzureCredential(additionally_allowed_tenants=['*'])
client = SecretClient(vault_url=KVUri, credential=credential)
# %%
url = "https://zillow-com1.p.rapidapi.com/propertyExtendedSearch"
headers = {
"X-RapidAPI-Key": client.get_secret("X-RapidAPI-Key").value,
"X-RapidAPI-Host": client.get_secret("X-RapidAPI-Host").value
}
current_page=1
querystring = {"location":"brampton, on","home_type":"Houses","page":current_page}
data = []
response = requests.request("GET", url, headers=headers, params=querystring)
data.extend(response.json()['props'])
#fetch all pages, if there are multiple pages
while current_page<=response.json()["totalPages"]:
data.extend(response.json()['props'])
print(current_page,end='-')
current_page+=1
print('\n\n Completed extraction. Final data shape: {}'.format(len(data)))
# %%
#connect to data lake storage account
from azure.storage.blob import BlockBlobService
blobService = BlockBlobService(account_name='propertystorage89768', account_key=client.get_secret("storagekey").value)
# %%
#write into data lake
blobService.create_blob_from_text(container_name='extracted',\
blob_name=f'raw\extracted_{datetime.today().strftime("%d%m%Y")}.json',\
text=json.dumps(data))
# %%