summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-01-13 04:17:50 +0100
committerkdx <kikoodx@paranoici.org>2023-01-13 04:17:50 +0100
commit002c67a1eb237141d98ff493d92e9d867123bffb (patch)
treef3ba4c251335f18c48d19286748777bfc823323e
parent1684f585b61073f5fb13126868c4a6b2298c18d0 (diff)
downloadcite-scrapper-002c67a1eb237141d98ff493d92e9d867123bffb.tar.gz
generate good html
-rw-r--r--cite.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/cite.c b/cite.c
index 12545c5..6c9852b 100644
--- a/cite.c
+++ b/cite.c
@@ -15,6 +15,7 @@ typedef struct {
char nationality[256];
char pitch[2048];
char poster[256];
+ char week_times[4096];
char times[4096];
} Movie;
@@ -23,8 +24,12 @@ CURL *curl = NULL;
static void print_style(void)
{
+ puts("<!DOCTYPE html>");
+ puts("<html>");
+ puts("<head>");
puts("<meta charset=\"UTF-8\">");
puts("<link rel='stylesheet' type='text/css' href='https://kdx.re/theme.css'/>");
+ puts("</head>");
}
static void print_times(Movie *movie)
@@ -129,11 +134,13 @@ 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 *week_times = xmlNodeGetContent(times_node);
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 || times == NULL) {
+ pitch == NULL || poster == NULL || week_times == NULL ||
+ times == NULL) {
err = 1;
goto set_fields_panic;
}
@@ -148,7 +155,10 @@ static int set_movie_base_fields(Movie *movie, const xmlNode *node)
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);
+ strncpy(movie->week_times, week_times, sizeof(movie->week_times) - 1);
+ strcpy(movie->times, "<b>");
+ strncat(movie->times, times, sizeof(movie->times) - 1);
+ strncat(movie->times, "</b>", sizeof(movie->times) - 1);
set_fields_panic:
xfree(title);
xfree(og_title);
@@ -161,6 +171,8 @@ set_fields_panic:
xfree(nationality);
xfree(pitch);
xfree(poster);
+ xfree(week_times);
+ xfree(times);
return err;
}
@@ -169,11 +181,18 @@ 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 *week_times = xmlNodeGetContent(times_node);
const xmlChar *times = xmlNodeGetContent(times_node->next);
- if (times == NULL)
+ if (week_times == NULL || times == NULL) {
+ xfree(week_times);
+ xfree(times);
return 1;
+ }
+ strncat(movie->week_times, "\n", sizeof(movie->week_times) - 1);
+ strncat(movie->week_times, week_times, sizeof(movie->week_times) - 1);
strncat(movie->times, ";", sizeof(movie->times) - 1);
strncat(movie->times, times, sizeof(movie->times) - 1);
+ xfree(week_times);
xfree(times);
return 0;
}
@@ -213,11 +232,14 @@ int main(int argc, char **argv)
}
}
print_style();
- printf("<h1><a href=\"http://www.citebd.org/spip.php?film2912\">cinéma de la cité</a></h1>\n");
+ puts("<body>");
+ puts("<h1><a href=\"http://www.citebd.org/spip.php?film2912\">cinéma de la cité</a></h1>");
for (Movie *movie = movies; movie->id != 0; movie++) {
download_poster(movie);
print_movie(movie, atoi(argv[2]));
}
+ puts("</body>");
+ puts("</html>");
curl_easy_cleanup(curl);
xmlFreeDoc(document);
xmlCleanupParser();