Basti1110 commited on
Commit
ff9d78a
·
verified ·
1 Parent(s): ec0d93c

Update render_report.py

Browse files
Files changed (1) hide show
  1. render_report.py +25 -25
render_report.py CHANGED
@@ -1,21 +1,23 @@
1
 
2
-
3
  import json
4
  import os
5
  import matplotlib.pyplot as plt
6
  import networkx as nx
 
 
 
 
7
 
8
- # Set safe output path
9
  output_dir = "/tmp"
10
 
11
  # Load data
12
  with open(os.path.join(output_dir, "data.json"), "r", encoding="utf-8") as f:
13
  data = json.load(f)
14
 
15
- # Generate sentiment chart
16
  sentiment_path = os.path.join(output_dir, "sentiment_pie_chart.png")
17
- labels = list(data["sentiment_overview"].keys())
18
- sizes = list(data["sentiment_overview"].values())
19
  colors = ['#4CAF50', '#FFC107', '#F44336']
20
  fig, ax = plt.subplots()
21
  ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140, colors=colors)
@@ -24,10 +26,10 @@ plt.title('Sentiment Overview')
24
  plt.savefig(sentiment_path, bbox_inches='tight')
25
  plt.close()
26
 
27
- # Generate network graph
28
  network_path = os.path.join(output_dir, "network_graph.png")
29
  G = nx.Graph()
30
- for cluster in data["network_analysis"]["clusters"]:
31
  nodes = cluster["nodes"]
32
  for i in range(len(nodes)):
33
  G.add_node(nodes[i])
@@ -41,11 +43,9 @@ plt.title("Network Influence Graph")
41
  plt.savefig(network_path, bbox_inches='tight')
42
  plt.close()
43
 
44
- # Format data into HTML
45
- from html import escape
46
-
47
  def bullet_list(items):
48
- return "\n".join(f"<li>{escape(item)}</li>" for item in items)
49
 
50
  def user_blocks(users):
51
  return "\n".join(f"<p><strong>{escape(u['username'])} ({u['type']}):</strong> {escape(u['activity_summary'])}</p>" for u in users)
@@ -53,24 +53,24 @@ def user_blocks(users):
53
  def cluster_blocks(clusters):
54
  return "\n".join(f"<p><strong>{escape(c['label'])}:</strong> {escape(c['summary'])}</p>" for c in clusters)
55
 
56
- # Load dark HTML template
57
  with open("osint_dark_template.html", "r", encoding="utf-8") as tpl:
58
  template = tpl.read()
59
 
 
60
  html_filled = template.format(
61
- summary=escape(data["summary"]),
62
- topics=", ".join(escape(topic) for topic in data["top_topics"]),
63
- users=user_blocks(data["notable_users"]),
64
- clusters=cluster_blocks(data["network_analysis"]["clusters"]),
65
- positive=data["sentiment_overview"]["positive"],
66
- neutral=data["sentiment_overview"]["neutral"],
67
- negative=data["sentiment_overview"]["negative"],
68
- flags=bullet_list(data["risk_flags"]),
69
- start=escape(data["timestamp_range"]["from"]),
70
- end=escape(data["timestamp_range"]["to"])
71
  )
72
 
73
- # Write final report
74
  with open(os.path.join(output_dir, "OSINT_Report.html"), "w", encoding="utf-8") as f:
75
- f.write(html_filled)
76
-
 
1
 
 
2
  import json
3
  import os
4
  import matplotlib.pyplot as plt
5
  import networkx as nx
6
+ from html import escape
7
+
8
+ def safe_escape(val):
9
+ return escape(str(val)) if val is not None else "N/A"
10
 
 
11
  output_dir = "/tmp"
12
 
13
  # Load data
14
  with open(os.path.join(output_dir, "data.json"), "r", encoding="utf-8") as f:
15
  data = json.load(f)
16
 
17
+ # Sentiment Chart
18
  sentiment_path = os.path.join(output_dir, "sentiment_pie_chart.png")
19
+ labels = list(data.get("sentiment_overview", {}).keys())
20
+ sizes = list(data.get("sentiment_overview", {}).values())
21
  colors = ['#4CAF50', '#FFC107', '#F44336']
22
  fig, ax = plt.subplots()
23
  ax.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140, colors=colors)
 
26
  plt.savefig(sentiment_path, bbox_inches='tight')
27
  plt.close()
28
 
29
+ # Network Graph
30
  network_path = os.path.join(output_dir, "network_graph.png")
31
  G = nx.Graph()
32
+ for cluster in data.get("network_analysis", {}).get("clusters", []):
33
  nodes = cluster["nodes"]
34
  for i in range(len(nodes)):
35
  G.add_node(nodes[i])
 
43
  plt.savefig(network_path, bbox_inches='tight')
44
  plt.close()
45
 
46
+ # Helper formatters
 
 
47
  def bullet_list(items):
48
+ return "\n".join(f"<li>{escape(item)}<\/li>" for item in items)
49
 
50
  def user_blocks(users):
51
  return "\n".join(f"<p><strong>{escape(u['username'])} ({u['type']}):</strong> {escape(u['activity_summary'])}</p>" for u in users)
 
53
  def cluster_blocks(clusters):
54
  return "\n".join(f"<p><strong>{escape(c['label'])}:</strong> {escape(c['summary'])}</p>" for c in clusters)
55
 
56
+ # Load HTML template
57
  with open("osint_dark_template.html", "r", encoding="utf-8") as tpl:
58
  template = tpl.read()
59
 
60
+ # Fill content
61
  html_filled = template.format(
62
+ summary=safe_escape(data.get("summary")),
63
+ topics=", ".join(escape(t) for t in data.get("top_topics", [])),
64
+ users=user_blocks(data.get("notable_users", [])),
65
+ clusters=cluster_blocks(data.get("network_analysis", {}).get("clusters", [])),
66
+ positive=data.get("sentiment_overview", {}).get("positive", 0),
67
+ neutral=data.get("sentiment_overview", {}).get("neutral", 0),
68
+ negative=data.get("sentiment_overview", {}).get("negative", 0),
69
+ flags=bullet_list(data.get("risk_flags", [])),
70
+ start=safe_escape(data.get("timestamp_range", {}).get("from")),
71
+ end=safe_escape(data.get("timestamp_range", {}).get("to"))
72
  )
73
 
74
+ # Save HTML
75
  with open(os.path.join(output_dir, "OSINT_Report.html"), "w", encoding="utf-8") as f:
76
+ f.write(html_filled)