@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

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.22255991597432878","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHJlcXVlc3RzCmltcG9ydCBqc29uCmltcG9ydCBkZW1qc29uCgp1cmwgPSAiaHR0cHM6Ly9zY2Fsci5hcGkuYXBwYmFzZS5pby9ob3VzaW5nLWRlbW8vbGlzdGluZy9fc2VhcmNoIgoKcGF5bG9hZCA9IGRlbWpzb24uZW5jb2RlKHsKICAicXVlcnkiOiB7CiAgICAiYm9vbCI6IHsKICAgICAgIm11c3QiOiBbCiAgICAgICAgewogICAgICAgICAgInJhbmdlIjogewogICAgICAgICAgICAiZGF0ZV9mcm9tIjogewogICAgICAgICAgICAgICJndCI6IDIwMTcwMTAxCiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIHsKICAgICAgICAgICJyYW5nZSI6IHsKICAgICAgICAgICAgImRhdGVfdG8iOiB7CiAgICAgICAgICAgICAgImx0IjogMjAxNzA0MzAKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgXQogICAgfQogIH0KfSkKCmhlYWRlcnMgPSB7CiAgJ0F1dGhvcml6YXRpb24nOiAiQmFzaWMgV1c1RFoxWjNiM3BXT21VNVpXTTFZMkl3TFRVNFpEZ3ROR0ppTUMxaVlXUmpMV0ZqWVdZM01qWTJOakZtTVE9PSIsCiAgJ0NvbnRlbnQtVHlwZSc6ICJhcHBsaWNhdGlvbi9qc29uIgp9CgpyZXNwb25zZSA9IHJlcXVlc3RzLnJlcXVlc3QoIlBPU1QiLCB1cmwsIGRhdGE9cGF5bG9hZCwgaGVhZGVycz1oZWFkZXJzKQoKcGFyc2VkID0ganNvbi5sb2FkcyhyZXNwb25zZS50ZXh0KQpwcmludCBqc29uLmR1bXBzKHBhcnNlZCwgaW5kZW50PTIsIHNvcnRfa2V5cz1UcnVlKQ=="},"asBuffer":null},"loaded":true}}
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)