-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview_renderer.py
62 lines (51 loc) · 1.87 KB
/
review_renderer.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
from typing import Dict
def highlight_text(text: str, color: str) -> str:
"""
Highlight text with a given color.
Args:
text (str): Text to highlight
color (str): Color for highlighting
Returns:
str: Highlighted HTML text
"""
return f'<span style="color: {color}; font-weight: bold;">{text}</span>' if text else ""
def render_review(review: Dict):
"""
Render a single review with highlighted text.
Args:
review (Dict): Review dictionary
Returns:
str: HTML representation of the review
"""
content = review["Content"]
# Highlight Food-related text
if review["Food"]:
content = content.replace(review["Food"], highlight_text(review["Food"], "green"))
# Highlight Service-related text
if review["Service"]:
content = content.replace(review["Service"], highlight_text(review["Service"], "blue"))
# Highlight Other text
if review["Other"]:
content = content.replace(review["Other"], highlight_text(review["Other"], "red"))
return f'''
<div style="
margin-bottom: 20px;
padding: 15px;
border: 1px solid #444;
border-radius: 8px;
background-color: #2c2c2c;
color: #f0f0f0;
">
<h3 style="margin-bottom: 10px; color: #ffffff;">{review["Name"]} <small style="color: #aaa;">({review["Date"]})</small></h3>
<p style="margin-bottom: 10px; color: #e0e0e0;">
<strong>Ratings:</strong>
<span style="margin-left: 10px;">
Overall: {review["Rating"]["Overall"]} |
Food: {review["Rating"]["Food"]} |
Service: {review["Rating"]["Service"]} |
Ambience: {review["Rating"]["Ambience"]}
</span>
</p>
<p style="color: #d0d0d0;">{content}</p>
</div>
'''