0.1.4 • Published 10 years ago

proapi v0.1.4

Weekly downloads
18
License
-
Repository
github
Last release
10 years ago

node-proAPI

PRONOTE 2014 - Permet de se connecter à Pronote sans passer par l'interface web.

Voici un exemple script pour récupérer les devoirs à faire :

var proAPI = require("proAPI"),
	fs = require('fs');

var PRONOTE = new proAPI({
	url: "http://XXXXXXXXXXXXXXX/pronote/",
	user: ["username", "password"],
	//proxy: "http://localhost:8000/" // activer le proxy pour le debogage
}, function() {
	PRONOTE.getHomework(function(aJSON) {
		var dmy2mdy = function(a) {
			return a.replace(/^(\d+)\/(\d+)\/(\d+)$/, "$2/$1/$3");
		};

		var listeTravaux = aJSON.xml.PageCahierDeTexteReponse.ListeTravauxAFaire[0].TravailAFaire,
			travail = null;

		var jours = [],
			travaux = [],
			cle, date, matiere, tache;
		for (var x in listeTravaux) {
			travail = listeTravaux[x];

			date = +new Date(dmy2mdy(travail.PourLe[0]._));
			matiere = travail.Matiere[0].$.L;
			tache = travail.Descriptif[0]._;
			tache = tache.replace(/<div>\s+<\/div>/g, "");
			tache = tache.replace(/<div>(.+?)<\/div>/g, "$1");
			tache = tache.replace(/(\r\n)\1+/g, "");

			if (jours.indexOf(date) === -1)
				jours.push(date);

			if (date >= new Date().setHours(0,0,0,0)) 
				travaux.push([date, matiere, tache]);
		}

		jours.sort();
		travaux.sort(function (a, b) {
			return jours.indexOf(a[0]) > jours.indexOf(b[0]);
		});
		console.log(travaux);
	});

	PRONOTE.clearPresence();
});