Changeset 9140
- Timestamp:
- May 3, 2011, 9:24:27 PM (14 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/gheat/management/commands/import_droidstumbler.py
r9139 r9140 1 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 2 3 # 3 4 ########################################### 4 5 # 5 # Script for importing .csv files6 # Script for importing DroidStumbler .csv files 6 7 # 7 8 # In theory, only the -f option is needed, but for overview's sake, please use the others aswell. … … 12 13 # 13 14 # (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> 15 16 # 16 17 # Make sure the variables in this script match the column numbers in your file e.g.; … … 33 34 import csv 34 35 35 def import_ file(location, meetrondje, gebruiker, email):36 def import_droidstumbler(location, meetrondje, gebruiker, email): 36 37 37 38 g, created = Gebruiker.objects.get_or_create(naam=gebruiker , email=email) … … 39 40 mr = MeetRondje.objects.create(datum=datetime.datetime.now() , naam=meetrondje , gebruiker=g , apparatuur=a) 40 41 41 csvfile = csv.reader(open(location, 'rb'), delimiter=' \t')42 csvfile = csv.reader(open(location, 'rb'), delimiter=',') 42 43 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 56 51 57 52 class Command(BaseCommand): … … 64 59 65 60 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.