-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpm_4.py
More file actions
44 lines (35 loc) · 911 Bytes
/
pm_4.py
File metadata and controls
44 lines (35 loc) · 911 Bytes
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
# -*- coding: utf-8 -*-
"""
pm_4.py
same as pm_2.py but the data retrieval uses the OpenDB class
"""
# import statements
import MySQLdb # MySQL api
from matplotlib.pylab import *
from openDB import *
#get the data
#get your connection identifiers
f=open('./identifiers.txt')
mylogin=f.readline().strip('\n')
mypass=f.readline().strip('\n')
#establish the connection
o=OpenDB(base="Parcelle",host="localhost",user=mylogin,passwd=mypass)
#write and execute the query
sql="select date(date), sum(precip) from imetos group by date(date)"
rows=o.execQuery(sql)
# define the variables as an empty python list
da=[]
pr=[]
# for each record returned store the values
for row in rows:
da.append(row[0])
pr.append(row[1])
# plot the results
fig=figure(1)
bar(da,pr)
xlabel('Date')
ylabel('Precipitation in mm')
fig.autofmt_xdate() # command to get the dates plotted correctly
show()
#close database
o.close()