-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_pages.sh
executable file
·71 lines (55 loc) · 1.91 KB
/
create_pages.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
cd "$(dirname "$0")"
yes | find . -mindepth 2 -type f -exec mv -i '{}' . \;
yes | find . -mindepth 1 -maxdepth 1 -type d -exec rm -r '{}' \;
dir_counter=1
all_latest_files=()
while IFS= read -r file; do
all_latest_files+=("$file")
done < <(grep -rl '"created_at":' *.json | xargs -I{} stat --format="%Y %n" {} | sort -nr | cut -d' ' -f2-)
while (( ${#all_latest_files[@]} > 0 )); do
latest_files=("${all_latest_files[@]:0:30}")
all_latest_files=("${all_latest_files[@]:30}")
if [ -z "$latest_files[@]" ]; then
echo "No JSON files found."
break
fi
oldest_timestamp=""
for file in "${latest_files[@]}"; do
created_at=$(grep -Eo '"created_at": "[^"]+"' "$file" | cut -d'"' -f4)
timestamp=$(date -d "$(echo "$created_at" | sed 's/\(..\) \([a-zA-Z]\{3\}\) /\1 \2 /')" "+%s")
if [ -z "$oldest_timestamp" ] || [ "$timestamp" -lt "$oldest_timestamp" ]; then
oldest_timestamp="$timestamp"
fi
done
oldest_date=$(date -d "@$oldest_timestamp" "+%a %b %d %T %z %Y")
formatted_date=$(echo "$oldest_date" | awk '{
split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", months, " ");
for (i=1; i<=12; i++) {
if ($2 == months[i]) {
month_number = sprintf("%02d", i);
break;
}
}
print $6"-"month_number"-"$3"_⇡"
}')
new_dir="$formatted_date"
mkdir "$new_dir"
mv ${latest_files[@]} "$new_dir"
cp page_index.html "$new_dir"/index.html
cd "$new_dir"
ls *.json > listOfFiles.txt
sed -i -e 's/\.json//g' listOfFiles.txt
cd ..
for json_file in ${latest_files[@]}; do
json_base_name=$(basename "$json_file" .json)
for file in "$json_base_name"*; do
if [ -f "$file" ]; then
mv "$file" "$new_dir"
fi
done
done
echo "Files moved to directory: $new_dir"
((dir_counter++))
done
bash gen_index.sh