Ignore:
Timestamp:
May 8, 2011, 9:31:41 PM (14 years ago)
Author:
rick
Message:

Make kismet import way more robust...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/management/commands/import_kismet.py

    r9158 r9168  
    5151  print "#INFO: Going to import %s points" % len(points)
    5252  for point in points:
     53    #XXX: This needs to be either the 'bssid' or the 'source', accesspoint from or too data.
     54    bssid = point.attrib['bssid']
    5355    # XXX: Filter this in the beginning with XPath, but etree does not support that (yet).
    54     if point.attrib['bssid'] in ['GP:SD:TR:AC:KL:OG','00:00:00:00:00:00']:
     56    if bssid in ['GP:SD:TR:AC:KL:OG','00:00:00:00:00:00']:
    5557      continue
    56     if point.attrib['bssid'] in ap_ignore:
     58    elif bssid in ap_ignore:
    5759      continue
    58     ap = ap_cache[point.attrib['bssid']]
     60    elif not ap_cache.has_key(bssid):
     61      try:
     62        ap = Accespoint.objects.get(mac=bssid)
     63        ap_cache[bssid] = ap
     64      except Accespoint.DoesNotExist:
     65        print "#ERROR: Cannot found SSID for BSSID '%s'" % bssid
     66        continue
    5967
    6068    # XXX: Signal need properly be a relation of signal_dbm and noice_dbm
    6169    signaal = 100 + int(point.attrib['signal_dbm'])
    6270
    63     meting,created = Meting.objects.get_or_create(meetrondje=mr, accespoint=ap,
     71    meting= Meting.objects.create(meetrondje=mr, accespoint=ap_cache[bssid],
    6472      latitude=point.attrib['lat'], longitude=point.attrib['lon'],
    6573      signaal=signaal)
    6674    # Give some feedback to the user
    67     if created:
    68       count += 1
    69       if (count % 1000) == 0:
    70         print count,
    71       elif (count % 100) == 0:
    72         print ".",
     75    count += 1
     76    if (count % 1000) == 0:
     77      sys.stdout.write(str(count))
     78    elif (count % 100) == 0:
     79      sys.stdout.write(".")
     80    sys.stdout.flush()
     81
     82  sys.stdout.write("%s\n" % count)
     83  print "#INFO: All done, goodbye"
     84
    7385
    7486class Command(BaseCommand):
    75   args = '<gpsxml> <netxml>'
     87  args = '<gpsxml> [<netxml>]'
    7688  option_list = BaseCommand.option_list + (
    7789    make_option('-m', '--meetrondje', dest='meetrondje', default='rondje',help='Naam van het meetrondje'),
     
    8092    )
    8193
    82   # TODO: Condider netxml file to be the gpsxml file with diffent suffix.
    8394  def handle(self, *args, **options):
    8495    try:
    85       (gpsxml_file, netxml_file) = args
     96      if len(args) == 2:
     97        (gpsxml_file, netxml_file) = args
     98      elif len(args) == 1:
     99        (gpsxml_file,) = args
     100        netxml_file = gpsxml_file[:-6] + 'netxml'
     101      else:
     102        raise ValueError
    86103    except ValueError:
    87104      self.print_help(sys.argv[0],sys.argv[1])
Note: See TracChangeset for help on using the changeset viewer.