forked from daymade/Twitter-Block-Porn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge.sh
executable file
·36 lines (25 loc) · 1.09 KB
/
merge.sh
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
#!/bin/bash
set -e
inputDir="lists/snapshot"
intermediateFile="lists/lists.json"
allFile="lists/all.json"
blockFile="lists/block.json"
for file in "$inputDir"/*.json; do
filename=$(basename "$file")
outputFile="lists/$filename"
echo $file
# Extract necessary information and write to a snapshot file
jq '[.[] | {id_str: .id_str, screen_name: .screen_name, name: .name}]' "$file" > "$file.snapshot"
# Ensure the intermediate and output files exist
touch "$outputFile"
touch "$intermediateFile"
# Merge the snapshot file with the current output file, ensuring uniqueness
jq -s 'add | unique_by(.id_str)' "$outputFile" "$file.snapshot" > temp.json && mv temp.json "$outputFile"
# Merge the output file with the intermediate file
jq -s 'add | unique_by(.id_str)' "$outputFile" "$intermediateFile" > temp.json && mv temp.json "$intermediateFile"
done
# Ensure the files exist
touch "$allFile"
touch "$blockFile"
# Merge block file with intermediate file to create final output
jq -s 'add | unique_by(.id_str)' "$blockFile" "$intermediateFile" > temp.json && mv temp.json "$allFile"