src/hdalab/management/commands/import_hdabo_db.py
changeset 271 8f77cf71ab02
parent 230 2185b943cabd
child 272 1c774f7a0341
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hdalab/management/commands/import_hdabo_db.py	Tue Jun 17 10:25:33 2014 +0200
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+'''
+Created on Feb 28, 2012
+
+@author: ymh
+'''
+from django.core.management.base import BaseCommand
+from django.core.management import call_command
+from optparse import make_option
+import os.path
+
+
+class Command(BaseCommand):
+
+    args = "[<path to the data folder>]"
+    option_list = BaseCommand.option_list + (
+        make_option('-c', '--categories',
+            action='store_true',
+            dest='categories',
+            default=False,
+            help='load categories in db'),
+    )
+
+
+    def handle(self, *args, **options):        
+        
+        if len(args) == 0:
+            data_path = os.path.abspath(os.path.join(os.path.basename(__file__),'../../../../data'))
+        else:
+            data_path = args[0]
+        
+        print("===========  MIGRATE ===========")
+        call_command('syncdb', migrate=True)
+        if options.get('categories', False):
+            print("===========  QUERY WIKIPEDIA CATEGORY ===========")
+            call_command('query_wikipedia_category', interactive=False, force=True)
+
+        print("===========  QUERY DBPEDIA ===========")                
+        call_command('query_dbpedia', interactive=False, force=True)
+        print("===========  FILL TAG YEAR ===========")
+        call_command('fill_tag_years')
+        print("===========  GEOJSON TRANSFORM ===========")
+        call_command('geojson_transform', os.path.join(data_path,'countries.geo.json'))
+        print("===========  QUERY GEO INCLUSION ===========")
+        call_command('query_geo_inclusion')
+        print("===========  IMPORT INSEE CSV PASS 1 ===========")
+        call_command('import_insee_csv', os.path.join(data_path,'villes.csv'))
+        print("===========  IMPORT INSEE CSV PASS 2 ===========")
+        call_command('import_insee_csv', os.path.join(data_path,'additional_cities.csv'))
+        print("===========  IMPORT HDA INSEE CSV ===========")
+        call_command('import_hda_insee_csv', os.path.join(data_path,'HDA_Insee.csv'))
+        print("===========  QUERY CATEGORY INCLUSION ===========")
+        call_command('query_category_inclusion', all=True, force=True, interactive=False)
+        
+        
\ No newline at end of file