Ignore:
Timestamp:
May 8, 2011, 8:11:47 PM (14 years ago)
Author:
rick
Message:

More robust and more friendly to user:

  • Allow continue on 'broken' line.
  • Less verbose fieldback, showing where we are from a user PoV during the import.
File:
1 edited

Legend:

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

    r9163 r9165  
    4141
    4242  csvfile = csv.reader(open(location, 'rb'), delimiter=',')
     43  count = 0
     44  ap_cache = {}
     45  print "#INFO: Importing points"
    4346  for row in csvfile:
    44     epoch, msg_type, lat, lon, accuracy, ssid, bssid, level, frequency, capabilities, empty = row
     47    try:
     48      epoch, msg_type, lat, lon, accuracy, ssid, bssid, level, frequency, capabilities = row
     49    except ValueError:
     50      print "# WARNING: Unable to parse line:%i '%s'" % (csvfile.line_num, row)
     51      continue
    4552    if msg_type == "data" and lat and lon:
    46       ap, created = Accespoint.objects.get_or_create(mac=bssid, ssid=ssid, encryptie=capabilities)
    47       if created:
    48         print "# INFO: New AccessPoint %s (%s)" % (ap.ssid, ap.mac)
    49       m = Meting.objects.create(meetrondje=mr, accespoint=ap, latitude=lat, longitude=lon, signaal=(100 + int(level)))
    50       print "# INFO: New Meeting: %s" % m
     53      if not ap_cache.has_key(bssid):
     54        ap_cache[bssid], created = Accespoint.objects.get_or_create(mac=bssid, ssid=ssid, encryptie=capabilities)
     55
     56      m = Meting.objects.create(meetrondje=mr, accespoint=ap_cache[bssid], latitude=lat, longitude=lon, signaal=(100 + int(level)))
     57      # Give some feedback to the user
     58      count += 1
     59      if (count % 1000) == 0:
     60        sys.stdout.write(str(count))
     61      elif (count % 100) == 0:
     62        sys.stdout.write(".")
     63      sys.stdout.flush()
     64
     65  sys.stdout.write("%s\n" % count)
     66  print "#INFO: All done, goodbye"
     67
    5168
    5269class Command(BaseCommand):
Note: See TracChangeset for help on using the changeset viewer.