source: src/django_gheat/gheat/management/commands/import_droidstumbler.py@ 9140

Last change on this file since 9140 was 9140, checked in by rick, 14 years ago

Import DroidStumbler Files.

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4###########################################
5#
6# Script for importing DroidStumbler .csv files
7#
8# In theory, only the -f option is needed, but for overview's sake, please use the others aswell.
9# -f = location of the .netxml, e.g. '/home/test.csv'
10# -m = name of the dataset, e.g. 'Walk in park' or 'Trip with boat'
11# -g = your name
12# -e = your email address
13#
14# (Run from project root)
15# ./manage.py import_droidstumbler -f <file location> -m <dataset name> -g <username> -e <email>
16#
17# Make sure the variables in this script match the column numbers in your file e.g.;
18# Lat is read from the first column [0], if the lat in your file is in the 4th column, change
19# 'lat = row[0]' to 'lat = row[3]'.
20# Also, take note of the 'replace()' and 'strip()' functions. These should probably be edited aswell.
21#
22# Dennis Wagenaar
23# d.wagenaar@gmail.com
24#
25###########################################
26
27from django.core.management import setup_environ
28from django.core.management.base import BaseCommand
29from optparse import OptionParser, make_option
30import settings
31setup_environ(settings)
32from gheat.models import *
33import datetime
34import csv
35
36def import_droidstumbler(location, meetrondje, gebruiker, email):
37
38 g, created = Gebruiker.objects.get_or_create(naam=gebruiker , email=email)
39 a, created = Apparatuur.objects.get_or_create(antenne='test' , kaart='test')
40 mr = MeetRondje.objects.create(datum=datetime.datetime.now() , naam=meetrondje , gebruiker=g , apparatuur=a)
41
42 csvfile = csv.reader(open(location, 'rb'), delimiter=',')
43 for row in csvfile:
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
51
52class Command(BaseCommand):
53 option_list = BaseCommand.option_list + (
54 make_option('-f', '--location', dest='location', default='location'),
55 make_option('-m', '--meetrondje', dest='meetrondje', default='rondje'),
56 make_option('-g', '--gebruiker', dest='gebruiker', default='username'),
57 make_option('-e', '--email', dest='email', default='foo@bar.org'),
58 )
59
60 def handle(self, *args, **options):
61 import_droidstumbler(options['location'],options['meetrondje'],options['gebruiker'],options['email'])
Note: See TracBrowser for help on using the repository browser.