Skip to content

Commit

Permalink
better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
newwaylw committed Jul 30, 2022
1 parent a354a59 commit c6e6bcb
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions tide_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,34 @@ def parse_record(self, area_id, port_id):
return tide_record_list

def write(self, port_id):
area_id = self.get_region(port_id)
tide_list = self.parse_record(area_id, port_id)
if len(tide_list) == 0:
log.warning("No record found, something is wrong with the url?")
else:
log.debug(f"inserting records, port_id={port_id}, region_id={area_id}, no. record={len(tide_list)}")
try:
area_id = self.get_region(port_id)
tide_list = self.parse_record(area_id, port_id)
if len(tide_list) == 0:
log.warning("No record found, something is wrong with the url?")
else:
log.debug(f"inserting records, port_id={port_id}, region_id={area_id}, no. record={len(tide_list)}")

for record in tide_list:
self.insert(record)
self.con.commit()
return True
except:
msg = f"parsing record for {port_id} tried {self.parse_record.retry.statistics['attempt_number']} times but failed"
log.error(msg)
return False


def write_all(self):
count = 0
wait_interval = int(self.config['DEFAULT']['Interval'])
for port_id in self.get_all_port_ids():
self.write(port_id)
success = self.write(port_id)
if success:
count += 1
log.info(f"tide info for port id {port_id} saved.")
time.sleep(wait_interval)
log.info(f"{count}/{len(self.get_all_port_ids())} saved.")


@click.command()
Expand Down

0 comments on commit c6e6bcb

Please sign in to comment.