Changeset 9080 for src/django_gheat/gheat
- Timestamp:
- Apr 18, 2011, 7:45:51 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/gheat/management/commands/dataimport.py
r9078 r9080 11 11 def import_file(location, meetrondje, gebruiker, email): 12 12 13 14 13 datasource = etree.parse(location) 14 doc = datasource.findall('wireless-network') 15 15 16 17 18 16 g, created = Gebruiker.objects.get_or_create(naam=gebruiker , email=email) 17 a, created = Apparatuur.objects.get_or_create(antenne='test' , kaart='test') 18 mr = MeetRondje.objects.create(datum=datetime.datetime.now() , naam=meetrondje , gebruiker=g , apparatuur=a) 19 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 20 for wnetwork in doc: 21 enc = wnetwork.find('SSID/encryption') 22 if enc != None: enc = 'true' 23 else: enc = 'false' 24 ssid = wnetwork.find('SSID/essid') 25 if ssid != None: ssid = ssid.text 26 else: ssid = 'hidden' 27 bssid = wnetwork.find('BSSID') 28 if bssid != None: bssid = bssid.text 29 lat = wnetwork.find('gps-info/min-lat') 30 if lat != None: lat = lat.text 31 lon = wnetwork.find('gps-info/min-lon') 32 if lon != None: lon = lon.text 33 if ssid is None: continue 34 print enc, ssid, bssid, lat, lon 35 35 36 37 36 ap, created = Accespoint.objects.get_or_create(mac=bssid, ssid=ssid, encryptie=enc) 37 m = Meting.objects.create(meetrondje=mr, accespoint=ap, latitude=lat, longitude=lon, signaal=100) 38 38 39 39 40 40 class Command(BaseCommand): 41 42 43 44 45 41 option_list = BaseCommand.option_list + ( 42 make_option('-f', '--location', dest='location', default='location'), 43 make_option('-m', '--meetrondje', dest='meetrondje', default='rondje'), 44 make_option('-g', '--gebruiker', dest='gebruiker', default='username'), 45 make_option('-e', '--email', dest='email', default='foo@bar.org'), 46 46 ) 47 47 48 49 48 def handle(self, *args, **options): 49 import_file(options['location'],options['meetrondje'],options['gebruiker'],options['email'])
Note:
See TracChangeset
for help on using the changeset viewer.