#!/usr/bin/python # -*- coding: utf8 -*- import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt import MySQLdb import datetime heute = datetime.date.today() tag = datetime.date.today().day mon = datetime.date.today().month jahr = datetime.date.today().year if tag == 1: mon = mon - 1 erster = datetime.date(jahr,mon,1) db = MySQLdb.connect(host="localhost", user="", passwd="", db="") cur = db.cursor() sql1 = "select date_format(datum,'%d.%m.%Y'), min(temp), max(temp) from wetter where datum >= '" sql2 = "' and datum < '" sql3 = "' group by date_format(datum,'%d.%m.%Y') order by datum" read_wetter = sql1 + erster.strftime("%Y-%m-%d") + sql2 + heute.strftime("%Y-%m-%d") + sql3 cur.execute (read_wetter) results = cur.fetchall() ltag = [] lmin = [] lmax = [] ymin = 30.0 ymax = -10.0 xmax = 0.0 lmonat = ['Januar','Februar','Maerz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'] for row in results: recdate = str(row[0]) mintemp = str(row[1]) maxtemp = str(row[2]) print recdate, recdate[0:2], mintemp, maxtemp lmin.append(row[1]) lmax.append(row[2]) ltag.append(float(recdate[0:2])) if ymin > row[1]: ymin = row[1] if ymax < row[2]: ymax = row[2] print ltag print lmin print lmax ymin = ymin - 3 ymax = ymax + 5 xmax = ltag[-1] + 1 cur.close() db.close () plt.xlabel(lmonat[mon-1] + " " + heute.strftime("%Y")) plt.ylabel('Grad Celsius') plt.title('Temperaturen Neu-Anspach') plt.plot(ltag, lmin, ltag, lmin, "bo", ltag, lmax, ltag, lmax, "ro") plt.axis([0, xmax, ymin, ymax]) fname = "temp" + heute.strftime("%Y%m") + ".jpg" print fname plt.savefig(fname)