2 # -*- coding: utf-8 -*-
4 # Run this script to generate the comic .md files from the CSV files
5 # and put them into content/comic.
8 csvfile_main
= open('./comic_data.csv', newline
='')
9 if csvfile_main
== None:
10 print('Could not load main CSV file!')
16 csvfile
= open('./comic_data_'+lang
+'.csv', newline
='')
18 print('Could not load language CSV file!')
20 csvfiles_lang
[lang
] = csvfile
23 # Re-open main file to reset read/write pointer
24 # TODO: Properly use seek function...
25 csvfile_main
= open('./comic_data.csv', newline
='')
26 if csvfile_main
== None:
27 print('Could not re-open main CSV file!')
31 reader_main
= csv
.reader(csvfile_main
, delimiter
=',', quotechar
='"')
32 for row
in reader_main
:
37 # The version of the comic, in case a comic needs updating
38 # The first version is always 1 and is incremented later.
41 csvfile_lang
= csvfiles_lang
[lang
]
42 reader_lang
= csv
.reader(csvfile_lang
, delimiter
=',', quotechar
='"')
43 for row_lang
in reader_lang
:
44 _id_lang
= row_lang
[0]
45 if _id_main
== _id_lang
:
46 if (len(row_lang
) < 4):
47 print('Insufficient columns in line '+_id_main
+' (lang='+lang
+')')
52 authorComment
= row_lang
[3]
53 table
.append([_id_main
, topics
, creationDate
, publishDate
, version
, title
, altText
, authorComment
])
59 topics_t
= topics
.replace("|", "\",\"")
61 topics_t
= "\"" + topics_t
+ "\""
67 authorComment
= row
[7]
69 if title
!= "___UNUSED___":
72 out
+= "weight= \"" + _id
+ "\"\n"
73 out
+= "title = \"" + title
+ "\"\n"
74 out
+= "topics = [" + topics_t
+ "]\n"
75 out
+= "creationDate = \"" + creationDate
+ "\"\n"
76 out
+= "date = \"" + publishDate
+ "\"\n"
77 out
+= "publishDate = \"" + publishDate
+ "\"\n"
78 out
+= "comic_version = \"" + version
+ "\"\n"
79 if altText
!= "" and altText
!= None:
80 out
+= "alt_text = \"" + altText
+ "\"\n"
81 if authorComment
!= "" and authorComment
!= None:
82 out
+= "author_comment = \"" + authorComment
+ "\"\n"
89 with
open("./content/comic/"+_id
+lang_tag
+".md", "w", encoding
='utf-8') as file: