-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIO.py
94 lines (70 loc) · 1.92 KB
/
IO.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import os
import MySQLdb
path_local = os.path.dirname(os.path.realpath(__file__))
with open(path_local+'/data/topojson/semiarido.json') as data_file:
_state_division_sab = json.load(data_file)
def states_sab():
"""return a json"""
return _state_division_sab
with open(path_local+'/data/brasil.json') as data_file:
_json_brazil = json.load(data_file)
def json_brazil():
"""return a json"""
return _json_brazil
def delete_DB_upload():
try:
conn = MySQLdb.connect(read_default_group='INSA',db="INSA")
cursor = conn.cursor()
cursor.execute("truncate tb_monitoramento_upload;")
conn.commit()
finally:
cursor.close()
conn.close()
def replace_reservat_history(reservatId):
conn = MySQLdb.connect(read_default_group='INSA',db="INSA")
cursor = conn.cursor()
ret = False
try:
cursor.execute("call replace_reservat_history(" + reservatId + ");")
conn.commit()
ret = True
finally:
cursor.close()
conn.close()
return ret
def insert_many_BD_upload(values):
conn = MySQLdb.connect(read_default_group='INSA',db="INSA")
cursor = conn.cursor()
try:
cursor.executemany("""INSERT INTO tb_monitoramento_upload (id_reservatorio,cota,volume,volume_percentual,data_informacao,visualizacao,fonte) VALUES (%s,%s,%s,%s,%s,%s,%s)""", values)
conn.commit()
except MySQLdb.Error as e:
print "Error", e
conn.rollback()
cursor.close()
conn.close()
def select_DB(query):
""" Connect to MySQL database """
try:
conn = MySQLdb.connect(read_default_group='INSA',db="INSA")
cursor = conn.cursor()
cursor.execute(query)
rows = cursor.fetchall()
finally:
cursor.close()
conn.close()
return rows
def select_one_DB(query):
""" Connect to MySQL database """
try:
conn = MySQLdb.connect(read_default_group='INSA',db="INSA")
cursor = conn.cursor()
cursor.execute(query)
rows = cursor.fetchone()
finally:
cursor.close()
conn.close()
return rows