SHARE
TWEET

Untitled

a guest Jun 18th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. try:
  2.     consulta = "SELECT "+select+" FROM parametros "
  3.     print(consulta)
  4.     cur.execute(consulta)
  5.     rows = cur.fetchall()
  6.     for row in rows:
  7.         #print(row)
  8.         lista = {}
  9.         lista['temperatura'] = row[0]
  10.         lista['ph'] = row[1]
  11.         lista['oxigeno'] = row[2]
  12.         lista['electroconductividad'] = row[3]
  13.         listas.append(lista)
  14.     #print (listas)
  15.  
  16. except Exception as inst:
  17.     print("Error en conexion con la base de datos", inst)
  18.  
  19. return json.dumps(listas)
  20.      
  21. import sqlite3
  22.  
  23. def dict_factory(cursor, row):
  24.     d = {}
  25.     for idx, col in enumerate(cursor.description):
  26.         d[col[0]] = row[idx]
  27.     return d
  28.  
  29. select = ("temperatura", "ph", "oxigeno", "electroconductividad")
  30.  
  31. conn = sqlite3.connect('test.db')
  32. conn.row_factory = dict_factory
  33.  
  34. consulta = "SELECT {} FROM parametros".format(", ".join(select))
  35. cur = conn.cursor()
  36.  
  37. cur.execute(consulta)
  38. listas = cur.fetchall()
  39.      
  40. import sqlite3
  41.  
  42.  
  43. select = ("temperatura", "ph", "oxigeno", "electroconductividad")
  44.  
  45. conn = sqlite3.connect('test.db')
  46. conn.row_factory = sqlite3.Row
  47.  
  48. consulta = "SELECT {} FROM parametros".format(", ".join(select))
  49. cur = conn.cursor()
  50.  
  51. cur.execute(consulta)
  52. listas = [dict(row) for row in cur]
  53.      
  54. [{'temperatura': 24, 'ph': 7.5, 'oxigeno': 12, 'electroconductividad': 1.2},
  55. {'temperatura': 25, 'ph': 6.3, 'oxigeno': 14, 'electroconductividad': 1.4},
  56. {'temperatura': 26.3, 'ph': 8, 'oxigeno': 15, 'electroconductividad': 1.2},
  57. {'temperatura': 27.5, 'ph': 6.2, 'oxigeno': 17, 'electroconductividad': 1.3}]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top