Ejemplo n.º 1
0
def create_new_geothing(the_geothing, the_location, geosite):
    geothing = Geothing(geosite=geosite)
    l = Location()
    l.NS_degree = the_location.NS_degree
    l.EW_degree = the_location.EW_degree
    l.NS_minute = the_location.NS_minute
    l.EW_minute = the_location.EW_minute
    l.save()
    geothing.location = l
    geothing.pid = the_geothing.pid
    geothing.code = the_geothing.code
    geothing.type_code = the_geothing.type_code
    geothing.name = the_geothing.name
    geothing.created_date = the_geothing.created_date
    geothing.author = the_geothing.author
    geothing.save()
Ejemplo n.º 2
0
def create_new_geothing(the_geothing, the_location, geosite):
    #print geosite.id
    geothing = Geothing(geosite=geosite)
    l = Location()
    l.NS_degree = the_location.NS_degree
    l.EW_degree = the_location.EW_degree
    l.NS_minute = the_location.NS_minute
    l.EW_minute = the_location.EW_minute
    l.save()
    geothing.location = l
    geothing.pid = the_geothing.get('pid')
    geothing.code = the_geothing.get('oxcode')
    geothing.type_code = the_geothing.get('type_code')
    geothing.name = the_geothing.get('name')
    geothing.created_date = the_geothing.get('created_date')
    geothing.author = the_geothing.get('author')
    geothing.country_name = the_geothing.get('country_name')
    geothing.country_code = the_geothing.get('country_code')
    print 'NEW', geothing.code
    geothing.save()
Ejemplo n.º 3
0
def main():
    LOAD_CACHES = True
    #LOAD_GEO_LOCATION = False

    start = time()

    sql = """
    DELETE location
    FROM location 
    LEFT JOIN geothing ON geothing.location_id=location.id
    LEFT JOIN geosite ON geothing.geosite_id = geosite.id
    WHERE geosite.code = 'GC_SU'
    """
    r = execute_query(sql)

    sql = """
    DELETE geothing
    FROM geothing
    LEFT JOIN geosite ON geothing.geosite_id = geosite.id
    WHERE geosite.code = 'GC_SU'
    """
    r = execute_query(sql)

    file = '/tmp/geocaching_su.wpt'

    # sanity checking, only work on wpt files
    if file.endswith('.wpt') == 0: sys.exit(-1)

    print "Reading file: " + file

    fh = codecs.open(file, 'r', "cp1251")
    wpt = fh.readlines()
    fh.close()

    WPT_CODE = 1
    WPT_LAT = 2
    WPT_LON = 3
    WPT_TITLE = 10
    WPT_DATE = 4

    geosite = Geosite.objects.get(code='GC_SU')
    print geosite
    print len(wpt), 'points'
    for point in wpt:
        print
        print point
        fields = point.split(',')
        if fields[0].isdigit():
            geothing = Geothing(geosite=geosite)
            print geothing.geosite.url
            for field in fields:
                print field
            l = Location()
            lat_degree = float(fields[WPT_LAT])
            l.NS_degree = int(lat_degree)
            l.NS_minute = (abs(lat_degree) - abs(l.NS_degree)) * 60
            lon_degree = float(fields[WPT_LON])
            l.EW_degree = int(lon_degree)
            l.EW_minute = (abs(lon_degree) - abs(l.EW_degree)) * 60
            l.save()
            geothing.location = l
            p = re.compile('(\D+)(\d+)')
            dgs = p.findall(fields[WPT_CODE])
            if dgs:
                code_data = dgs[0]
                geothing.code = fields[WPT_CODE]
                geothing.pid = int(code_data[1])
                geothing.type_code = code_data[0]

            p = re.compile(u'(.+)от(.+)')
            dgs = p.findall(fields[WPT_TITLE])
            if dgs:
                title = dgs[0]
                geothing.name = title[0]
                geothing.author = title[1]

            d = float(fields[WPT_DATE])
            print Dephi_date_to_python_date(d)
            geothing.created_date = Dephi_date_to_python_date(d)
            if geothing.type_code in GEOCACHING_SU_ONMAP_TYPES:
                geothing.save()

    elapsed = time() - start
    print "Elapsed time -->", elapsed
    return