loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6974641693228851","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHJlcXVlc3RzCmltcG9ydCBqc29uCmltcG9ydCBkZW1qc29uCgp1cmwgPSAiaHR0cHM6Ly9zY2Fsci5hcGkuYXBwYmFzZS5pby9uZXdzdHJlYW1pbmdhcHAvYm9va3MvX2J1bGsiCgojIEFycmF5IG9mIGRhdGEgb2JqZWN0cwpkYXRhQXJyYXkgPSBbCiAgewogICAgImlkIjogIlgxIiwKICAgICJkZXBhcnRtZW50X25hbWUiOiAiQm9va3MiLAogICAgImRlcGFydG1lbnRfbmFtZV9hbmFseXplZCI6ICJCb29rcyIsCiAgICAiZGVwYXJ0bWVudF9pZCI6IDEsCiAgICAibmFtZSI6ICJBIEZha2UgQm9vayBvbiBOZXR3b3JrIFJvdXRpbmciLAogICAgInByaWNlIjogMTAzMgogIH0sCiAgewogICAgImlkIjogIlgyIiwKICAgICJkZXBhcnRtZW50X25hbWUiOiAiQm9va3MiLAogICAgImRlcGFydG1lbnRfbmFtZV9hbmFseXplZCI6ICJCb29rcyIsCiAgICAiZGVwYXJ0bWVudF9pZCI6IDIsCiAgICAibmFtZSI6ICJBIEZha2UgQm9vayBvbiBDb21wdXRlciBTY2llbmNlIiwKICAgICJwcmljZSI6IDQxMjUKICB9LAogIHsKICAgICJpZCI6ICJYMyIsCiAgICAiZGVwYXJ0bWVudF9uYW1lIjogIkJvb2tzIiwKICAgICJkZXBhcnRtZW50X25hbWVfYW5hbHl6ZWQiOiAiQm9va3MiLAogICAgImRlcGFydG1lbnRfaWQiOiAzLAogICAgIm5hbWUiOiAiQSBGYWtlIEJvb2sgb24gUmVhY3RpdmUgUHJvZ3JhbW1pbmciLAogICAgInByaWNlIjogMzg0NgogIH0KXQoKcGF5bG9hZCA9ICIiCgojIENyZWF0aW5nIHJlcXVlc3QgYm9keQpmb3IgZGF0YSBpbiBkYXRhQXJyYXk6CiAgIyBQdXNoaW5nIHRoZSBvcGVyYXRpb24gYW5kIF9pZCBmb3IgZWFjaCByZXF1ZXN0CiAgdHlwZSA9IHsKICAgICJpbmRleCI6IHsKICAgICAgIl9pZCI6IGRhdGFbJ2lkJ10KICAgIH0KICB9CiAgcGF5bG9hZCArPSBkZW1qc29uLmVuY29kZSh0eXBlKSArICJcbiIgKyBkZW1qc29uLmVuY29kZShkYXRhKSArICJcbiIKCnByaW50IHBheWxvYWQKCmhlYWRlcnMgPSB7CiAgJ0F1dGhvcml6YXRpb24nOiAiQmFzaWMgYldWeFVtWTRTMHBET2pZMVkyTXhOakZoTFRJeVlXUXROREJqTlMxaFlXRm1MVFZqTURneVpEVmtZMlprWVE9PSIsCiAgJ0NvbnRlbnQtVHlwZSc6ICJhcHBsaWNhdGlvbi94LW5kanNvbiIKfQoKIyBCdWxrIHJlcXVlc3QgaW5jbHVkaW5nIHRoZSBpbmRleCBtZXRob2QgYW5kIGFsbCBkYXRhIG9iamVjdHMKcmVzcG9uc2UgPSByZXF1ZXN0cy5yZXF1ZXN0KCJQT1NUIiwgdXJsLCBkYXRhPXBheWxvYWQsIGhlYWRlcnM9aGVhZGVycykKCnBhcnNlZCA9IGpzb24ubG9hZHMocmVzcG9uc2UudGV4dCkKcHJpbnQganNvbi5kdW1wcyhwYXJzZWQsIGluZGVudD00LCBzb3J0X2tleXM9VHJ1ZSk="},"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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import requests
import json
import demjson

url = "https://scalr.api.appbase.io/newstreamingapp/books/_bulk"

# Array of data objects
dataArray = [
  {
    "id": "X1",
    "department_name": "Books",
    "department_name_analyzed": "Books",
    "department_id": 1,
    "name": "A Fake Book on Network Routing",
    "price": 1032
  },
  {
    "id": "X2",
    "department_name": "Books",
    "department_name_analyzed": "Books",
    "department_id": 2,
    "name": "A Fake Book on Computer Science",
    "price": 4125
  },
  {
    "id": "X3",
    "department_name": "Books",
    "department_name_analyzed": "Books",
    "department_id": 3,
    "name": "A Fake Book on Reactive Programming",
    "price": 3846
  }
]

payload = ""

# Creating request body
for data in dataArray:
  # Pushing the operation and _id for each request
  type = {
    "index": {
      "_id": data['id']
    }
  }
  payload += demjson.encode(type) + "\n" + demjson.encode(data) + "\n"

print payload

headers = {
  'Authorization': "Basic bWVxUmY4S0pDOjY1Y2MxNjFhLTIyYWQtNDBjNS1hYWFmLTVjMDgyZDVkY2ZkYQ==",
  'Content-Type': "application/x-ndjson"
}

# Bulk request including the index method and all data objects
response = requests.request("POST", url, data=payload, headers=headers)

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