Created
April 2, 2017 12:44
-
-
Save agustincl/1fc31d5c22f4f1ff842ad5494fd16228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import read | |
from flask import Flask | |
from flask_cors import CORS, cross_origin | |
app = Flask(__name__) | |
CORS(app) | |
@app.route("/") | |
def home(): | |
from couchbase.bucket import Bucket | |
bucket = Bucket('couchbase://10.7.0.11/eess') | |
n1ql = 'SELECT count(`Precio Biodiesel`) as Biodiesel, count(`Precio Bioetanol`) as Bioetanol, count(`Precio Gas Natural Comprimido`) as GNC, count(`Precio Gas Natural Licuado`) as GNL,count(`Precio Gases licuados del petróleo`) as GLP,count(`Precio Gasoleo A`) as GasoleoA,count(`Precio Gasoleo B`) as GasoleoB,count(`Precio Gasolina 95 Protección`) as Gasolina95,count(`Precio Gasolina 98`) as Gasolina98,count(`Precio Nuevo Gasoleo A`) as NGasoleoA FROM eess as estation where meta().id like "IDEESS%"' | |
# print n1ql | |
from couchbase.n1ql import N1QLQuery | |
query = N1QLQuery(n1ql) | |
rows = ''; | |
for row in bucket.n1ql_query(query): | |
# print(row['GasoleoB']) | |
rows = rows + '{"c":[{"v":"Biodiesel","f":null},{"v":' + str(row['Biodiesel']) + ',"f":null}]},' | |
rows = rows + '{"c":[{"v":"Bioetanol","f":null},{"v":' + str(row['Bioetanol']) + ',"f":null}]},' | |
rows = rows + '{"c":[{"v":"GLP","f":null},{"v":' + str(row['GLP']) + ',"f":null}]},' | |
rows = rows + '{"c":[{"v":"GNC","f":null},{"v":' + str(row['GNC']) + ',"f":null}]},' | |
rows = rows + '{"c":[{"v":"GNL","f":null},{"v":' + str(row['GNL']) + ',"f":null}]},' | |
rows = rows + '{"c":[{"v":"GasoleoA","f":null},{"v":' + str(row['GasoleoA']) + ',"f":null}]},' | |
rows = rows + '{"c":[{"v":"Gasolina95","f":null},{"v":' + str(row['Gasolina95']) + ',"f":null}]},' | |
rows = rows + '{"c":[{"v":"Gasolina98","f":null},{"v":' + str(row['Gasolina98']) + ',"f":null}]},' | |
rows = rows + '{"c":[{"v":"NGasoleoA","f":null},{"v":' + str(row['NGasoleoA']) + ',"f":null}]},' | |
json = '{"cols":[{"id":"","label":"type","pattern":"","type":"string"},{"id":"","label":"Biodiesel","pattern":"","type":"number"},{"id":"","label":"Bioetanol","pattern":"","type":"number"},{"id":"","label":"GLP","pattern":"","type":"number"},{"id":"","label":"GNC","pattern":"","type":"number"},{"id":"","label":"GNL","pattern":"","type":"number"},{"id":"","label":"GasoleoA","pattern":"","type":"number"},{"id":"","label":"GasoleoB","pattern":"","type":"number"},{"id":"","label":"Gasolina95","pattern":"","type":"number"},{"id":"","label":"Gasolina98","pattern":"","type":"number"},{"id":"","label":"NGasoleoA","pattern":"","type":"number"}],"rows": [' + rows[:-1] + ']}' | |
return json | |
if __name__ == "__main__": | |
app.run(host= '0.0.0.0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment