File size: 980 Bytes
f9d3aeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json

def load_first_jsonl_record(filepath):
    try:
        with open(filepath, 'r', encoding='utf-8') as f:
            first_line = f.readline().strip()
            if first_line:
                return json.loads(first_line)
            else:
                print("文件为空")
                return None
    except FileNotFoundError:
        print(f"文件未找到: {filepath}")
        return None
    except json.JSONDecodeError as e:
        print(f"JSON解析错误: {e}")
        return None
    except Exception as e:
        print(f"发生错误: {e}")
        return None

# 使用示例
if __name__ == "__main__":
    filepath = "/data/haofeiy2/social-world-model/data/splitted_polymarket/polymarket_data_processed_with_news_train_2024-11-01.jsonl"
    
    first_record = load_first_jsonl_record(filepath)
    breakpoint()
    
    if first_record:
        print("第一条记录:")
        print(json.dumps(first_record, ensure_ascii=False, indent=2))