diff options
| author | Maksim A. Boyko <maksim.a.boyko@gmail.com> | 2012-10-28 17:22:07 -0400 |
|---|---|---|
| committer | Maksim A. Boyko <maksim.a.boyko@gmail.com> | 2012-10-28 17:22:07 -0400 |
| commit | 9bd1a089dc79884d4962192fe6cf1890488bbad4 (patch) | |
| tree | 0d5acc62c2153f4abb17e2bc43e979e7afda4252 | |
| parent | 5e25c2f2574237db6d21ea50fa163a97be2dc139 (diff) | |
tools: Fix bug
| -rwxr-xr-x | tools/migrate_db.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/tools/migrate_db.py b/tools/migrate_db.py index b5c12f8..70918c2 100755 --- a/tools/migrate_db.py +++ b/tools/migrate_db.py @@ -39,7 +39,10 @@ class MigrateDB(DB): for i, r in enumerate(row[:]): if isinstance(r, str): detect = chardet.detect(r) - row[i] = unicode(r, detect['encoding'] or 'utf8', 'replace') + try: + row[i] = unicode(r, detect['encoding'] or 'utf8', 'replace') + except LookupError: + row[i] = unicode(r, 'utf8', 'replace') yield dict(zip(fields, row)) def get_radio_chat_table(self): @@ -254,19 +257,19 @@ if __name__ == '__main__': pk = map_video.get(row['videoid'], 0) if pk: video = SJContent.objects.get(pk=pk) - try: - like = SJLike.objects.get( - user=user, - datetime=datetime.fromtimestamp(row['date']), - content=video) - except SJContent.DoesNotExist: - like = SJLike( - user=user, - datetime=datetime.fromtimestamp(row['date']), - content=video) - like.save() + try: + like = SJLike.objects.get( + user=user, + datetime=datetime.fromtimestamp(row['date']), + content=video) + except SJLike.DoesNotExist: + like = SJLike( + user=user, + datetime=datetime.fromtimestamp(row['date']), + content=video) + like.save() - row['__sjlike_pk'] = like.pk + row['__sjlike_pk'] = like.pk # Migrate sj_chat table |
