+def main():
+ parser = argparse.ArgumentParser('Plot log.csv.')
+ parser.add_argument('filename', nargs='?', default='log.csv', help='Name of csv file')
+ parser.add_argument('-t', '--temperature', action='store_true', help='Include temperature plot')
+ args = parser.parse_args()
+
+ with open(args.filename) as f:
+ reader = csv.reader(f)
+ headers = next(reader)
+
+ time = []
+ co2 = []
+ temp = []
+ for row in reader:
+ dt = datetime.strptime(row[0], '%Y-%m-%d %H:%M:%S')
+ if len(time) > 0 and dt - time[-1] < timedelta(hours=-2): # DST switch!
+ dt += timedelta(days=1)
+ time.append(dt)
+ co2.append(int(row[2]))
+ temp.append(int(row[3]))
+
+ plt.plot(time, co2, c = 'red')
+ plt.title('CO₂')
+ plt.xlabel('time')
+ plt.ylabel('ppm')
+ plt.tick_params(axis = 'both', which = 'major')
+ if args.temperature is True:
+ plt.gca().twinx()
+ plt.plot(time, temp, c = 'blue')
+ plt.show()