liuzhen932 revised this gist . Go to revision
1 file changed, 6 insertions, 6 deletions
format.py
@@ -19,18 +19,18 @@ def format_response(data): | |||
19 | 19 | ||
20 | 20 | # 添加 Reason 字段(如果存在) | |
21 | 21 | if "reason" in validity: | |
22 | - | formatted_text += f" 🚫 **Reason**: {validity['reason'].upper()}\n\n" | |
22 | + | formatted_text += f" 🚫 Reason: {validity['reason'].upper()}\n\n" | |
23 | 23 | ||
24 | - | formatted_text += " 🔍 **VRP Analysis**:\n" | |
24 | + | formatted_text += " 🔍 VRP Analysis:\n" | |
25 | 25 | ||
26 | 26 | # 处理 Matched VRPs | |
27 | 27 | if vrps.get("matched"): | |
28 | - | formatted_text += " ✅ **Matched VRPs**:\n" | |
28 | + | formatted_text += " ✅ Matched VRPs:\n" | |
29 | 29 | for vrp in vrps["matched"]: | |
30 | 30 | formatted_text += ( | |
31 | - | f" 🌐 **ASN**: {vrp['asn']}\n" | |
32 | - | f" 📍 **Prefix**: {vrp['prefix']}\n" | |
33 | - | f" 🔑 **Max Length**: {vrp['max_length']}\n" | |
31 | + | f" 🌐 ASN: {vrp['asn']}\n" | |
32 | + | f" 📍 Prefix: {vrp['prefix']}\n" | |
33 | + | f" 🔑 Max Length: {vrp['max_length']}\n" | |
34 | 34 | ) | |
35 | 35 | else: | |
36 | 36 | formatted_text += " ❌ **No Matched VRPs Found**\n" |
liuzhen932 revised this gist . Go to revision
1 file changed, 64 insertions
format.py(file created)
@@ -0,0 +1,64 @@ | |||
1 | + | def format_response(data): | |
2 | + | route = data["validated_route"]["route"] | |
3 | + | validity = data["validated_route"]["validity"] | |
4 | + | vrps = validity.get("VRPs", {}) | |
5 | + | generated_time = data["generatedTime"] | |
6 | + | ||
7 | + | # 根据状态选择不同 emoji 和描述 | |
8 | + | state_emoji = "✅" if validity["state"] == "valid" else "❌" | |
9 | + | state_str = validity["state"].capitalize() | |
10 | + | ||
11 | + | formatted_text = ( | |
12 | + | f"🌐 Route Information\n" | |
13 | + | f" 🏢 Origin ASN: {route['origin_asn']}\n" | |
14 | + | f" 📍 Prefix: {route['prefix']}\n\n" | |
15 | + | f"{state_emoji} Validation Result\n" | |
16 | + | f" 💬 State: {state_str}\n" | |
17 | + | f" 📝 Description: {validity['description']}\n" | |
18 | + | ) | |
19 | + | ||
20 | + | # 添加 Reason 字段(如果存在) | |
21 | + | if "reason" in validity: | |
22 | + | formatted_text += f" 🚫 **Reason**: {validity['reason'].upper()}\n\n" | |
23 | + | ||
24 | + | formatted_text += " 🔍 **VRP Analysis**:\n" | |
25 | + | ||
26 | + | # 处理 Matched VRPs | |
27 | + | if vrps.get("matched"): | |
28 | + | formatted_text += " ✅ **Matched VRPs**:\n" | |
29 | + | for vrp in vrps["matched"]: | |
30 | + | formatted_text += ( | |
31 | + | f" 🌐 **ASN**: {vrp['asn']}\n" | |
32 | + | f" 📍 **Prefix**: {vrp['prefix']}\n" | |
33 | + | f" 🔑 **Max Length**: {vrp['max_length']}\n" | |
34 | + | ) | |
35 | + | else: | |
36 | + | formatted_text += " ❌ **No Matched VRPs Found**\n" | |
37 | + | ||
38 | + | # 处理 Unmatched AS VRPs | |
39 | + | if vrps.get("unmatched_as"): | |
40 | + | formatted_text += " ❌ **Unmatched AS VRPs**:\n" | |
41 | + | for vrp in vrps["unmatched_as"]: | |
42 | + | formatted_text += ( | |
43 | + | f" 🌐 **ASN**: {vrp['asn']}\n" | |
44 | + | f" 📍 **Prefix**: {vrp['prefix']}\n" | |
45 | + | f" 🔑 **Max Length**: {vrp['max_length']}\n" | |
46 | + | ) | |
47 | + | else: | |
48 | + | formatted_text += " ✅ **No Unmatched AS Found**\n" | |
49 | + | ||
50 | + | # 处理 Unmatched Length VRPs | |
51 | + | if vrps.get("unmatched_length"): | |
52 | + | formatted_text += " ❌ **Unmatched Length VRPs**:\n" | |
53 | + | for vrp in vrps["unmatched_length"]: | |
54 | + | formatted_text += ( | |
55 | + | f" 🌐 **ASN**: {vrp['asn']}\n" | |
56 | + | f" 📍 **Prefix**: {vrp['prefix']}\n" | |
57 | + | f" 🔑 **Max Length**: {vrp['max_length']}\n" | |
58 | + | ) | |
59 | + | else: | |
60 | + | formatted_text += " ✅ No Unmatched Length Found\n" | |
61 | + | ||
62 | + | formatted_text += f"\n⏳ Generated Time: {generated_time}" | |
63 | + | ||
64 | + | return formatted_text |