-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_helper.py
87 lines (76 loc) · 2.69 KB
/
html_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
file: html_helper.py
language: python3
author: Annie Tiet
description: helper file for html_builder. Deals with Paragraph objects.
date: 11/2019
"""
from dataclasses import dataclass
from typing import Union
valid_img = {"images/Dubai_Miracle_Garden.jpg", "images/flowers.jpg", "images/garden1.jpg",
"images/Garden_of_Versailles.jpg", "images/happy-kid.png", "images/logo.jpg", "images/Maze_Dobrzyca.jpg",
"images/WOW.jpg"}
@dataclass
class Paragraph:
"""
class Paragraph represents a paragraph for the website.
field description:
title: title of paragraph
content: content of paragraph
image: image(s) to be added to paragraph if desired.
"""
title: str
content: str
image: list
@dataclass
class Image:
"""
class Image represents an image
field description:
name: image name
width: percentage
"""
name: str
width: Union[int, None]
def make_paragraph(image_width=100):
"""
Function that prompts paragraph components in wizard mode.
:return: Paragraph object
"""
title = input("Title of your paragraph: ")
content = input("Content of your paragraph (single line) ")
image = []
images_choice = input("Do you want to add images? [yes] ")
if images_choice == "yes" or images_choice == "":
while True:
img = input("Image file name: ")
if img not in valid_img:
print("Please enter a valid image file from the images subdirectory.")
continue
else:
image.append(Image(img, image_width))
break
while True:
choice_two = input("Do you want to add another image? [yes] ")
if choice_two == "yes" or choice_two == "":
while True:
another = input("Image file name: ")
if another not in valid_img:
print("Please enter a valid image file from the images subdirectory.")
continue
else:
image.append(Image(another, image_width))
break
else:
break
return Paragraph(title, content, image)
def paragraph_tagging(paragraph):
"""
Takes Paragraph object and puts information between html tags
:param paragraph: Paragraph object
:return: string of html
"""
html = "<h2>" + paragraph.title + "</h2><p>" + paragraph.content + "</p>"
for img in paragraph.image:
html += '<img src="' + img.name + '" width="' + str(img.width) + '%"class="center">'
return html