web/hdalab/management/commands/fill_country_codes.py
changeset 133 e821a1ae9773
parent 132 e6483309fa52
child 134 75f8f05f9a60
--- a/web/hdalab/management/commands/fill_country_codes.py	Wed Feb 29 16:14:01 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-# -*- coding: utf-8 -*-
-'''
-Created on Jan 29, 2012
-
-@author: ymh
-'''
-from django.core.management.base import NoArgsCommand
-from django.core.management.color import no_style
-import urllib
-from hdabo.utils import show_progress
-import re
-from hdalab.models import CountryCode
-
-class Command(NoArgsCommand):
-    def handle_noargs(self, **options):
-        self.style = no_style()
-        
-        
-        f = urllib.urlopen("http://fr.wikipedia.org/wiki/ISO_3166-1?action=raw&section=3")
-        lines = f.read().split("|-")
-        
-        total = len(lines)
-        writer = None
-        
-        for i,line in enumerate(lines):
-            writer = show_progress(i+1, total, line.decode("utf-8"), 50, writer)
-            isocode = re.findall("(?m)(\[\[|\|)([A-Z]{3})]]", line)
-            countryname = re.findall("(?m)\{\{([^|}]+)", line)
-            if len(isocode) and len(countryname):
-                isocode = isocode[0][1]
-                countryname = countryname[0].strip()
-                CountryCode.objects.get_or_create(label=countryname, isocode=isocode)