Hello,
Anybody would have Python 3.4 code to extract the data from the json OpenContracting standard??? I'm working on a web site to display contrats to be awarded by Montreal City, based on the PDF file prepared for the City Council and others meetings (http://ville.montreal.qc.ca/portal/page?_pageid=5798,85931607&_dad=portal&_schema=PORTAL). I then want to show past contrats of the supplier (ex.: http://contratsouvertsmtl.info/ce/ in the darker gray sections), based on the json coming from the city's site API (ex.: http://ville.montreal.qc.ca/vuesurlescontrats/api/releases?q=mecano&format=json). Tks Pascal Robichaud Données ouvertes 101 @DO101Mtl Code I have so far, but having some problems: import requests import json r = requests.get(url) r.encoding = 'utf-8' data = json.loads(r.text) #Nombre de contrats du fournisseur print(data["meta"]["count"]) for release in data["releases"]: print("-----------------------------------------") print("Date: " + release["date"]) print("subject: " + release["subject"][0]) print("language: " + release["language"]) print("tag: " + release["tag"]) #release.tender for tender in release["tender"]: print(tender) #problem with extracting the data #release.award print() for award in release["awards"]: for value in award["value"]: print(value) if award["repartition"]: print("Répartition: " + award["repartition"]) print("No de dossier: " + award["id"]) for supplier in award["suppliers"]: print("Fournisseur: " + supplier["name"]) #release.buyer print() for buyer in release["buyer"]: print(buyer["name"]) _______________________________________________ CivicAccess-discuss mailing list [hidden email] http://lists.pwd.ca/mailman/listinfo/civicaccess-discuss |
Pascal,
Here is a working Go example I just threw together that might help your Pythoning: https://github.com/gnewton/openContractingGoExampleMontreal Code: https://github.com/gnewton/openContractingGoExampleMontreal/blob/master/main.go Sample output: https://raw.githubusercontent.com/gnewton/openContractingGoExampleMontreal/master/output.txt If you have any questions, let me know. Glen Sample output: -------------------------------- Date: 2015-08-25T00:00:00-04:00 Subject: Autres Language: fr Procurement Method Rationale: contract Status: complete Value: 2091.830000 No de dossier: MAD787215 Fournisseur: MECANO ALCA INC Buyer: Service du Materiel roulant et des ateliers -------------------------------- Date: 2015-07-15T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 2529.210000 No de dossier: CAR783647 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-07-13T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 2191.610000 No de dossier: CAR782961 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-07-09T00:00:00-04:00 Subject: Infrastructures Language: fr Procurement Method Rationale: contract Status: complete Value: 58268.060000 No de dossier: DEU17071 Fournisseur: GROUPE MECANO INC Buyer: SERVICE DE L'EAU -------------------------------- Date: 2015-07-09T00:00:00-04:00 Subject: Infrastructures Language: fr Procurement Method Rationale: contract Status: complete Value: 2913.400000 No de dossier: DEU17071 Fournisseur: GROUPE MECANO INC Buyer: SERVICE DE L'EAU -------------------------------- Date: 2015-06-18T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 2214.590000 No de dossier: CAR781459 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-05-15T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 3791.000000 No de dossier: MAD778139 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-05-01T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 2095.000000 No de dossier: MAD776448 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-04-21T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 6338.000000 No de dossier: MAD775078 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-04-21T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 6338.040000 No de dossier: MAD775078 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-02-17T00:00:00-05:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 4588.940000 No de dossier: CAR764496 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-02-17T00:00:00-05:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 16811.220000 No de dossier: CAR764496 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-01-15T00:00:00-05:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 2059.500000 No de dossier: MAD763924 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-01-07T00:00:00-05:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 2481.880000 No de dossier: CAR760509 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2015-01-05T00:00:00-05:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 5088.620000 No de dossier: CAR762463 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2014-12-08T00:00:00-05:00 Subject: Infrastructures Language: fr Procurement Method Rationale: contract Status: complete Value: 114975.000000 No de dossier: 1143334032 Fournisseur: GROUPE MÉCANO Buyer: SERVICE DE L'EAU -------------------------------- Date: 2014-10-07T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 3577.760000 No de dossier: CAR754965 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2014-07-07T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 3652.850000 No de dossier: CAR738693 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2014-05-06T00:00:00-04:00 Subject: Ressources matérielles et services Language: fr Procurement Method Rationale: contract Status: complete Value: 3671.200000 No de dossier: MAD742684 Fournisseur: MECANO ALCA INC Buyer: SERVICE DU MATÉRIEL ROULANT ET DES ATELIERS -------------------------------- Date: 2014-04-30T00:00:00-04:00 Subject: Arrondissements Language: fr Procurement Method Rationale: contract Status: complete Value: 575985.000000 No de dossier: 1143903001 Fournisseur: NORCLAIR INC. Buyer: ARRONDISSEMENT DE PIERREFONDS-ROXBORO -------------------------------- Date: 2014-02-27T00:00:00-05:00 Subject: Organisation et administration Language: fr Procurement Method Rationale: contract Status: complete Value: 3007.190000 No de dossier: CAR736938 Fournisseur: MECANO ALCA INC Buyer: SERVICE DE LA CONCERTATION DES ARRONDISSEMENTS ET RESSOURCES MATÉRIELLES -------------------------------- Date: 2014-02-04T00:00:00-05:00 Subject: Organisation et administration Language: fr Procurement Method Rationale: contract Status: complete Value: 2348.740000 No de dossier: CAR734638 Fournisseur: MECANO ALCA INC Buyer: SERVICE DE LA CONCERTATION DES ARRONDISSEMENTS ET RESSOURCES MATÉRIELLES -------------------------------- Date: 2014-01-28T00:00:00-05:00 Subject: Infrastructures Language: fr Procurement Method Rationale: contract Status: complete Value: 303215.000000 No de dossier: 1133334026 Fournisseur: GROUPE MÉCANO Buyer: SERVICE DE L'EAU -------------------------------- Date: 2014-01-06T00:00:00-05:00 Subject: Organisation et administration Language: fr Procurement Method Rationale: contract Status: complete Value: 2570.210000 No de dossier: CAR730834 Fournisseur: MECANO ALCA INC Buyer: SERVICE DE LA CONCERTATION DES ARRONDISSEMENTS ET RESSOURCES MATÉRIELLES -------------------------------- Date: 2013-11-12T00:00:00-05:00 Subject: Organisation et administration Language: fr Procurement Method Rationale: contract Status: complete Value: 6014.250000 No de dossier: 908753 Fournisseur: MECANO ALCA INC Buyer: SERVICE DE LA CONCERTATION DES ARRONDISSEMENTS ET RESSOURCES MATÉRIELLES -------------------------------- Date: 2013-09-30T00:00:00-04:00 Subject: Organisation et administration Language: fr Procurement Method Rationale: contract Status: complete Value: 4081.150000 No de dossier: 889224 Fournisseur: GROUPE MECANO INC Buyer: SERVICE DE LA CONCERTATION DES ARRONDISSEMENTS ET RESSOURCES MATÉRIELLES -------------------------------- Date: 2013-06-13T00:00:00-04:00 Subject: Organisation et administration Language: fr Procurement Method Rationale: contract Status: complete Value: 2408.430000 No de dossier: CAR715266 Fournisseur: MECANO ALCA INC Buyer: SERVICE DE LA CONCERTATION DES ARRONDISSEMENTS ET RESSOURCES MATÉRIELLES -------------------------------- Date: 2013-02-13T00:00:00-05:00 Subject: Organisation et administration Language: fr Procurement Method Rationale: contract Status: complete Value: 2300.340000 No de dossier: CAR688205 Fournisseur: MECANO ALCA INC Buyer: SERVICE DE LA CONCERTATION DES ARRONDISSEMENTS ET RESSOURCES MATÉRIELLES -------------------------------- Date: 2012-04-18T00:00:00-04:00 Subject: Organisation et administration Language: fr Procurement Method Rationale: contract Status: complete Value: 5569.910000 No de dossier: CAR681364 Fournisseur: MECANO ALCA INC Buyer: SERVICE DE LA CONCERTATION DES ARRONDISSEMENTS ET RESSOURCES MATÉRIELLES -------------------------------- Date: 2012-02-16T00:00:00-05:00 Subject: Arrondissements Language: fr Procurement Method Rationale: contract Status: complete Value: 3215.670000 No de dossier: 724489 Fournisseur: MECANO ALCA INC Buyer: ARRONDISSEMENT D'AHUNTSIC-CARTIERVILLE -------------------------------- Date: 2012-02-06T00:00:00-05:00 Subject: Arrondissements Language: fr Procurement Method Rationale: contract Status: complete Value: 3250.260000 No de dossier: 720340 Fournisseur: MECANO ALCA INC Buyer: ARRONDISSEMENT D'AHUNTSIC-CARTIERVILLE -------------------------------- Date: 2011-12-08T00:00:00-05:00 Subject: Sports, loisirs, culture et développement social Language: fr Procurement Method Rationale: contract Status: complete Value: 14214.720000 No de dossier: 700785 Fournisseur: MECANO-INDUSTRIE INC. Buyer: SERVICE DE LA QUALITÉ DE VIE On Sun, Sep 27, 2015 at 8:31 AM, Pascal Robichaud <[hidden email]> wrote: > Hello, > > Anybody would have Python 3.4 code to extract the data from the json > OpenContracting standard??? > > I'm working on a web site to display contrats to be awarded by Montreal > City, based on the PDF file prepared for the City Council and others > meetings > (http://ville.montreal.qc.ca/portal/page?_pageid=5798,85931607&_dad=portal&_schema=PORTAL). > > I then want to show past contrats of the supplier (ex.: > http://contratsouvertsmtl.info/ce/ in the darker gray sections), based on > the json coming from the city's site API (ex.: > http://ville.montreal.qc.ca/vuesurlescontrats/api/releases?q=mecano&format=json). > > Tks > > Pascal Robichaud > Données ouvertes 101 > @DO101Mtl > > Code I have so far, but having some problems: > > import requests > import json > > url = > "http://ville.montreal.qc.ca/vuesurlescontrats/api/releases?q=GROUPE%20MECANO&format=json" > > r = requests.get(url) > r.encoding = 'utf-8' > > data = json.loads(r.text) > > #Nombre de contrats du fournisseur > print(data["meta"]["count"]) > > for release in data["releases"]: > print("-----------------------------------------") > print("Date: " + release["date"]) > print("subject: " + release["subject"][0]) > print("language: " + release["language"]) > print("tag: " + release["tag"]) > > #release.tender > for tender in release["tender"]: > print(tender) #problem with extracting the data > > #release.award > print() > for award in release["awards"]: > for value in award["value"]: > print(value) > > if award["repartition"]: > print("Répartition: " + award["repartition"]) > > print("No de dossier: " + award["id"]) > > for supplier in award["suppliers"]: > print("Fournisseur: " + supplier["name"]) > > #release.buyer > print() > for buyer in release["buyer"]: > print(buyer["name"]) > > > > > > > > > > _______________________________________________ > CivicAccess-discuss mailing list > [hidden email] > http://lists.pwd.ca/mailman/listinfo/civicaccess-discuss CivicAccess-discuss mailing list [hidden email] http://lists.pwd.ca/mailman/listinfo/civicaccess-discuss |
Thanks Glem, I check it out. Pascal 2015-09-27 10:33 GMT-04:00 Glen Newton <[hidden email]>: Pascal, _______________________________________________ CivicAccess-discuss mailing list [hidden email] http://lists.pwd.ca/mailman/listinfo/civicaccess-discuss |
Free forum by Nabble | Edit this page |