Spaces:
Runtime error
Runtime error
| import os | |
| import json | |
| import requests | |
| import requests | |
| import urllib.parse | |
| import json | |
| from fastapi import FastAPI, File, UploadFile, Form | |
| # from Zillow_Scraper.selenium_wrapper import search | |
| API_token = os.environ['API_token'] | |
| # eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1MzRmanRmdmZwNnplcmJldHEzcnpienExZ2l6b201dyIsImlzcyI6ImRhdGFmaW5pdGkuY28ifQ.CONEaG0VEABopROdGvMWy3sBv0X8dB2rAUhijXEKRdRgAbII-zbX6FIZsV7pZ72M5BbaREhjOi9eU-5NKpvhiWnU8cjlrx0AmHRNrIBrHmPvoFE9IFeIN1pYS9nOvU6CctQB6ZvmoEMpF_VYVKwkBkmUNmY1UPF6TdINkdWg9ym0pC1TIhch4WM5akuHwlJXirzbV07SRrijnQUT1DRpt7_igbwRSt8smFUWejFDJnbxAaMeqsLHo7Trb3FgkBLAEHDdA7CgG2HONsAvOEKnf7hwpp3_mfziZ_uYO369wbfxkYIn6WnMqHYjjC6viD0b5zZI-hjZgT-87CUetWj3Oqs_B37JzqiHm0rxRHxlfFP_IvpqS263tjdnMgSUmsETy62W_cXAuk_Wn45nGiPfM26HclcZxBieYuCOFNojdZE-1apMehtXAgN0JEN29y5JZGBoSPHPZQKfvfAGEHlh-Ty3yZRiiPaQ2m4BLilZN2bB_tA0c8s7RXeHWph_t_GH5xoLO0PB_fZa_RrUmg-Cc2wsjTr59rYH-uGWpfhE-7Qa1du1tZYE4PpRqTq7KysAZzfuAgkhpJzpXwDAnuEsRDSGdhbteKnRIKajiEw8jt9KW0OnXEDOxx_cU9YrPmDvJIdvQjKKYz1Tuptce7ZmxXaHYoOtzN1I1aKpGQe1UJw | |
| format = 'JSON' | |
| # query = 'country:US AND numRoom:3 AND numFloor:1 AND postalCode:75231 AND "prices":{"amountMax": 289000}' | |
| download = False | |
| request_headers = { | |
| 'Authorization': 'Bearer ' + API_token, | |
| 'Content-Type': 'application/json', | |
| } | |
| def send_request (budget,zip_code): | |
| # query = "country:US AND numRoom:3 AND numFloor:1 AND postalCode:75231 AND {prices.amountMin:>=100} AND {prices.amountMax:<={param}} AND {prices.currency:USD} " | |
| query = "country:US AND numRoom:3 AND numFloor:1 AND postalCode:"+f"{zip_code}"+" AND {prices.amountMin:>=100} AND {prices.amountMax:<="+ f"{budget}"+"} AND {prices.currency:USD} " | |
| num_records = 7 | |
| request_data = { | |
| 'query': query, | |
| 'format': format, | |
| 'num_records': num_records, | |
| 'download': download, | |
| } | |
| # Make the API call. | |
| r = requests.post('https://api.datafiniti.co/v4/properties/search',json=request_data,headers=request_headers) | |
| if r.status_code == 200: | |
| out_data = json.loads(r.content.decode('utf8').replace('"', '\"')) | |
| print("Founded result: ",out_data['num_found']) | |
| return out_data['num_found'],out_data['records'] | |
| else: | |
| print('Request failed') | |
| return None,None | |
| # _,o = send_request (8000000,19701) | |
| # print(o) | |
| # def send_zillow_request (budget,zip_code): | |
| # inf = search(zipcode=zip_code, budget=budget, for_sale = "rent") | |
| # return 1, inf | |
| # # r = requests.post('https://api.datafiniti.co/v4/properties/search',json=request_data,headers=request_headers) | |
| # # if r.status_code == 200: | |
| # # out_data = json.loads(r.content.decode('utf8').replace('"', '\"')) | |
| # # print("Founded result: ",out_data['num_found']) | |
| # # return out_data['num_found'],out_data['records'] | |
| # # else: | |
| # # print('Request failed') | |
| # # return None,None | |
| # ## 1. Health Check | |
| # url = "https://api.datafiniti.co/v4/health" | |
| # response = requests.request("GET", url, headers=[]) | |
| # print(response.text) | |
| # ## 2. Authentication | |
| # url = "https://api.datafiniti.co/v4/auth" | |
| # header= {"key": "Content-Type", | |
| # "name": "Content-Type", | |
| # "type": "text", | |
| # "value": "application/json" | |
| # } | |
| # # payload = json.dumps({ | |
| # body = {"mode": "raw","raw": "{\n\t\"email\": \"ar@playpingpong.co\",\n\t\"password\": \"p@ssWord123\"\n\t\n}"} | |
| # response = requests.request("POST", url, headers=header, data=body) | |
| # print(response.text) | |
| # query = "country:US AND numRoom:3 AND numFloor:1 AND postalCode:75231 AND {prices.amountMin:>=100} AND {prices.amountMax:<= "+ f"{param}"+ "} AND {prices.currency:USD} " | |