Skip to content
Snippets Groups Projects
Commit c1a0c93c authored by Jeremy M Fee's avatar Jeremy M Fee
Browse files

Use os line separator, convert iteration group to list for reuse

parent a12b94d1
No related branches found
No related tags found
No related merge requests found
...@@ -95,6 +95,8 @@ calfile = [] ...@@ -95,6 +95,8 @@ calfile = []
cals = sorted(cals, key=lambda c: c['start']) cals = sorted(cals, key=lambda c: c['start'])
# group by date # group by date
for date, cals in itertools.groupby(cals, key=lambda c: c['start'].date()): for date, cals in itertools.groupby(cals, key=lambda c: c['start'].date()):
# convert group to list so it can be reused
cals = list(cals)
# within each day, order by H, then D, then Z # within each day, order by H, then D, then Z
for channel in ['H', 'D', 'Z']: for channel in ['H', 'D', 'Z']:
channel_cals = [c for c in cals if c['channel'] == channel] channel_cals = [c for c in cals if c['channel'] == channel]
...@@ -104,13 +106,14 @@ for date, cals in itertools.groupby(cals, key=lambda c: c['start'].date()): ...@@ -104,13 +106,14 @@ for date, cals in itertools.groupby(cals, key=lambda c: c['start'].date()):
# add channel header # add channel header
calfile.append(CAL_HEADER_FORMAT.format(channel=channel, date=date)) calfile.append(CAL_HEADER_FORMAT.format(channel=channel, date=date))
calfile.extend([CAL_LINE_FORMAT.format(**c) for c in channel_cals]) calfile.extend([CAL_LINE_FORMAT.format(**c) for c in channel_cals])
calfile.append('')
# write calfile # write calfile
filename = FILENAME_FORMAT.format(OBSERVATORY=OBSERVATORY, YEAR=YEAR) filename = FILENAME_FORMAT.format(OBSERVATORY=OBSERVATORY, YEAR=YEAR)
print >> sys.stderr, 'Writing cal file to {}'.format(filename) print >> sys.stderr, 'Writing cal file to {}'.format(filename)
with open(filename, 'wb', -1) as f: with open(filename, 'wb', -1) as f:
f.write('\n'.join(calfile) + '\n') f.write(os.linesep.join(calfile))
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment