repl.it
@dhruvdutt/

Appbase.io - Python - search - date

Python 2.7

Date query to get houses that are available between certain dates

fork
loading
Files
  • main.py
main.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
import requests
import json
import demjson

url = "https://scalr.api.appbase.io/housing-demo/listing/_search"

payload = demjson.encode({
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "date_from": {
              "gt": 20170101
            }
          }
        },
        {
          "range": {
            "date_to": {
              "lt": 20170430
            }
          }
        }
      ]
    }
  }
})

headers = {
  'Authorization': "Basic WW5DZ1Z3b3pWOmU5ZWM1Y2IwLTU4ZDgtNGJiMC1iYWRjLWFjYWY3MjY2NjFmMQ==",
  'Content-Type': "application/json"
}

response = requests.request("POST", url, data=payload, headers=headers)

parsed = json.loads(response.text)
print json.dumps(parsed, indent=2, sort_keys=True)