def manage_categorie(self, loisir): text = self.get_node_text(loisir, self.categorie_key) if text is not None: if Categorie.objects.filter(UID=text).count() == 0: model = Categorie() model.UID = text model.save() pprint(model)
elif mode == 'payant': f = open(filepath, "r") parser = LoisirParser("LOISIR_PAYANT") else: print "bad" exit() loisirs = parser.parse( f.read() ) category_parser = CategoryParser() categories = category_parser.categorie_loisirs(loisirs) for c in categories: if c is not None and Categorie.objects.filter(UID=c).count() == 0: model = Categorie() model.UID = c model.save() print c for l in loisirs: L = Loisir() L.CODE_SESSION = l['code_session'] L.DESCRIPTION = l['description'] L.DESCRIPTION_ACT = l['act'] L.DESCRIPTION_NAT = l['nat'] L.NOM_COUR = l['cours'] L.ARRONDISSEMENT = l['arrondissement'] L.ADRESSE = l['adresse'] L.CATEGORIE = Categorie.objects.get(UID=l['nat'])
if len(sys.argv) <= 1: print "USAGE: %s XML_FILE" % sys.argv[0] sys.exit(1) filepath = sys.argv[1] f = open(filepath, 'r') parser = EvenementParser() category_parser = CategoryParser() evenements = parser.parse( f.read() ) categories = category_parser.categorie_evenements(evenements) for category in categories: if Categorie.objects.filter(UID=category).count() == 0: model = Categorie() model.UID = category model.save() print category for e in evenements: E = Evenement() E.TITRE_EVENEMENT = e['titre'] E.DEBUT_EVENEMENT = e['debut'] E.FIN_EVENEMENT = e['fin'] E.HORAIRE_EVENEMENT = e['horaire'] E.COUT_EVENEMENT = e['cout'] E.DESCRIPTION_EVENEMENT = e['description'] E.RENSEIGNEMENT_EVENEMENT = e['renseignement']