Skip to content

Instantly share code, notes, and snippets.

@Miguel000
Last active June 14, 2016 09:45
Show Gist options
  • Save Miguel000/b02cfd9f0238195a68e0 to your computer and use it in GitHub Desktop.
Save Miguel000/b02cfd9f0238195a68e0 to your computer and use it in GitHub Desktop.

Revisions

  1. Miguel000 revised this gist Nov 30, 2015. 1 changed file with 4 additions and 12 deletions.
    16 changes: 4 additions & 12 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -59,24 +59,16 @@ def userprocess(self):
    typeRelation = ""
    crearRelation=True
    item = self.listEntities[i]
    if item.keys()[0].endswith("default"):
    self.log(str("VALOR ENTIDAD START : " + item.keys()[1]))
    self.log(str("VALOR RELACION : " + item.values()[1] ))
    self.log(str("VALOR ENTIDAD END : " + item.values()[0]))
    else:
    self.log(str("VALOR ENTIDAD START : " + item.keys()[0]))
    self.log(str("VALOR RELACION : " + item.values()[0]))
    self.log(str("VALOR ENTIDAD END : " + item.values()[1]))
    try:
    if item.keys()[0].endswith("default"):
    typeRelation = item.values()[1]
    idStart = self.getField(item.keys()[1])
    idEnd = self.getField(item.values()[0])
    idStart = str(self.getField(item.keys()[1]))
    idEnd = str(self.getField(item.values()[0]))

    else:
    typeRelation = item.values()[0]
    idStart = self.getField(item.keys()[0])
    idEnd = self.getField(item.values()[1])
    idStart = str(self.getField(item.keys()[0]))
    idEnd = str(self.getField(item.values()[1]))

    endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
    finalUrl = self.url + endUrlnode
  2. Miguel000 revised this gist Nov 26, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -112,7 +112,7 @@ def userprocess(self):
    finalUrlrelation = self.url + endUrlnode
    payload = '{"to": "'+idnodeend+'" , "type" : "'+typeRelation+'"}'
    response = requests.post(finalUrlrelation, headers=headers, data=payload)
    self.log("CREATE RELATION: " + str(response.text))
    self.log("CREATE RELATION: " + str(response.json()))

    except Exception, ex:
    self.log("Una Entidad no tiene ningun valor : " + str(ex))
  3. Miguel000 revised this gist Nov 26, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -82,15 +82,15 @@ def userprocess(self):
    finalUrl = self.url + endUrlnode
    payload = '{"key" : "'+self.key+'" , "value" : "'+idStart+'" }'
    response = requests.post(finalUrl, headers=headers, data=payload)
    self.log("DEFAULT ENTITY: " + str(response.text))
    self.log("DEFAULT ENTITY: " + str(response.json()))
    idnodestart = str(response.json().get('metadata').get('id'))
    payload = '{"key" : "'+self.key+'" , "value" : "'+idEnd+'" }'
    response = requests.post(finalUrl, headers=headers, data=payload)
    self.log("EXIST 2 ENTITY: " + str(response.text))
    self.log("EXIST 2 ENTITY: " + str(response.json()))
    idnodeend = str(response.json().get('metadata').get('id'))
    urlrelations = str(response.json().get('incoming_relationships'))
    response = requests.get(urlrelations, headers=headers)
    self.log("EXIST RELATION: " + str(response.text))
    self.log("EXIST RELATION: " + str(response.json()))
    if response.text == "[ ]":
    self.log("CREO RELACION")
    crearRelation = True
  4. Miguel000 revised this gist Nov 26, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -27,6 +27,7 @@
    import json
    import base64
    import urllib
    import traceback

    class Neo4jRelationshipsUniqueId(basesinfonierdrain.BaseSinfonierDrain):

    @@ -115,6 +116,7 @@ def userprocess(self):

    except Exception, ex:
    self.log("Una Entidad no tiene ningun valor : " + str(ex))
    self.log(str(traceback.format_exc()))
    pass

    except Exception, ex:
  5. Miguel000 revised this gist Nov 25, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -68,14 +68,14 @@ def userprocess(self):
    self.log(str("VALOR ENTIDAD END : " + item.values()[1]))
    try:
    if item.keys()[0].endswith("default"):
    typeRelation = item.values()[0]
    typeRelation = item.values()[1]
    idStart = self.getField(item.keys()[1])
    idEnd = self.getField(item.values()[1])
    idEnd = self.getField(item.values()[0])

    else:
    typeRelation = item.values()[1]
    typeRelation = item.values()[0]
    idStart = self.getField(item.keys()[0])
    idEnd = self.getField(item.values()[0])
    idEnd = self.getField(item.values()[1])

    endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
    finalUrl = self.url + endUrlnode
  6. Miguel000 revised this gist Nov 25, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -60,12 +60,12 @@ def userprocess(self):
    item = self.listEntities[i]
    if item.keys()[0].endswith("default"):
    self.log(str("VALOR ENTIDAD START : " + item.keys()[1]))
    self.log(str("VALOR RELACION : " + item.values()[0] ))
    self.log(str("VALOR ENTIDAD END : " + item.values()[1]))
    else:
    self.log(str("VALOR ENTIDAD START : " + item.keys()[0]))
    self.log(str("VALOR RELACION : " + item.values()[1] ))
    self.log(str("VALOR ENTIDAD END : " + item.values()[0]))
    else:
    self.log(str("VALOR ENTIDAD START : " + item.keys()[0]))
    self.log(str("VALOR RELACION : " + item.values()[0]))
    self.log(str("VALOR ENTIDAD END : " + item.values()[1]))
    try:
    if item.keys()[0].endswith("default"):
    typeRelation = item.values()[0]
  7. Miguel000 revised this gist Nov 25, 2015. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -58,6 +58,14 @@ def userprocess(self):
    typeRelation = ""
    crearRelation=True
    item = self.listEntities[i]
    if item.keys()[0].endswith("default"):
    self.log(str("VALOR ENTIDAD START : " + item.keys()[1]))
    self.log(str("VALOR RELACION : " + item.values()[0] ))
    self.log(str("VALOR ENTIDAD END : " + item.values()[1]))
    else:
    self.log(str("VALOR ENTIDAD START : " + item.keys()[0]))
    self.log(str("VALOR RELACION : " + item.values()[1] ))
    self.log(str("VALOR ENTIDAD END : " + item.values()[0]))
    try:
    if item.keys()[0].endswith("default"):
    typeRelation = item.values()[0]
    @@ -69,9 +77,6 @@ def userprocess(self):
    idStart = self.getField(item.keys()[0])
    idEnd = self.getField(item.values()[0])

    self.log(str("VALOR ENTIDAD START : " + idStart))
    self.log(str("VALOR RELACION : " + typeRelation ))
    self.log(str("VALOR ENTIDAD END : " + idEnd))
    endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
    finalUrl = self.url + endUrlnode
    payload = '{"key" : "'+self.key+'" , "value" : "'+idStart+'" }'
  8. Miguel000 revised this gist Nov 25, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -69,6 +69,9 @@ def userprocess(self):
    idStart = self.getField(item.keys()[0])
    idEnd = self.getField(item.values()[0])

    self.log(str("VALOR ENTIDAD START : " + idStart))
    self.log(str("VALOR RELACION : " + typeRelation ))
    self.log(str("VALOR ENTIDAD END : " + idEnd))
    endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
    finalUrl = self.url + endUrlnode
    payload = '{"key" : "'+self.key+'" , "value" : "'+idStart+'" }'
  9. Miguel000 revised this gist Nov 25, 2015. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -106,12 +106,13 @@ def userprocess(self):
    self.log("CREATE RELATION: " + str(response.text))

    except Exception, ex:
    continue
    self.log("Una Entidad no tiene ningun valor : " + str(ex))
    pass

    except Exception, ex:
    self.log("Values is not a proper list element" + str(ex))
    self.log("ERROR antes de empezar el bucle : t" + str(ex))

    except Exception, ex:
    self.log("Error in check"+str(ex))
    self.log("Error al inicio : "+str(ex))

    Neo4jRelationshipsUniqueId().run()
  10. Miguel000 revised this gist Nov 25, 2015. 1 changed file with 6 additions and 8 deletions.
    14 changes: 6 additions & 8 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -56,20 +56,18 @@ def userprocess(self):
    idStart = ""
    idEnd = ""
    typeRelation = ""
    keystart=""
    keysend=""
    crearRelation=True
    item = self.listEntities[i]
    try:
    if item.keys()[0].endswith("default"):
    valueLabel = item.values()[0]
    keyNode = item.keys()[1]
    valueNode = self.getField(item.values()[1])
    typeRelation = item.values()[0]
    idStart = self.getField(item.keys()[1])
    idEnd = self.getField(item.values()[1])

    else:
    valueLabel = item.values()[1]
    keyNode = item.keys()[0]
    valueNode = self.getField(item.values()[0])
    typeRelation = item.values()[1]
    idStart = self.getField(item.keys()[0])
    idEnd = self.getField(item.values()[0])

    endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
    finalUrl = self.url + endUrlnode
  11. Miguel000 revised this gist Nov 25, 2015. 1 changed file with 48 additions and 43 deletions.
    91 changes: 48 additions & 43 deletions Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -60,50 +60,55 @@ def userprocess(self):
    keysend=""
    crearRelation=True
    item = self.listEntities[i]
    for key in item.keys():
    if not key.endswith("default"):
    self.log("CLAVE NO DEFAULT " + str(key))
    idStart = self.getField(key)
    typeRelation = item[key]
    self.log("VALUE NO DEFAULT " + str(item[key]))
    try:
    if item.keys()[0].endswith("default"):
    valueLabel = item.values()[0]
    keyNode = item.keys()[1]
    valueNode = self.getField(item.values()[1])

    else:
    idEnd = self.getField(item[key])
    self.log("VALUE DEFAULT " + str(item[key]))
    endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
    finalUrl = self.url + endUrlnode
    payload = '{"key" : "'+self.key+'" , "value" : "'+idStart+'" }'
    response = requests.post(finalUrl, headers=headers, data=payload)
    self.log("DEFAULT ENTITY: " + str(response.text))
    idnodestart = str(response.json().get('metadata').get('id'))
    payload = '{"key" : "'+self.key+'" , "value" : "'+idEnd+'" }'
    response = requests.post(finalUrl, headers=headers, data=payload)
    self.log("EXIST 2 ENTITY: " + str(response.text))
    idnodeend = str(response.json().get('metadata').get('id'))
    urlrelations = str(response.json().get('incoming_relationships'))
    response = requests.get(urlrelations, headers=headers)
    self.log("EXIST RELATION: " + str(response.text))
    if response.text == "[ ]":
    self.log("CREO RELACION")
    crearRelation = True
    else:
    self.log("ENTRO SI EXISTER RELACIONES")
    for j in response.json():
    self.log(str(j))
    existrelation = str(j['start'])
    idstart = existrelation.split("/")
    self.log(str(idstart))
    idfin = idstart[-1]
    if idfin == idnodestart:
    if j['metadata']['type'] == typeRelation:
    self.log("TODO ES IGUAL, RELACION EXISTENTE")
    crearRelation = False
    if crearRelation:
    self.log("ENTRO, nodo inicial: ")
    endUrlnode = "node/"+idnodestart+"/relationships"
    finalUrlrelation = self.url + endUrlnode
    payload = '{"to": "'+idnodeend+'" , "type" : "'+typeRelation+'"}'
    response = requests.post(finalUrlrelation, headers=headers, data=payload)
    self.log("CREATE RELATION: " + str(response.text))
    valueLabel = item.values()[1]
    keyNode = item.keys()[0]
    valueNode = self.getField(item.values()[0])

    endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
    finalUrl = self.url + endUrlnode
    payload = '{"key" : "'+self.key+'" , "value" : "'+idStart+'" }'
    response = requests.post(finalUrl, headers=headers, data=payload)
    self.log("DEFAULT ENTITY: " + str(response.text))
    idnodestart = str(response.json().get('metadata').get('id'))
    payload = '{"key" : "'+self.key+'" , "value" : "'+idEnd+'" }'
    response = requests.post(finalUrl, headers=headers, data=payload)
    self.log("EXIST 2 ENTITY: " + str(response.text))
    idnodeend = str(response.json().get('metadata').get('id'))
    urlrelations = str(response.json().get('incoming_relationships'))
    response = requests.get(urlrelations, headers=headers)
    self.log("EXIST RELATION: " + str(response.text))
    if response.text == "[ ]":
    self.log("CREO RELACION")
    crearRelation = True
    else:
    self.log("ENTRO SI EXISTER RELACIONES")
    for j in response.json():
    self.log(str(j))
    existrelation = str(j['start'])
    idstart = existrelation.split("/")
    self.log(str(idstart))
    idfin = idstart[-1]
    if idfin == idnodestart:
    if j['metadata']['type'] == typeRelation:
    self.log("TODO ES IGUAL, RELACION EXISTENTE")
    crearRelation = False
    if crearRelation:
    self.log("ENTRO, nodo inicial: ")
    endUrlnode = "node/"+idnodestart+"/relationships"
    finalUrlrelation = self.url + endUrlnode
    payload = '{"to": "'+idnodeend+'" , "type" : "'+typeRelation+'"}'
    response = requests.post(finalUrlrelation, headers=headers, data=payload)
    self.log("CREATE RELATION: " + str(response.text))

    except Exception, ex:
    continue

    except Exception, ex:
    self.log("Values is not a proper list element" + str(ex))
  12. Miguel000 revised this gist Nov 25, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -60,7 +60,6 @@ def userprocess(self):
    keysend=""
    crearRelation=True
    item = self.listEntities[i]
    lkeys = self.listkeys[i]
    for key in item.keys():
    if not key.endswith("default"):
    self.log("CLAVE NO DEFAULT " + str(key))
  13. Miguel000 renamed this gist Nov 25, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Neo4jRelationships2.py → Neo4jRelationshipsUniqueId.py
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@
    import base64
    import urllib

    class Neo4jRelationships2(basesinfonierdrain.BaseSinfonierDrain):
    class Neo4jRelationshipsUniqueId(basesinfonierdrain.BaseSinfonierDrain):


    def __init__(self):
    @@ -112,4 +112,4 @@ def userprocess(self):
    except Exception, ex:
    self.log("Error in check"+str(ex))

    Neo4jRelationships2().run()
    Neo4jRelationshipsUniqueId().run()
  14. Miguel000 created this gist Nov 25, 2015.
    115 changes: 115 additions & 0 deletions Neo4jRelationships2.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,115 @@
    #!/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 urllib

    class Neo4jRelationships2(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.key = self.getParam("key")
    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"
    self.log(str(self.config))
    try:
    for i in range(len(self.listEntities)):
    idStart = ""
    idEnd = ""
    typeRelation = ""
    keystart=""
    keysend=""
    crearRelation=True
    item = self.listEntities[i]
    lkeys = self.listkeys[i]
    for key in item.keys():
    if not key.endswith("default"):
    self.log("CLAVE NO DEFAULT " + str(key))
    idStart = self.getField(key)
    typeRelation = item[key]
    self.log("VALUE NO DEFAULT " + str(item[key]))
    else:
    idEnd = self.getField(item[key])
    self.log("VALUE DEFAULT " + str(item[key]))
    endUrlnode = "index/node/"+self.index+"?uniqueness=get_or_create"
    finalUrl = self.url + endUrlnode
    payload = '{"key" : "'+self.key+'" , "value" : "'+idStart+'" }'
    response = requests.post(finalUrl, headers=headers, data=payload)
    self.log("DEFAULT ENTITY: " + str(response.text))
    idnodestart = str(response.json().get('metadata').get('id'))
    payload = '{"key" : "'+self.key+'" , "value" : "'+idEnd+'" }'
    response = requests.post(finalUrl, headers=headers, data=payload)
    self.log("EXIST 2 ENTITY: " + str(response.text))
    idnodeend = str(response.json().get('metadata').get('id'))
    urlrelations = str(response.json().get('incoming_relationships'))
    response = requests.get(urlrelations, headers=headers)
    self.log("EXIST RELATION: " + str(response.text))
    if response.text == "[ ]":
    self.log("CREO RELACION")
    crearRelation = True
    else:
    self.log("ENTRO SI EXISTER RELACIONES")
    for j in response.json():
    self.log(str(j))
    existrelation = str(j['start'])
    idstart = existrelation.split("/")
    self.log(str(idstart))
    idfin = idstart[-1]
    if idfin == idnodestart:
    if j['metadata']['type'] == typeRelation:
    self.log("TODO ES IGUAL, RELACION EXISTENTE")
    crearRelation = False
    if crearRelation:
    self.log("ENTRO, nodo inicial: ")
    endUrlnode = "node/"+idnodestart+"/relationships"
    finalUrlrelation = self.url + endUrlnode
    payload = '{"to": "'+idnodeend+'" , "type" : "'+typeRelation+'"}'
    response = requests.post(finalUrlrelation, headers=headers, data=payload)
    self.log("CREATE RELATION: " + str(response.text))

    except Exception, ex:
    self.log("Values is not a proper list element" + str(ex))

    except Exception, ex:
    self.log("Error in check"+str(ex))

    Neo4jRelationships2().run()