Example #1
0
 def handle(self, *args, **options):
     print "clean old downloaded files"
     if os.path.exists(JSON_DUMP_ARCHIVE_LOCALIZATION):
         os.system("rm %s" % (JSON_DUMP_ARCHIVE_LOCALIZATION))
     if os.path.exists(JSON_DUMP_LOCALIZATION):
         os.system("rm %s" % (JSON_DUMP_LOCALIZATION))
     print "download lastest data dump of meps from parltrack"
     os.system("wget http://parltrack.euwiki.org/dumps/ep_meps_current.json.xz -O %s" % JSON_DUMP_ARCHIVE_LOCALIZATION)
     print "unxz dump"
     os.system("unxz %s" % JSON_DUMP_ARCHIVE_LOCALIZATION)
     print "load json"
     meps = json.load(open(JSON_DUMP_LOCALIZATION, "r"))
     print "Set all current active mep to unactive before importing"
     with transaction.commit_on_success():
         MEP.objects.filter(active=True).update(active=False)
         a = 0
         for mep_json in meps:
             a += 1
             print a, "-", mep_json["Name"]["full"].encode("Utf-8")
             in_db_mep = MEP.objects.filter(ep_id=int(mep_json["UserID"]))
             if in_db_mep:
                 mep = in_db_mep[0]
                 mep.active = mep_json['active']
                 manage_mep(mep, mep_json)
             else:
                 mep = create_mep(mep_json)
         clean()
     print
     update_meps_positions(verbose=True)
     update_search_index()
    def forwards(self, orm):

        # Adding field 'MEP.position'
        db.add_column('meps_mep', 'position', self.gf('django.db.models.fields.IntegerField')(default=None, null=True), keep_default=False)
        db.add_column('meps_mep', 'total_score', self.gf('django.db.models.fields.FloatField')(default=None, null=True), keep_default=False)

        update_total_score_of_all_meps(score=orm['votes.Score'], mep=orm.MEP, proposal=orm['votes.Proposal'], verbose=True)
        update_meps_positions(mep=orm.MEP, verbose=True)
 def handle(self, *args, **options):
     if len(args) not in (3, 4):
         print >>sys.stderr, "Usage: %s <recommendationdata id> <{for,against}> <recommendation weight> <proposal ponderation=1 by default>" % __file__
         sys.exit(1)
     if len(args) == 4:
         recommendationdata_id, recommendation, weight, proposal_ponderation = args
     else:
         recommendationdata_id, recommendation, weight = args
         proposal_ponderation = 1
     if recommendation not in ("for", "against"):
         print recommendation
         print >>sys.stderr, "Recommendation should be either 'for' or 'against'"
         sys.exit(1)
     with transaction.commit_on_success():
         create_recommendation(*args)
     sys.stdout.write("Update total score of all meps now\n")
     update_total_score_of_all_meps(verbose=True)
     update_meps_positions(verbose=True)
     sys.stdout.write("Clean all deprecated trends\n")
     clean_all_trends()
     update_search_index()