diff options
author | Johannes Raggam <raggam-nl@adm.at> | 2011-03-26 20:35:14 (GMT) |
---|---|---|
committer | Johannes Raggam <raggam-nl@adm.at> | 2011-03-26 20:35:14 (GMT) |
commit | d277b4a96830dac291fa77c710ffcba1c802407d (patch) | |
tree | 4209a83efd4ab96b028b7daa8e89630dfe383e90 /helsinki/program/management/commands/importhosts.py | |
parent | faa08b0b5ff0da35708fdbfc0cf2475a051ee6e4 (diff) |
refactor project structure
Diffstat (limited to 'helsinki/program/management/commands/importhosts.py')
-rw-r--r-- | helsinki/program/management/commands/importhosts.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/helsinki/program/management/commands/importhosts.py b/helsinki/program/management/commands/importhosts.py new file mode 100644 index 0000000..39a8afd --- /dev/null +++ b/helsinki/program/management/commands/importhosts.py @@ -0,0 +1,34 @@ +from django.core.management.base import NoArgsCommand + +import MySQLdb + +from helsinki.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].split(','): + host = Host(name=macher.strip()) + host.save() + + counter += 1 + + cursor.close() + connection.close() + + print '%i hosts imported' % counter |