eshan6704 commited on
Commit
44dfbf5
·
verified ·
1 Parent(s): b70cc59

Update common.py

Browse files
Files changed (1) hide show
  1. common.py +85 -1
common.py CHANGED
@@ -1,9 +1,77 @@
1
  # common.py
2
  import datetime
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  def format_large_number(num):
5
  if not isinstance(num, (int, float)):
6
- return num # Return as-is if not a number
7
  sign = '-' if num < 0 else ''
8
  num = abs(float(num))
9
  if num >= 1_000_000_000_000:
@@ -22,3 +90,19 @@ def format_timestamp_to_date(timestamp):
22
  return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d')
23
  except ValueError:
24
  return "Invalid Date"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # common.py
2
  import datetime
3
 
4
+ # --- Shared CSS for all modules ---
5
+ STYLE_BLOCK = """
6
+ <style>
7
+ .styled-table {
8
+ border-collapse: collapse;
9
+ margin: 10px 0;
10
+ font-size: 0.9em;
11
+ font-family: sans-serif;
12
+ width: 100%;
13
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
14
+ }
15
+ .styled-table th, .styled-table td {
16
+ padding: 8px 10px;
17
+ border: 1px solid #ddd;
18
+ }
19
+ .styled-table tbody tr:nth-child(even) {
20
+ background-color: #f9f9f9;
21
+ }
22
+ .card {
23
+ width: 95%;
24
+ margin: 10px auto;
25
+ padding: 15px;
26
+ border: 1px solid #ddd;
27
+ border-radius: 8px;
28
+ background: #fafafa;
29
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
30
+ }
31
+ .card h2 {
32
+ margin-top:0;
33
+ }
34
+ .big-box {
35
+ width:95%;
36
+ margin:20px auto;
37
+ padding:20px;
38
+ border:1px solid #ccc;
39
+ border-radius:8px;
40
+ background:#fff;
41
+ box-shadow:0 2px 8px rgba(0,0,0,0.1);
42
+ font-size:0.95em;
43
+ line-height:1.4em;
44
+ max-height:400px;
45
+ overflow-y:auto;
46
+ }
47
+ .key-value-pair {
48
+ flex: 1 1 calc(20% - 15px);
49
+ box-sizing: border-box;
50
+ min-width: 150px;
51
+ background: #fff;
52
+ padding: 10px;
53
+ border: 1px solid #e0e0e0;
54
+ border-radius: 5px;
55
+ box-shadow: 0 1px 3px rgba(0,0,0,0.05);
56
+ }
57
+ .key-value-pair h3 {
58
+ font-size: 0.95em;
59
+ color: #444;
60
+ margin: 0 0 5px 0;
61
+ }
62
+ .key-value-pair p {
63
+ font-size: 0.9em;
64
+ color: #555;
65
+ margin: 0;
66
+ font-weight: bold;
67
+ }
68
+ </style>
69
+ """
70
+
71
+ # --- Shared utility functions ---
72
  def format_large_number(num):
73
  if not isinstance(num, (int, float)):
74
+ return num
75
  sign = '-' if num < 0 else ''
76
  num = abs(float(num))
77
  if num >= 1_000_000_000_000:
 
90
  return datetime.datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d')
91
  except ValueError:
92
  return "Invalid Date"
93
+
94
+ def wrap_html(title, content_html, style_block=None):
95
+ """Wrap content in a full HTML page with optional CSS."""
96
+ style = style_block if style_block else STYLE_BLOCK
97
+ return f"""
98
+ <!DOCTYPE html>
99
+ <html>
100
+ <head>
101
+ <title>{title}</title>
102
+ {style}
103
+ </head>
104
+ <body>
105
+ {content_html}
106
+ </body>
107
+ </html>
108
+ """