Ignore:
Timestamp:
Apr 18, 2011, 3:12:48 PM (14 years ago)
Author:
dennisw
Message:

dataimport.py - werkt soort van, import data naar gheat_meting en gheat_accespoint, rest volgt. SSID's zonder naam worden tijdelijk geskipped wegens 'None' problemen.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/dataimport.py

    r9069 r9072  
    33import settings
    44setup_environ(settings)
    5 #from xml.dom.minidom import parse
    65from gheat.models import *
    76from lxml import etree
    87
    9 doc = etree.parse('/home/dennis/Desktop/test.netxml')
    10 test = doc.findall('wireless-network')
     8datasource = etree.parse('/home/dennis/Desktop/test2.netxml')
     9doc = datasource.findall('wireless-network')
    1110
    12 for wnetwork in test:
     11for wnetwork in doc:
     12    enc = wnetwork.find('SSID/encryption')
     13    if enc != None: enc = 'true'
     14    else: enc = 'false'
     15    ssid = wnetwork.find('SSID/essid')
     16    if ssid != None: ssid = ssid.text
     17    else: ssid = 'hidden'
    1318    bssid = wnetwork.find('BSSID')
    14     print bssid.text
    15     manuf = wnetwork.find('manuf')
    16     print manuf.text
    17 
    18 #    attr = wnetwork.attrib
    19 #    print(attr['BSSID'])
    20 #    print(attr['lon'])
    21 
    22 #    for bssid in wnetwork.getElementsByTagName('BSSID'):
    23 #        bssid = bssid.firstChild.nodeValue
    24 #        print bssid
    25 #    for manuf in wnetwork.getElementsByTagName('manuf'):
    26 #        manuf = manuf.firstChild.nodeValue
    27 #        print manuf
    28 #    for enc in wnetwork.getElementsByTagName('encryption'):
    29 #        enc = enc.firstChild.nodeValue
    30 #        print enc
    31 #    for ssid in wnetwork.getElementsByTagName('ssid'):
    32 #        ssid = ssid.firstChild.nodeValue
    33 #        print ssid
    34 #    for lat in wnetwork.getElementsByTagName('min-lat'):
    35 #        lat = lat.firstChild.nodeValue
    36 #        print lat
    37 #    for lon in wnetwork.getElementsByTagName('min-lon'):
    38 #        lon = lon.firstChild.nodeValue
    39 #        print lon
     19    if bssid != None: bssid = bssid.text
     20    lat = wnetwork.find('gps-info/min-lat')
     21    if lat != None: lat = lat.text
     22    lon = wnetwork.find('gps-info/min-lon')
     23    if lon != None: lon = lon.text
     24    if ssid is None: continue
     25    print enc, ssid, bssid, lat, lon
    4026
    4127#    g = Gebruiker.objects.get_or_create(naam= , email= )
     
    4531#    mr = MeetRondje.objects.create(datum= , naam= , gebruiker_id=g.id , apparatuur_id=a.id )
    4632#    mr.save()
    47 #    ap = Accespoint.objects.get_or_create(mac= , ssid= , encryptie= )
    48 #    ap.save()
    49 #    m = Meting.objects.create(meetrondje_id=mr.id, accespoint_id=ap.id, latitude= , longitude= , signaal= )
    50 #    m.save()
     33    ap = Accespoint(mac=bssid, ssid=ssid, encryptie=enc)
     34    ap.save()
     35    m = Meting(meetrondje_id=1, accespoint_id=ap.id, latitude=lat, longitude=lon, signaal=100)
     36    m.save()
Note: See TracChangeset for help on using the changeset viewer.