summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-01-12 18:25:58 +0100
committerkdx <kikoodx@paranoici.org>2023-01-12 18:25:58 +0100
commit42e637b9fb461bd1df67032900df7fd6436243cb (patch)
tree7c29a10158fa37d29356a9b3e5812a23d8b2a241
parentd1c29717fcff974e51d8a6bd83851a1607f3ffd9 (diff)
downloadcite-scrapper-42e637b9fb461bd1df67032900df7fd6436243cb.tar.gz
well here we go
-rwxr-xr-xbuild.sh2
-rw-r--r--cite.c66
-rwxr-xr-xscrap.sh2
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("<meta charset=\"UTF-8\">");
puts("<link rel='stylesheet' type='text/css' href='https://kdx.re/theme.css'/>");
}
-static void print_movie(const Movie *movie)
+static void print_times(Movie *movie)
+{
+ printf("<ul>\n");
+ for (const char *tok = strtok(movie->times, ";"); tok != NULL; tok = strtok(NULL, ";"))
+ printf("<li>%s</li>\n", tok);
+ printf("</ul>\n");
+}
+
+static void print_movie(Movie *movie)
{
if (movie->og_title[0] != '\0')
printf("<h2>%s</h2>\n", movie->og_title);
@@ -40,6 +50,8 @@ static void print_movie(const Movie *movie)
printf("<li>genres : %s</li>\n", movie->main_genres);
printf("<li>nationalité : %s</li>\n", movie->nationality);
//printf("synopsis : %s\n", movie->pitch);
+ printf("<li>horaires :</li>\n");
+ print_times(movie);
printf("</ul>\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("<h1>cinéma de la cité</h1>\n");
- for (const Movie *movie = movies; movie->id != 0; movie++)
+ printf("<h1><a href=\"http://www.citebd.org/spip.php?film2912\">cinéma de la cité</a></h1>\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