Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for o, a in opts:
if o in ('-h', '--help'):
print(__usage__.strip(), file=sys.stderr)
return 0
# check arguments
if len(args) != 2:
print('Error: 2 arguments required\n', file=sys.stderr)
print(__usage__.strip(), file=sys.stderr)
return 2
# process arguments
in_name = args[0]
out_name = args[1]
# open input
in_file = open(in_name, 'r')
# open data store via PywwsContext
ds = pywws.storage.PywwsContext(out_name,False).raw_data
# get time to go forward to
first_stored = ds.after(datetime.min)
if first_stored == None:
first_stored = datetime.max
# copy any missing data
last_date = None
count = 0
for line in in_file:
items = line.split(',')
local_date = datetime.strptime(items[2].strip(), '%Y-%m-%d %H:%M:%S')
local_date = pywws.timezone.Local.localize(local_date)
date = local_date.astimezone(pywws.timezone.utc)
if last_date and date < last_date:
date = date + timedelta(hours=1)
print("Corrected DST ambiguity %s %s -> %s" % (
local_date, local_date.tzname(), date))
if o == '-h' or o == '--help':
print(__usage__.strip())
return 0
elif o == '-n' or o == '--noaction':
noaction = True
# check arguments
if len(args) != 1:
print('Error: 1 argument required\n', file=sys.stderr)
print(__usage__.strip(), file=sys.stderr)
return 2
data_dir = args[0]
# date & time range of data to be changed, in UTC!
start = datetime(2013, 10, 27, 11, 21)
stop = datetime(2013, 10, 29, 18, 32)
# open data store via PywwsContext
context = pywws.storage.PywwsContext(data_dir,False)
raw_data = context.raw_data
# process the data
aperture = timedelta(minutes=14, seconds=30)
# make list of changes to apply after examining the data
changes = []
for data in raw_data[start:stop]:
if data['temp_out'] is None:
continue
# get temperatures at nearby times
idx = data['idx']
temp_list = []
for local_data in raw_data[idx-aperture:idx+aperture]:
temp = local_data['temp_out']
if temp is not None:
temp_list.append(temp)
if len(temp_list) < 3:
# process options
for o, a in opts:
if o == '-h' or o == '--help':
print(__usage__.strip())
return 0
# check arguments
if len(args) != 1:
print('Error: 1 argument required\n', file=sys.stderr)
print(__usage__.strip(), file=sys.stderr)
return 2
data_dir = args[0]
# date & time range of data to be changed, in UTC!
start = datetime(2013, 10, 26, 15, 23)
stop = datetime(2013, 10, 30, 12, 47)
# open data store via PywwsContext
context = pywws.storage.PywwsContext(data_dir,False)
raw_data = context.raw_data
# change the data
for data in raw_data[start:stop]:
data['rain'] -= 263.1
raw_data[data['idx']] = data
# make sure it's saved
raw_data.flush()
# clear calibrated data that needs to be regenerated
calib_data = context.calib_data
del calib_data[start:]
calib_data.flush()
# done
return 0