diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-03-19 23:15:01 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-03-19 23:15:01 (GMT) |
commit | e1d853c457d77d1f36ad211c85dc28a8833cd6cd (patch) | |
tree | 3668b67ab4d13e102d777e3e0e67d59ce16bd668 /program/management/commands/importhosts.py | |
parent | 0176bc873cb1b46a1ebf277fe1f138f26bd95e31 (diff) |
data migration.
Diffstat (limited to 'program/management/commands/importhosts.py')
-rw-r--r-- | program/management/commands/importhosts.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/program/management/commands/importhosts.py b/program/management/commands/importhosts.py new file mode 100644 index 0000000..0f1b154 --- /dev/null +++ b/program/management/commands/importhosts.py @@ -0,0 +1,34 @@ +from django.core.management.base import NoArgsCommand + +import MySQLdb + +from program.models import Host + +USER = 'helsinki' +PASSWD = 'helsinki' +DB = 'helsinki' + +class Command(NoArgsCommand): + help = 'Import hosts from current program' + + def handle_noargs(self, **options): + connection = MySQLdb.connect(user=USER, passwd=PASSWD, db=DB) + cursor = connection.cursor() + + cursor.execute("""SELECT DISTINCT macher +FROM sendungen +WHERE letzter_termin > current_date AND macher != '' AND titel NOT LIKE 'Musikprogramm'""") + + counter = 0 + + for row in cursor.fetchall(): + for macher in row[0].decode('latin1').encode('utf8').split(','): + host = Host(name=macher.strip()) + host.save() + + counter += 1 + + cursor.close() + connection.close() + + print '%i hosts imported' % counter
\ No newline at end of file |