Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if o in ('-h', '--help'):
print(__usage__.strip())
return 0
# check arguments
if len(args) != 1:
print("Error: 1 argument required", file=sys.stderr)
print(__usage__.strip(), file=sys.stderr)
return 2
data_dir = args[0]
with pywws.storage.pywws_context(data_dir) as context:
params = context.params
pywws.localisation.set_application_language(params)
hourly_data = context.hourly_data
idx = hourly_data.before(datetime.max)
print('Zambretti (current):', zambretti(params, hourly_data[idx]))
idx = timezone.to_local(idx)
if idx.hour < 8 or (idx.hour == 8 and idx.minute < 30):
idx -= timedelta(hours=24)
idx = idx.replace(hour=9, minute=0, second=0)
idx = timezone.to_naive(idx)
idx = hourly_data.nearest(idx)
lcl = timezone.to_local(idx)
print('Zambretti (at %s):' % lcl.strftime('%H:%M %Z'), zambretti(
params, hourly_data[idx]))
return 0
print(__usage__.strip(), file=sys.stderr)
return 2
data_dir = args[0]
with pywws.storage.pywws_context(data_dir) as context:
params = context.params
pywws.localisation.set_application_language(params)
hourly_data = context.hourly_data
idx = hourly_data.before(datetime.max)
print('Zambretti (current):', zambretti(params, hourly_data[idx]))
idx = timezone.to_local(idx)
if idx.hour < 8 or (idx.hour == 8 and idx.minute < 30):
idx -= timedelta(hours=24)
idx = idx.replace(hour=9, minute=0, second=0)
idx = timezone.to_naive(idx)
idx = hourly_data.nearest(idx)
lcl = timezone.to_local(idx)
print('Zambretti (at %s):' % lcl.strftime('%H:%M %Z'), zambretti(
params, hourly_data[idx]))
return 0
file_encoding = 'ascii'
elif command[0] == 'roundtime':
if eval(command[1]):
round_time = timedelta(seconds=30)
else:
round_time = None
elif command[0] == 'jump':
prevdata = data
idx, valid_data = jump(idx, int(command[1]))
data = data_set[idx]
elif command[0] == 'goto':
prevdata = data
time_str = command[1]
if '%' in time_str:
if local_time:
lcl = timezone.to_local(idx)
else:
lcl = timezone.to_utc(idx)
time_str = lcl.strftime(time_str)
new_idx = pywws.weatherstation.WSDateTime.from_csv(time_str)
if local_time:
new_idx = timezone.to_naive(timezone.localize(new_idx))
new_idx = data_set.after(new_idx)
if new_idx:
idx = new_idx
data = data_set[idx]
valid_data = True
else:
valid_data = False
elif command[0] == 'loop':
loop_count = int(command[1])
loop_start = tmplt.tell()
# output a value
if not valid_data:
continue
# format is: key fmt_string no_value_string conversion
# get value
if command[0] == 'calc':
x = eval(command[1])
del command[1]
else:
x = data[command[0]]
# adjust time
if isinstance(x, datetime):
if round_time:
x += round_time
if local_time:
x = timezone.to_local(x)
else:
x = timezone.to_utc(x)
# convert data
if x is not None and len(command) > 3:
x = eval(command[3])
# get format
fmt = u'%s'
if len(command) > 1:
fmt = command[1]
# write output
if x is None:
if len(command) > 2:
yield command[2]
elif isinstance(x, datetime):
if sys.version_info[0] < 3:
fmt = fmt.encode(file_encoding)