forked from samuelclay/NewsBlur
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a migration for intelligence classifiers to include social_use…
…r_id, where it didn't exist before.
- Loading branch information
1 parent
5df6637
commit d5d6a6c
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import sys | ||
from mongoengine.queryset import OperationError | ||
from mongoengine.base import ValidationError | ||
from apps.analyzer.models import MClassifierFeed | ||
from apps.analyzer.models import MClassifierAuthor | ||
from apps.analyzer.models import MClassifierTag | ||
from apps.analyzer.models import MClassifierTitle | ||
|
||
for classifier_cls in [MClassifierFeed, MClassifierAuthor, | ||
MClassifierTag, MClassifierTitle]: | ||
print " ================================================================= " | ||
print " Now on %s " % classifier_cls.__name__ | ||
print " ================================================================= " | ||
classifiers = classifier_cls.objects.filter(social_user_id__exists=False) | ||
count = classifiers.count() | ||
print " ---> Found %s classifiers" % count | ||
for i, classifier in enumerate(classifiers): | ||
if i % 1000 == 0: | ||
print " ---> %s / %s" % (i, count) | ||
sys.stdout.flush() | ||
classifier.social_user_id = 0 | ||
try: | ||
classifier.save() | ||
except OperationError, e: | ||
print " ***> Operation error on: %s" % e | ||
sys.stdout.flush() | ||
# classifier.delete() | ||
except ValidationError, e: | ||
print " ***> ValidationError error on: %s" % e | ||
print " ***> Original classifier: %s" % classifier.__dict__ | ||
|