#!/usr/bin/python import argparse import json from w1thermsensor import W1ThermSensor parser = argparse.ArgumentParser() parser.add_argument("-p","--path", help="Specify a specific sensor ID. If path not provided returns all.") parser.add_argument("-s","--scale", help="Choose fahrenheit (f) or celsius (c)") parser.add_argument("-r","--round", action='store_true', default=False, help="Add to round values") args = parser.parse_args() def transform ( temperature ): if args.scale == "fahrenheit" or args.scale == "f": temperature = temperature * 1.8 + 32 if args.round == True: temperature = int(round(temperature)) return temperature if args.path == None: data = {} for sensor in W1ThermSensor.get_available_sensors(): data[sensor.id] = transform(sensor.get_temperature()) print(json.dumps(data)) else: sensor = W1ThermSensor(sensor_id=args.path) temp = transform(sensor.get_temperature()) print(temp)