Changeset 9170


Ignore:
Timestamp:
May 9, 2011, 5:35:32 PM (14 years ago)
Author:
rick
Message:

Allow import (default) .gz files as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/gheat/management/commands/import_droidstumbler.py

    r9165 r9170  
    22# -*- coding: utf-8 -*-
    33#
    4 ###########################################
    5 #
    64# Script for importing DroidStumbler .csv files
    75#
    8 # In theory, only the -f option is needed, but for overview's sake, please use the others aswell.
    9 # -f = location of the .netxml, e.g. '/home/test.csv'
    10 # -m = name of the dataset, e.g. 'Walk in park' or 'Trip with boat'
    11 # -g = your name
    12 # -e = your email address
     6# Original by Dennis Wagenaar <d.wagenaar@gmail.com>
    137#
    14 # (Run from project root)
    15 # ./manage.py import_droidstumbler -f <file location> -m <dataset name> -g <username> -e <email>
     8# Rick van der Zwet <info@rickvanderzwet.nl>
    169#
    17 # Make sure the variables in this script match the column numbers in your file e.g.;
    18 # Lat is read from the first column [0], if the lat in your file is in the 4th column, change
    19 # 'lat = row[0]' to 'lat = row[3]'.
    20 # Also, take note of the 'replace()' and 'strip()' functions. These should probably be edited aswell.
    21 #
    22 # Dennis Wagenaar
    23 # d.wagenaar@gmail.com
    24 #
    25 ###########################################
    26 
    2710from django.core.management import setup_environ
    2811from django.core.management.base import BaseCommand, CommandError
     
    3114import csv
    3215import datetime
     16import gzip
    3317import os
    3418import sys
     
    4024  mr = MeetRondje.objects.create(datum=datetime.datetime.now() , naam=meetrondje , gebruiker=g , apparatuur=a)
    4125
    42   csvfile = csv.reader(open(location, 'rb'), delimiter=',')
     26  if location.endswith('.gz'):
     27    fh = gzip.open(location,'rb')
     28  else:
     29    fh = open(location,'rb')
     30  csvfile = csv.reader(fh, delimiter=',')
    4331  count = 0
    4432  ap_cache = {}
     
    6856
    6957class Command(BaseCommand):
    70   args = '<csvfile>'
     58  args = '<csvfile>[.gz]'
    7159  option_list = BaseCommand.option_list + (
    7260    make_option('-m', '--meetrondje', dest='meetrondje', default='rondje'),
Note: See TracChangeset for help on using the changeset viewer.