File size: 912 Bytes
db30823
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
"""
2018: 10,732,804
2019: 9,725,094
2020: 31,449,608
2021: 37,282,461
2022: 74,024,575
"""
import json
import os

files = [
    "dataset/tweets/2018.jsonline",
    "dataset/tweets/2019.jsonline",
    "dataset/tweets/2020.jsonline",
    "dataset/tweets/2021.jsonline",
    "dataset/tweets/2022.jsonline"
]
n_shard = 10000
root_dir = "dataset/tweets_sharded"

os.makedirs(root_dir, exist_ok=True)
counter = 0
file_id = 0
f_writer = open(f"{root_dir}/{file_id}.jsonl")
for i in files:
    with open(i) as f:
        for line in f:
            tmp = json.loads(line)
            tmp = {"id": tmp["id"], "text": tmp["text"], "date": tmp["created_at"]}
            f_writer.write(json.dumps(tmp) + '\n')
            counter += 1
            if counter > n_shard:
                file_id += 1
                counter = 0
                f_writer.close()
                f_writer = open(f"{root_dir}/{file_id}.jsonl")