本文整理匯總了Python中repository.Repository.save_readings方法的典型用法代碼示例。如果您正苦於以下問題:Python Repository.save_readings方法的具體用法?Python Repository.save_readings怎麽用?Python Repository.save_readings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類repository.Repository
的用法示例。
在下文中一共展示了Repository.save_readings方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from repository import Repository [as 別名]
# 或者: from repository.Repository import save_readings [as 別名]
def main(argv):
config_file = None
read_only = False
verbose = False
try:
# -h (optional), -c (mandatory, hence 'c:'), -r (optional)
opts, args = getopt.getopt(argv,"hc:rv",[])
except getopt.GetoptError:
print 'repository.py [-h] [-r] [-v] -c <cfgfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'repository.py [-h] [-r] [-v] -c <cfgfile>'
sys.exit(0)
elif opt in ("-c", "--cfgfile"):
config_file = arg
elif opt == '-r':
read_only = True
elif opt == '-v':
verbose = True
if config_file is None:
print 'repository.py [-h] [-r] [-v] -c <cfgfile>'
sys.exit(2)
if verbose: print 'Using cfg file:', config_file
repository = Repository(config_file, verbose)
config = ConfigParser.RawConfigParser()
config.read(config_file)
sensor_names = config.get("sensors", "names").strip().split(',')
if verbose: print 'Sensor names:', sensor_names
sensors = []
for name in sensor_names:
if verbose: print 'Adding sensor:', name
sensors.append(Sensor(name, config_file))
for sensor in sensors:
if verbose: print 'Reading sensor', sensor.sensor_id
readings = sensor.get_readings()
if readings is not None:
if read_only:
s=json.dumps(readings, sort_keys=True, indent=4, separators=(',', ': '))
print s
else:
repository.save_readings(readings)
print 'Done'