-
Notifications
You must be signed in to change notification settings - Fork 0
/
agente_vendedor_externo.py
55 lines (50 loc) · 1.87 KB
/
agente_vendedor_externo.py
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
from flask import Flask, jsonify, render_template, request, url_for
import requests
import json
from rdflib import Graph
from rdflib import URIRef, BNode, Literal, Namespace, RDF
from rdflib.namespace import FOAF
from rdflib.namespace import XSD
import rdflib
app = Flask(__name__)
g = Graph()
n = Namespace('http://www.owl-ontologies.com/ECSDI/projectX.owl#')
@app.route('/venderProductoExterno', methods=['GET'])
def venderProductoExterno():
try:
result = []
g.parse('prueba.rdf', format='xml')
except Exception,e:
print str(e)
try:
vendedor_externo = g.triples((None, RDF.type, n.VendedorExterno))
for s,p,o in vendedor_externo:
nombre_vendedor_externo = g.triples((s, n.nombre, None))
for s,p,o in nombre_vendedor_externo:
nombre = o.toPython()
cuenta = g.value(s, n.cuentaBancaria)
result.append({'nombre': nombre, 'cuentaBancaria': cuenta})
return render_template('venderProductoExterno.html', nombre_vendedor_externo=result)
except Exception, e:
print str(e)
@app.route('/realizarPeticion', methods=['POST'])
def realizarPeticion():
peticion = {}
try:
nombre_vendedor = request.form["nombres_vendedor"]
producto = request.form["producto"]
cuenta = request.form["cuentas"]
precio = request.form["precio"]
categoria = request.form["categoria"]
peticion = {"nombre_vendedor": nombre_vendedor,
"producto": producto,
"precio": precio,
"cuenta": cuenta,
"categoria": categoria
}
r = requests.post('http://127.0.0.1:9001/acordarProductoExterno', data=json.dumps(peticion))
return "peticion done"
except Exception, e:
print str(e)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=9002)