statuses2files.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. # convert statuses as files and dirs
  3. json="$(cat)"
  4. ids=$(echo "$json" | jj -l '#.id' | sed 's/"//g')
  5. notload_reblogs=$(jj -i "$main_basedir"/config.json notload_reblogs)
  6. mkdir -p "$main_basedir/all_statuses/$instance"
  7. mkdir -p "$main_basedir/statuses/$instance"
  8. mkdir -p "$main_basedir/timelines/$instance/$timeline"
  9. for i in $ids; do
  10. if [ -f "$main_basedir"/all_statuses/$instance/$i/$i.json ]; then
  11. ids=$(echo "$ids" | sed -E "s/.?$i.?//g")
  12. continue
  13. elif [ -n "$(unzip -p $main_basedir/archives/$instance.zip "**/$i.json")" ]; then
  14. ids=$(echo "$ids" | sed -E "s/.?$i.?//g")
  15. continue
  16. elif [ -d "$main_basedir"/all_statuses/$instance/$i ]; then
  17. ids=$(echo "$ids" | sed -E "s/.?$i.?//g")
  18. continue
  19. fi
  20. status_date=$(echo "$json" | jj "#[id=$1].created_at")
  21. reblog_id=$(echo "$json" | jj "#[id=$1].reblog.id")
  22. if [ "$notload_reblogs" = 'true' ] && [ -n "$reblog_id" ]; then
  23. ids=$(echo "$ids" | sed -E "s/.?$i.?//g")
  24. continue
  25. fi
  26. mkdir -m 711 -p "$main_basedir"/all_statuses/$instance/$i
  27. touch -d "$status_date" "$main_basedir"/all_statuses/$instance/$i
  28. echo "$json" | jj -p "#[id=$i]" > "$main_basedir"/all_statuses/$instance/$i/$i.json
  29. done
  30. export ids
  31. echo "$json" | "$main_basedir"/utils/extract_fields_statuses.sh