Fix for marinetraffic web change
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Tue, 12 Apr 2011 08:13:16 +0000 (08:13 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Tue, 12 Apr 2011 08:13:16 +0000 (08:13 +0000)
bin/extras/marinetraffic.py

index 31868456d8ba2a8ad74579319950f030cc50f2a4..87a34860a655d36d193285a31309b4242e226ea4 100755 (executable)
@@ -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()