#!/usr/bin/env python
from django.core.management import setup_environ
import settings
setup_environ(settings)
from gheat.models import *
from lxml import etree

datasource = etree.parse('/home/dennis/Desktop/test2.netxml')
doc = datasource.findall('wireless-network')

for wnetwork in doc:
    enc = wnetwork.find('SSID/encryption')
    if enc != None: enc = 'true'
    else: enc = 'false'
    ssid = wnetwork.find('SSID/essid')
    if ssid != None: ssid = ssid.text
    else: ssid = 'hidden'
    bssid = wnetwork.find('BSSID')
    if bssid != None: bssid = bssid.text
    lat = wnetwork.find('gps-info/min-lat')
    if lat != None: lat = lat.text
    lon = wnetwork.find('gps-info/min-lon')
    if lon != None: lon = lon.text
    if ssid is None: continue
    print enc, ssid, bssid, lat, lon 

#    g = Gebruiker.objects.get_or_create(naam= , email= )
#    g.save()
#    a = Apparatuur.objects.get_or_create(antenne= , kaart= )
#    a.save()
#    mr = MeetRondje.objects.create(datum= , naam= , gebruiker_id=g.id , apparatuur_id=a.id )
#    mr.save()
    ap = Accespoint(mac=bssid, ssid=ssid, encryptie=enc)
    ap.save()
    m = Meting(meetrondje_id=1, accespoint_id=ap.id, latitude=lat, longitude=lon, signaal=100)
    m.save()
