Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- The MIT License (MIT)
- Copyright (c) 2016 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 basesinfonierbolt
- import requests
- import urllib
- import os
- import requests
- import json
- from base64 import b64encode
- class OrientDBVertexesUpd (basesinfonierbolt.BaseSinfonierBolt):
- def __init__(self):
- basesinfonierbolt.BaseSinfonierBolt().__init__()
- def userprepare(self):
- # catching json_list = vertex, edge and params
- self.list = self.getParam("list")
- self.name_database = self.getParam("name_database")
- self.decision = self.getPAram("decision")
- # catching url_database and port to create the header. It will be "url_database:port"
- self.url_database = self.getParam("url_database")
- self.port = self.getParam("port")
- # Is not necesary put user and password variables. By this reason we need to see if it exists.
- #if self.existsField("user"):
- self.user = self.getParam("user")
- #if self.existsField("password"):
- self.password = self.getParam("password")
- def userprocess(self):
- try:
- if(selft.decision == no):
- # creating headers
- final_url_database = self.url_database + ":" + self.port
- user_password = self.user + ":" + self.password
- user_and_pass = b64encode(user_password).decode("ascii")
- headers = { 'Authorization' : 'Basic %s' % user_and_pass }
- # inserting data in OrientDB json
- for x in self.list:
- data_final = { "@class":x[0], x[1]:self.getField(x[2]) }
- #request necesary to create vertex and their params. Use headers and the json_list
- request = requests.post(final_url_database + "/document/" + name_database, headers = headers, data = json.dumps(data_final))
- self.emit()
- else: # UPDATE WILL BE HERE
- except Exception, ex:
- self.log("ERROR is comming : " + str(ex))
- OrientDBVertexesUpd().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement