From: olivier Date: Mon, 15 Feb 2010 16:47:37 +0000 (+0000) Subject: add missing collections year of issue migrator X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=e413e528945e6a5daab9d55da03064a0e8df5255;p=telemeta-data.git add missing collections year of issue migrator git-svn-id: http://svn.parisson.org/svn/crem@156 3bf09e05-f825-4182-b9bc-eedd7160adf0 --- diff --git a/trunk/import/migration/tasks/dates.py b/trunk/import/migration/tasks/dates.py index 76a3eea..dd184de 100644 --- a/trunk/import/migration/tasks/dates.py +++ b/trunk/import/migration/tasks/dates.py @@ -37,13 +37,64 @@ from core import DataMigrator import re from datetime import date, datetime -class CollectionsYearConverter(DataMigrator): +class CollectionsPublishingYearConverter(DataMigrator): + """Migrate the collections year of issue""" + + implements(IDataMigrator) + + def get_name(self): + return "dates:collections_pub" + + def process(self): + + self.stats = { + 'total': 0, + 'migrated': 0, + 'unsignificant': 0, + 'incoherent': 0 + } + + self.target_cursor.execute("UPDATE media_collections SET year_published = 0") + self.src_cursor.execute("SELECT Cote, Annee_Parution FROM Support") + + self.start(self.src_cursor.rowcount) + while True: + row = self.src_cursor.fetchone() + if not row: + break + + old_code, year_str = row + year = int(year_str) + if year < 1900: + if year >=0 and year < 100: + year += 1900 + elif year < 0: + year = 0 + self.stats['unsignificant'] += 1 + else: + year = 0 + self.stats['incoherent'] += 1 + elif year > 2020: + year = 0 + self.stats['incoherent'] += 1 + + if year: + self.target_cursor.execute("UPDATE media_collections SET year_published = %s " + "WHERE old_code = %s", (year, old_code)) + self.stats['migrated'] += self.target_cursor.rowcount + + self.stats['total'] += 1 + self.step() + + self.end() + +class CollectionsRecordingYearConverter(DataMigrator): """Perform a preliminary conversion of the collections recording years""" implements(IDataMigrator) def get_name(self): - return "dates:collections" + return "dates:collections_rec" def process(self):