File size: 541 Bytes
5ae4d47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a6b60f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
import json
import tempfile
import os

from modules.db import fetch_channel_data

def json_serializer(obj):
    if hasattr(obj, "tolist"):  # NumPy arrays
        return obj.tolist()
    return str(obj)

def export_channel_json(channel_id):
    data = fetch_channel_data(channel_id)
    
    # Save to a temporary JSON file
    fd, path = tempfile.mkstemp(suffix=".json")
    with os.fdopen(fd, "w", encoding="utf-8") as f:
        json.dump(data, f, indent=2, ensure_ascii=False, default=json_serializer)
    return path