From 571b1f995c00aad59315b4051c18d07952517a1d Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 12 Sep 2017 09:49:38 +0200 Subject: [PATCH] 1st commit --- .htaccess | 3 ++ autoloader.php | 46 ++++++++++++++++++ build/.htaccess | 2 + build/service/lib/months.php | 16 +++++++ build/service/lib/parse.php | 79 +++++++++++++++++++++++++++++++ build/service/lib/update.php | 92 ++++++++++++++++++++++++++++++++++++ build/service/main.sh | 48 +++++++++++++++++++ config/.htaccess | 2 + public_html/.htaccess | 4 ++ public_html/index.php | 6 +++ tmp/cursus.json | 1 + tmp/period.json | 1 + 12 files changed, 300 insertions(+) create mode 100644 .htaccess create mode 100644 autoloader.php create mode 100644 build/.htaccess create mode 100644 build/service/lib/months.php create mode 100644 build/service/lib/parse.php create mode 100644 build/service/lib/update.php create mode 100644 build/service/main.sh create mode 100644 config/.htaccess create mode 100644 public_html/.htaccess create mode 100644 public_html/index.php create mode 100644 tmp/cursus.json create mode 100644 tmp/period.json diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..a80b524 --- /dev/null +++ b/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine on + +RewriteRule ^(.*)$ public_html/$1 [QSA,L] diff --git a/autoloader.php b/autoloader.php new file mode 100644 index 0000000..b17cf87 --- /dev/null +++ b/autoloader.php @@ -0,0 +1,46 @@ + Nom de la classe appelee + * + */ + function autoloader($className){ + $path = ''; + + /* [1] On utilise le namespace pour localiser + ===============================================*/ + // On remplace les '\' par des '/' + $path = str_replace('\\', '/', $className) . '.php'; + $path = __BUILD__.'/'.$path; + + // Si le fichier existe + if( file_exists($path) ) + require_once $path; // on inclue le fichier + + } + + // On definit l'autoloader comme autoloader (obvious) + spl_autoload_register('autoloader', false, true); + + +?> diff --git a/build/.htaccess b/build/.htaccess new file mode 100644 index 0000000..93169e4 --- /dev/null +++ b/build/.htaccess @@ -0,0 +1,2 @@ +Order deny,allow +Deny from all diff --git a/build/service/lib/months.php b/build/service/lib/months.php new file mode 100644 index 0000000..9d8b758 --- /dev/null +++ b/build/service/lib/months.php @@ -0,0 +1,16 @@ + '01', + 'février' => '02', + 'mars' => '03', + 'avril' => '04', + 'mai' => '05', + 'juin' => '06', + 'juillet' => '07', + 'août' => '08', + 'septembre' => '09', + 'octobre' => '10', + 'novembre' => '11', + 'décembre' => '12' + ]; \ No newline at end of file diff --git a/build/service/lib/parse.php b/build/service/lib/parse.php new file mode 100644 index 0000000..acb64d7 --- /dev/null +++ b/build/service/lib/parse.php @@ -0,0 +1,79 @@ + abort */ + if( $argc <= 2 ) + exit(1); + + /* (2) If @type incorrect */ + if( !in_array($argv[1], ['cursus', 'period']) ) + die(" * incorrect file type\n"); + + /* (3) Check given file */ + if( !file_exists($argv[2]) ) + die(" * file does not exist\n"); + + + + + + /* [2] Try to access file's content + =========================================================*/ + /* (1) Read file */ + $raw = file_get_contents($argv[2]); + + /* (2) Manage error */ + if( !is_string($raw) ) + die(" * Cannot read file\n"); + + /* (3) Split by lines */ + $raw = explode("\n", $raw); + + + + /* [3] Parse data + =========================================================*/ + /* (1) Prepare the output list */ + $list = []; + + /* (2) Cursur parser */ + if( $argv[1] == 'cursus' ){ + + foreach($raw as $line) + if( preg_match('@"grDiplome","(?:<)?(.+)(?:>)?","T(.+)"@i', $line, $m) ) + $list[ html_entity_decode($m[1]) ] = "T${m[2]}"; + + /* (3) Period parser */ + }else{ + + $first = null; + + foreach($raw as $line){ + + if( preg_match('@"T\d+","du \d+ au (\d+) ([a-z]+) (\d+)","T\d+S(.+)"@i', $line, $m) ){ + + /* (3.1) Translate month */ + $month = $monthList[$m[2]]; + + /* (3.2) Get date of monday */ + $list[ "S${m[4]}" ] = date('d-m-Y', strtotime("${m[1]}-$month-${m[3]} - 5 days")); + } + + } + } + + + + /* [4] Write data back + =========================================================*/ + if( !file_put_contents("$ABSROOT/../../tmp/${argv[1]}.json", json_encode($list)) ) + die(" * Cannot write parsed data back\n"); + + + exit(0); \ No newline at end of file diff --git a/build/service/lib/update.php b/build/service/lib/update.php new file mode 100644 index 0000000..967b7e3 --- /dev/null +++ b/build/service/lib/update.php @@ -0,0 +1,92 @@ + "$ABSROOT/../../tmp/cursus.json", + 'period' => "$ABSROOT/../../tmp/period.json", + ]; + + /* (1) cursus list */ + if( !file_exists($path['cursus']) ) + die(" * Missing tmp/cursus.json\n"); + + /* (2) period list */ + if( !file_exists($path['period']) ) + die(" * Missing tmp/period.json\n"); + + } + + + /* [2] Parse cursus list + =========================================================*/ { + /* (1) Read from file */ + $clist = file_get_contents($path['cursus']); + + /* (2) Manage error */ + if( $clist == false ) + die(" * Cannot read cursus file\n"); + + /* (3) Parse JSON */ + $clist = json_decode($clist, true); + + /* (4) Manage error */ + if( $clist == null ) + die(" * Cannot parse cursus file\n"); + + } + + + /* [3] Parse period list + =========================================================*/ { + + /* (1) Read from file */ + $plist = file_get_contents($path['period']); + + /* (2) Manage error */ + if( $plist == false ) + die(" * Cannot read period file\n"); + + /* (3) Parse JSON */ + $plist = json_decode($plist, true); + + /* (4) Manage error */ + if( $plist == null ) + die(" * Cannot parse period file\n"); + + } + + + + /* [4] Manage each cursus + =========================================================*/ { + + /* (1) For each cursus */ + foreach($clist as $cname=>$cvalue){ + + /* (1.2) Create a directory */ + if( !file_exists("$ABSROOT/../../tmp/$cvalue") ) + file_put_contents("$ABSROOT/../../tmp/$cvalue.ics", ""); + + + /* (1) Download all images + ---------------------------------------------------------*/ + foreach($plist as $pvalue=>$pdate) + "http://sciences.univ-pau.fr/edt/diplomes/${cvalue}${pvalue}.png"; // image file + + + } + + + } + + + + + diff --git a/build/service/main.sh b/build/service/main.sh new file mode 100644 index 0000000..1699c46 --- /dev/null +++ b/build/service/main.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Absolute root dir +ABSROOT=$( dirname $(realpath $0) ); + + + +# [1] Download the list of Diplomes +#========================================================# +# (1) Get the diplomes list # +wget http://sciences.univ-pau.fr/edt/_ressource.js -qO $ABSROOT/../../tmp/cursus.js && echo "* downloaded successfully" || echo "* download failed" || exit 1; + +# (2) Get Period list # +wget http://sciences.univ-pau.fr/edt/_periode.js -qO $ABSROOT/../../tmp/period.js && echo "* downloaded successfully" || echo "* download failed" || exit 1; + + + + +# [2] Parse these lists +#========================================================# +# (1) Parse the diplomes list # +php $ABSROOT/lib/parse.php cursus $ABSROOT/../../tmp/cursus.js && echo "* parsed successfully" || echo "* parsing failed" || exit 1; + +# (2) Parse the period list # +php $ABSROOT/lib/parse.php period $ABSROOT/../../tmp/period.js && echo "* parsed successfully" || echo "* parsing failed" || exit 1; + + + + +# [3] Update ICS files +#========================================================# +# (1) Create ICS files # +php $ABSROOT/lib/update.php; + +# (2) Remove buffer data # +rm -r $ABSROOT/../../tmp/*.ics + + + + +# [X] Remove downloaded original files +#========================================================# +# (1) Remove cursus # +rm $ABSROOT/../../tmp/cursus.js && echo "* removed successfully" || echo "* removing failed" || exit 1; + +# (2) Remove period # +rm $ABSROOT/../../tmp/period.js && echo "* removed successfully" || echo "* removing failed" || exit 1; + diff --git a/config/.htaccess b/config/.htaccess new file mode 100644 index 0000000..93169e4 --- /dev/null +++ b/config/.htaccess @@ -0,0 +1,2 @@ +Order deny,allow +Deny from all diff --git a/public_html/.htaccess b/public_html/.htaccess new file mode 100644 index 0000000..760dba5 --- /dev/null +++ b/public_html/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine on + +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^(.*)$ index.php?url=/$1 [QSA,L] diff --git a/public_html/index.php b/public_html/index.php new file mode 100644 index 0000000..2559cc6 --- /dev/null +++ b/public_html/index.php @@ -0,0 +1,6 @@ + CMI-CBE Bio 1\u00e8re Ann\u00e9e":"T0005396693","CMI- CBE 1\u00e8re Ann\u00e9e> CMI-CBE Chimie 1\u00e8re Ann\u00e9e":"T0005396692","CMI- CBE 2\u00e8me Ann\u00e9e> CMI-CBE Bio 2\u00e8me Ann\u00e9e":"T0005396892","CMI- CBE 2\u00e8me Ann\u00e9e> CMI-CBE Chimie 2\u00e8me Ann\u00e9e":"T0005396893","CMI- GP 1\u00e8re Ann\u00e9e> CMI-GP G\u00e9osciences 1\u00e8re Ann\u00e9e":"T0005396862","CMI- GP 1\u00e8re Ann\u00e9e> CMI-GP R\u00e9serv et Product 1\u00e8re Ann\u00e9e":"T0005396863","L1 Biologie> L1 BIO groupe 1":"T0000000491","L1 Biologie> L1 BIO groupe 2":"T0000000494","L1 Biologie> L1 BIO groupe 3":"T0005395984","L1 Biologie> L1 BIO groupe 4":"T0005396527","L1 Informatique> L1 Info Gr1":"T0005396004","L1 Informatique> L1 Info Gr2":"T0005396003","L1 Informatique> L1 Info Gr3":"T0005396450","L1 Maths> L1 MATH Gr1":"T0005396556","L1 Maths> L1 MATH Gr2":"T0005396557","L1 Maths> L1 MATH Gr3":"T0005396715","L1 MIASHS> L1 MIASHS Gr1":"T0005396232","L1 MIASHS> L1 MIASHS Gr2":"T0005396233","L1 Phys. et Chim.> L1 PC groupe 1":"T0000000488","L1 Phys. et Chim.> L1 PC groupe 2":"T0000000489","L1 Phys. et Chim.> L1 PC groupe 3":"T0005396633","L1 Sciences de la Terre> L1 SDT GR 1":"T0005396887","L1 Sciences de la Terre> L1 SDT GR 2":"T0005396888","L2 Biologie> L2 BIO GR1":"T0005396244","L2 Biologie> L2 BIO GR2":"T0005396245","L2 Biologie> L2 BIO GR3":"T0005396246","L2 Biologie> L2 BIO GR4":"T0005396690","L2 Informatique> L2 Info Gr1":"T0005395091","L2 Informatique> L2 Info Gr2":"T0005395092","L2 Informatique> L2 Info Gr3":"T0005396870","L2 Math\u00e9matiques> L2 MATH Gr 1":"T0005394768","L2 Math\u00e9matiques> L2 MATH Gr 2":"T0005396687","L3 Biologie> L3 BIO G1":"T0000000219","L3 Biologie> L3 BIO G2":"T0000000218","L3 Biologie> L3 BIO G3":"T0005396782","L3 informatique> L3 info groupe 1":"T0000000246","L3 informatique> L3 info groupe 2":"T0000000247","L3 Math\u00e9matiques> L3 Math G 1":"T0005396879","L3 Math\u00e9matiques> L3 Math G 2":"T0005396880","M1 G\u00e9nie p\u00e9trolier> M1 GP G\u00e9osciences":"T0005394886","M1 G\u00e9nie p\u00e9trolier> M1 GP Production et trait":"T0005394888","M1 G\u00e9nie p\u00e9trolier> M1 GP R\u00e9servoirs":"T0005394887","M1 Technologie de l'Internet> M1 Tech Inter groupe 1":"T0000000377","M1 Technologie de l'Internet> M1 Tech Inter groupe 2":"T0000000378","M2 G\u00e9nie p\u00e9trolier> M2 GP G\u00e9osciences":"T0005394889","M2 G\u00e9nie p\u00e9trolier> M2 GP Production et trait":"T0005394891","M2 G\u00e9nie p\u00e9trolier> M2 GP R\u00e9servoirs":"T0005394890"} \ No newline at end of file diff --git a/tmp/period.json b/tmp/period.json new file mode 100644 index 0000000..8627949 --- /dev/null +++ b/tmp/period.json @@ -0,0 +1 @@ +{"S0000000000002":"11-09-2017","S0000000000004":"18-09-2017","S0000000000008":"25-09-2017","S0000000000010":"02-10-2017","S0000000000020":"09-10-2017","S0000000000040":"16-10-2017","S0000000000080":"23-10-2017","S0000000000200":"06-11-2017","S0000000000400":"13-11-2017","S0000000000800":"20-11-2017"} \ No newline at end of file