From 42e637b9fb461bd1df67032900df7fd6436243cb Mon Sep 17 00:00:00 2001 From: kdx Date: Thu, 12 Jan 2023 18:25:58 +0100 Subject: well here we go --- build.sh | 2 +- cite.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++----------------- scrap.sh | 2 +- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/build.sh b/build.sh index d1fd2d4..983c5fd 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ #!/bin/sh -gcc -Wall -Wextra -Wno-pointer-sign $(xml2-config --cflags --libs) -o cite cite.c +gcc -g -Wall -Wextra -Wno-pointer-sign $(xml2-config --cflags --libs) -o cite cite.c diff --git a/cite.c b/cite.c index 7db3749..9817345 100644 --- a/cite.c +++ b/cite.c @@ -14,16 +14,26 @@ typedef struct { char nationality[256]; char pitch[2048]; char poster[256]; + char times[4096]; } Movie; -Movie movies[256] = {0}; +Movie movies[64] = {0}; static void print_style(void) { + puts(""); puts(""); } -static void print_movie(const Movie *movie) +static void print_times(Movie *movie) +{ + printf("\n"); +} + +static void print_movie(Movie *movie) { if (movie->og_title[0] != '\0') printf("

%s

\n", movie->og_title); @@ -40,6 +50,8 @@ static void print_movie(const Movie *movie) printf("
  • genres : %s
  • \n", movie->main_genres); printf("
  • nationalité : %s
  • \n", movie->nationality); //printf("synopsis : %s\n", movie->pitch); + printf("
  • horaires :
  • \n"); + print_times(movie); printf("\n"); printf("\n"); } @@ -77,6 +89,9 @@ static Movie *get_movie(int id) static int set_movie_base_fields(Movie *movie, const xmlNode *node) { + const xmlNode *times_node = node->children; + if (times_node == NULL || times_node->next == NULL) + return 1; int err = 0; const xmlChar *title = xmlGetProp(node, "titre"); const xmlChar *og_title = xmlGetProp(node, "titreoriginal"); @@ -89,24 +104,26 @@ static int set_movie_base_fields(Movie *movie, const xmlNode *node) const xmlChar *nationality = xmlGetProp(node, "nationalite"); const xmlChar *pitch = xmlGetProp(node, "synopsis"); const xmlChar *poster = xmlGetProp(node, "affichette"); + const xmlChar *times = xmlNodeGetContent(times_node->next); if (title == NULL || og_title == NULL || directors == NULL || actors == NULL || prod_year == NULL || release_date == NULL || duration == NULL || main_genres == NULL || nationality == NULL || - pitch == NULL || poster == NULL) { + pitch == NULL || poster == NULL || times == NULL) { err = 1; goto set_fields_panic; } - strncpy(movie->title, title, sizeof(movie->title)); - strncpy(movie->og_title, og_title, sizeof(movie->title)); - strncpy(movie->directors, directors, sizeof(movie->directors)); - strncpy(movie->actors, actors, sizeof(movie->actors)); - strncpy(movie->prod_year, prod_year, sizeof(movie->prod_year)); - strncpy(movie->release_date, release_date, sizeof(movie->release_date)); - strncpy(movie->duration, duration, sizeof(movie->duration)); - strncpy(movie->main_genres, main_genres, sizeof(movie->main_genres)); - strncpy(movie->nationality, nationality, sizeof(movie->nationality)); - strncpy(movie->pitch, pitch, sizeof(movie->pitch)); - strncpy(movie->poster, poster, sizeof(movie->poster)); + strncpy(movie->title, title, sizeof(movie->title) - 1); + strncpy(movie->og_title, og_title, sizeof(movie->title) - 1); + strncpy(movie->directors, directors, sizeof(movie->directors) - 1); + strncpy(movie->actors, actors, sizeof(movie->actors) - 1); + strncpy(movie->prod_year, prod_year, sizeof(movie->prod_year) - 1); + strncpy(movie->release_date, release_date, sizeof(movie->release_date) - 1); + strncpy(movie->duration, duration, sizeof(movie->duration) - 1); + strncpy(movie->main_genres, main_genres, sizeof(movie->main_genres) - 1); + strncpy(movie->nationality, nationality, sizeof(movie->nationality) - 1); + strncpy(movie->pitch, pitch, sizeof(movie->pitch) - 1); + strncpy(movie->poster, poster, sizeof(movie->poster) - 1); + strncpy(movie->times, times, sizeof(movie->times) - 1); set_fields_panic: xfree(title); xfree(og_title); @@ -122,6 +139,20 @@ set_fields_panic: return err; } +static int append_movie_times(Movie *movie, const xmlNode *node) +{ + const xmlNode *times_node = node->children; + if (times_node == NULL || times_node->next == NULL) + return 1; + const xmlChar *times = xmlNodeGetContent(times_node->next); + if (times == NULL) + return 1; + strncat(movie->times, ";", sizeof(movie->times) - 1); + strncat(movie->times, times, sizeof(movie->times) - 1); + xfree(times); + return 0; +} + int main(int argc, char **argv) { if (argc != 2) @@ -146,12 +177,13 @@ int main(int argc, char **argv) if (movie->id == 0) { movie->id = id; set_movie_base_fields(movie, mov); - } + } else + append_movie_times(movie, mov); } } print_style(); - printf("

    cinéma de la cité

    \n"); - for (const Movie *movie = movies; movie->id != 0; movie++) + printf("

    cinéma de la cité

    \n"); + for (Movie *movie = movies; movie->id != 0; movie++) print_movie(movie); xmlFreeDoc(document); xmlCleanupParser(); diff --git a/scrap.sh b/scrap.sh index 7a2943d..47ad12f 100755 --- a/scrap.sh +++ b/scrap.sh @@ -2,4 +2,4 @@ ./build.sh || exit 1 curl -o seances.xml 'http://www.citebd.org/IMG/xml/allocineseances-4.xml' || exit 1 ./cite seances.xml >cite.html || exit 1 -firefox cite.html +scp cite.html root@kdx.re:/var/www/html -- cgit v1.2.3