From 9bbfbc00795fb658f1d9bf3a0324153bcfa6aa2d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Michel=20Nirgal=20Vourg=C3=A8re?= Date: Tue, 12 Apr 2011 08:13:16 +0000 Subject: [PATCH] Fix for marinetraffic web change --- bin/extras/marinetraffic.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/bin/extras/marinetraffic.py b/bin/extras/marinetraffic.py index 3186845..87a3486 100755 --- a/bin/extras/marinetraffic.py +++ b/bin/extras/marinetraffic.py @@ -23,7 +23,7 @@ def go_summary(reference_date, mmsi): root = html_parse(html) divs = get_elem(root, 'div') divdetail = divs[3] - + #print_idented_tree(divdetail, 0) info_raw = {} section = u'' boldtext = u'' @@ -34,7 +34,10 @@ def go_summary(reference_date, mmsi): continue if isinstance(node, Tag) and node.name == 'h2': if boldtext or text: - info_raw[section][boldtext] = text + if not section: + print >> sys.stderr, "WARNING: section is empty for setting", boldtext, "=", text + else: + info_raw[section][boldtext] = text boldtext = text = u'' section = get_inner_text(node) info_raw[section] = {} @@ -46,7 +49,10 @@ def go_summary(reference_date, mmsi): boldtext = text = u'' elif isinstance(node, Tag) and node.name == 'b': if boldtext or text: - info_raw[section][boldtext] = text + if not section: + print >> sys.stderr, "WARNING: section is empty for setting", boldtext, "=", text + else: + info_raw[section][boldtext] = text boldtext = text = u'' boldtext = get_inner_text(node) else: @@ -181,7 +187,7 @@ def go_summary(reference_date, mmsi): info_raw = get_raw_summary(html) info = qualify_summary(info_raw) - #pprint(info) + pprint(info) assert info['mmsi'] == mmsi @@ -275,7 +281,7 @@ def import_last_pos(reference_date, mmsi, page=None): latlong = get_merged_leaf_content(line[5]) latlong = latlong.replace(u'\xa0', u'').strip() if latlong: - lon, lat = latlong.split(' ') + lat, lon = latlong.split(' ') show_on_map = line[8] assert get_merged_leaf_content(show_on_map).strip() == 'Show on Map' @@ -309,6 +315,7 @@ def import_last_pos(reference_date, mmsi, page=None): cog = int(course*AIS_COG_SCALE) heading = AIS_NO_HEADING source = 'MTWW' + print strmmsi, timestamp, status, rot, sog, latitude, longitude, cog, heading, source add_nmea1(strmmsi, timestamp, status, rot, sog, latitude, longitude, cog, heading, source) import_track(mmsi, dt, isodt) @@ -364,10 +371,10 @@ def import_track(mmsi, dt, isodt): cog = int(info['course'])*AIS_COG_SCALE heading = AIS_NO_HEADING source = 'MTTR' - #print datetime.utcfromtimestamp(timestamp), - #for i in strmmsi, timestamp, status, rot, sog, latitude, longitude, cog, heading, source: - # print repr(i), - #print + print datetime.utcfromtimestamp(timestamp), + for i in strmmsi, timestamp, status, rot, sog, latitude, longitude, cog, heading, source: + print repr(i), + print add_nmea1(strmmsi, timestamp, status, rot, sog, latitude, longitude, cog, heading, source) #dbcommit() -- 2.30.2