Skip to content

Instantly share code, notes, and snippets.

@pleabargain
Last active September 27, 2021 21:47
Show Gist options
  • Save pleabargain/1e9a23b9c8d53e2c3e3146becbc29986 to your computer and use it in GitHub Desktop.
Save pleabargain/1e9a23b9c8d53e2c3e3146becbc29986 to your computer and use it in GitHub Desktop.
create a presentation from csv with revealjs and python3
#!/usr/bin/python3
# resources https://revealjs.com/
# resources https://spielend-programmieren.at/en/
import csv
import sys
import textwrap
DATABASE = "/home/dgd/Desktop/TODO_reveal_slide_creator/Video.horst_presentation/Horst.data.csv"
HTML = """
<html>
<head>
<meta charset="utf-8">
<title>reveal.js – The HTML Presentation Framework</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--<link rel="stylesheet" href="dist/reset.css">-->
<link rel="stylesheet" href="dist/reveal.css">
<!--<link rel="stylesheet" href="dist/theme/black.css" id="theme">-->
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<!-- block used by python -->
{}
</div>
</div>
<script src="dist/reveal.js"></script>
<script>
Reveal.initialize();
</script>
</body>
</html>
"""
DETAIL = """
<section>
<!--<table>
<tr>
<td>-->
<div style="float:left;padding:0px;">
<img style = "max-height:600px; max-width:500px; height:auto; width:auto;"
src="{}" > <!-- big image -->
</div>
<div width="40%" style="float:right;padding:0px;text-align:left;">
<img src="/home/dgd/Desktop/TODO_reveal_slide_creator/Video.horst_presentation/Horst.jpeg" width="150"><br>
<b>Property:</b> {}<br>
<b>Company:</b> {}<br>
<b>City / Country:</b> {}<br>
<b>type:</b> {} <br>
<b>activity:</b> {} <br>
<b>month:</b> {} <br>
<!--<b>audience:</b> {} <br>-->
<br><br><br>
<!--<small>database-line: {}</small> -->
<!-- document id = line number?-->
</div>
<!--</td>
</tr>
</table>-->
</section>
"""
def split_text(text, maxlength=30):
"""
This will wrap text so that it will fit in a box
"""
text=textwrap.fill(text,width=maxlength)
# text contains \n
return text.replace('\n','<br>')
def main(command_line_args=None):
"""opens csv table, create html file for revealjs presentation"""
if command_line_args is None:
command_line_args = []
# https://docs.python.org/3/library/csv.html#csv.DictReader
sections = "" # text to add into html
with open(DATABASE) as csvfile:
reader = csv.DictReader(csvfile)
# file must remain open!
line_number = 1
for row in reader:
print("processing line number:", line_number, ":", row)
#for column in row.keys():
# data = row[column]
# if data is None or len(data.strip())==0:
# data = "<no data>"
# print(column,":",data,",", end="")
#print()
this_detail = DETAIL.format(
row["Link-to-image-website"],
row["Property-code"],
row["TO-Media"],
row["City"],
row["Type"],
split_text(row["Activity-publication"]),
row["Month"],
row["Audience"],
line_number,
)
sections += this_detail
line_number += 1
# next row
# close csv
print("database is closed now")
print("writing html file...")
with open("bHorst.Create.Slides.from.CSV.html", "w") as tmp:
tmp.write(HTML.format(sections))
print("Horst.Create.Slides.from.CSV.html is written")
if __name__ == "__main__":
main(sys.argv[1:]) # pass command line arguments to main function except the python program name itself
Month No Property-code TO-Media Type Activity-publication City Comments Status Currency Amount Mode-of-payment TOTAL-in-USD Estimated-value-if-FOC Audience Link-to-image-website
005 May 1 ABC Contact Horst Jens Internet Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210326_103549.jpg
005 May 2 DEF Contact Horst Jens Internet Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210327_085013.jpg
005 May 3 GHI Contact Horst Jens Internet Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210327_085015.jpg
005 May 4 JKL Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210327_085020.jpg
005 May 5 ABC Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210329_115023.jpg
005 May 6 DEF Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210329_115028.jpg
006 June 1 GHI Contact Horst Jens Internet Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210329_115035.jpg
006 June 2 JKL Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210329_115041.jpg
006 June 3 ABC Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210329_115051.jpg
006 June 4 DEF Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210329_115057.jpg
006 June 5 GHI Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210329_115111.jpg
006 June 6 JKL Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210329_121521.jpg
006 June 7 ABC Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210330_082455.jpg
006 June 8 DEF Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210330_082458.jpg
006 June 9 GHI Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210330_082502.jpg
006 June 10 JKL Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/20210401_083449.jpg
006 June 11 ABC Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/a1.jpg
006 June 12 DEF Contact Horst Jens Webinar Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/a2.jpg
006 June 13 GHI Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/a3.jpg
007 July 1 JKL Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/aaanothertry.jpg
007 July 2 ABC Contact Horst Jens Internet Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/aanewhoriz.jpg
007 July 3 ABC Contact Horst Jens Newsletters Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/anewhoriz.jpg
007 July 4 DEF Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/merged_image_12_16_27_dim_8064x1960.jpg
007 July 5 GHI Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/merged_image_12_17_9_dim_4032x3920.jpg
008 August 1 JKL Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/merged_image_12_18_4_dim_4032x4900.jpg
008 August 2 ABC Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/merged_image_12_19_25_dim_4032x7840.jpg
008 August 3 DEF Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/merged_image_12_20_39_dim_8064x3920.jpg
008 August 4 GHI Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/merged_image_12_20_55_dim_8064x3920.jpg
008 August 5 JKL Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/merged_image_12_21_2_dim_8064x3920.jpg
008 August 6 ABC Contact Horst Jens Social Media Horst is a skilled programmer and instructor. Completed FOC file:///home/dgd/Pictures/chalk-art/newhoriz.jpg
file:///home/dgd/Pictures/chalk-art/preview.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment