From c3bfbeda8f1463a59f0f3cf31bd908f8e4c8da16 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Thu, 28 Jul 2011 18:47:07 +0200 Subject: [PATCH] [enh] new script to update all the current meps in the db with parltrack data --- parltrack/update_meps.py | 27 +++++++++++++++++++++++++++ parltrack/update_meps.sh | 11 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 parltrack/update_meps.py create mode 100755 parltrack/update_meps.sh diff --git a/parltrack/update_meps.py b/parltrack/update_meps.py new file mode 100644 index 00000000..dd7bb1af --- /dev/null +++ b/parltrack/update_meps.py @@ -0,0 +1,27 @@ +#!/usr/bin/python +# -*- coding:Utf-8 -*- + +import json + +from urllib import urlopen + +from django.conf import settings + +from meps.models import MEP + +from current_meps_json_2_sql import clean_existant_data, manage_mep + +if __name__ == "__main__": + print "load json" + meps = json.load(urlopen(settings.PARLTRACK_URL + "/search?s_meps=on&q=+&format=json")) + a = 0 + for mep_json in meps["items"]: + a += 1 + print a, "-", mep_json["Name"]["full"] + in_db_mep = MEP.objects.filter(ep_id=mep_json["UserID"]) + if in_db_mep: + mep = in_db_mep[0] + clean_existant_data(mep) + manage_mep(mep, mep_json) + +# vim:set shiftwidth=4 tabstop=4 expandtab: diff --git a/parltrack/update_meps.sh b/parltrack/update_meps.sh new file mode 100755 index 00000000..32f4116b --- /dev/null +++ b/parltrack/update_meps.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +export PYTHONPATH="../:"$PYTHONPATH +export PYTHONPATH="../apps/:"$PYTHONPATH +export DJANGO_SETTINGS_MODULE="memopol2.settings" + +echo "Starting the update" +python ./update_meps.py || (echo "import json data into the database failed" && echo "end" && exit 1) + +echo +echo "successful end"