Changeset 9140


Ignore:
Timestamp:
May 3, 2011, 9:24:27 PM (14 years ago)
Author:
rick
Message:

Import DroidStumbler Files.

File:
1 copied

Legend:

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

    r9139 r9140  
    11#!/usr/bin/env python
     2# -*- coding: utf-8 -*-
    23#
    34###########################################
    45#
    5 # Script for importing .csv files
     6# Script for importing DroidStumbler .csv files
    67#
    78# In theory, only the -f option is needed, but for overview's sake, please use the others aswell.
     
    1213#
    1314# (Run from project root)
    14 # ./manage.py import_csv -f <file location> -m <dataset name> -g <username> -e <email>
     15# ./manage.py import_droidstumbler -f <file location> -m <dataset name> -g <username> -e <email>
    1516#
    1617# Make sure the variables in this script match the column numbers in your file e.g.;
     
    3334import csv
    3435
    35 def import_file(location, meetrondje, gebruiker, email):
     36def import_droidstumbler(location, meetrondje, gebruiker, email):
    3637
    3738  g, created = Gebruiker.objects.get_or_create(naam=gebruiker , email=email)
     
    3940  mr = MeetRondje.objects.create(datum=datetime.datetime.now() , naam=meetrondje , gebruiker=g , apparatuur=a)
    4041
    41   csvfile = csv.reader(open(location, 'rb'), delimiter='\t')
     42  csvfile = csv.reader(open(location, 'rb'), delimiter=',')
    4243  for row in csvfile:
    43     lat = row[0].replace('N ', '')
    44     lon = row[1].replace('E ', '')
    45     ssid = row[2].strip('( )')
    46     bssid = row[4].strip('( )')
    47     enc = row[8]
    48     if enc[2] == '1': enc = True
    49     else: enc = False
    50     sig = 100 # Get's fix soon
    51     print lat, lon, ssid, bssid, enc, sig
    52 
    53     ap, created = Accespoint.objects.get_or_create(mac=bssid, ssid=ssid, encryptie=enc)
    54     m = Meting.objects.create(meetrondje=mr, accespoint=ap, latitude=lat, longitude=lon, signaal=sig)
    55 
     44    epoch, msg_type, lat, lon, accuracy, ssid, bssid, level, frequency, capabilities, empty = row
     45    if msg_type == "data" and lat and lon:
     46      ap, created = Accespoint.objects.get_or_create(mac=bssid, ssid="ap-WirelessLeiden-" + 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
    5651
    5752class Command(BaseCommand):
     
    6459
    6560  def handle(self, *args, **options):
    66     import_file(options['location'],options['meetrondje'],options['gebruiker'],options['email'])
     61    import_droidstumbler(options['location'],options['meetrondje'],options['gebruiker'],options['email'])
Note: See TracChangeset for help on using the changeset viewer.