Skip to content

Instantly share code, notes, and snippets.

@Miguel000
Last active November 18, 2015 16:00
Show Gist options
  • Select an option

  • Save Miguel000/4d5b15d8bd30c69b7110 to your computer and use it in GitHub Desktop.

Select an option

Save Miguel000/4d5b15d8bd30c69b7110 to your computer and use it in GitHub Desktop.
Neo4jEntities
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
The MIT License (MIT)
Copyright (c) 2014 sinfonier-project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
import basesinfonierdrain
import requests
import json
import base64
import json
import urllib
class Neo4jEntities(basesinfonierdrain.BaseSinfonierDrain):
def __init__(self):
basesinfonierdrain.BaseSinfonierDrain().__init__()
def userprepare(self):
# Get Param (get value of "param_name" from input box)
self.url = self.getParam("urlDatabase")
self.index = self.getParam("index")
self.param = self.getParam("param")
self.idkey = self.getParam("idkey")
self.listEntities = self.getParam("listEntities")
def userprocess(self):
try:
auth = base64.b64encode(self.param)
headers = {"Accept" : "application/json; charset=UTF-8","Content-Type": "application/json", "Authorization" : "Basic " + auth}
endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
finalUrl = self.url + endUrlnode
self.log(str(finalUrl))
self.log(str(self.config))
try:
for item in self.listEntities:
self.log("VALOR ITEM : " + str(item))
payload = '{"key" : "'+self.idkey+'" , "value" : "'+self.getField(item)+'" }'
self.log("PAYLOAD " + str(payload))
response = requests.post(finalUrl, headers=headers, data=payload)
self.log("CREATE ENTITY" + str(response.text))
except:
self.log("Values is not a proper list element")
except Exception, ex:
self.log("Error in check"+str(ex))
Neo4jEntities().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment