Last active
February 13, 2024 19:10
-
-
Save jivanpal/116032ab6329fa5eaef88c9e9f46f2a3 to your computer and use it in GitHub Desktop.
Revisions
-
jivanpal revised this gist
Feb 13, 2024 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,6 +19,11 @@ cd undated for j in *.json; do unix_timestamp="$(jq -r .photoTakenTime.timestamp "$j")" if [ $? -ne 0 ] ; then >&2 echo "Timestamp not found in $j" continue fi date="$(date -d "@$unix_timestamp" +%Y/%m/%d)" basename="$(echo "$j" | grep -Eo '^[^\.]*')" destination="../dated/$date" -
jivanpal revised this gist
Feb 13, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ cd undated for j in *.json; do unix_timestamp="$(jq -r .photoTakenTime.timestamp "$j")" date="$(date -d "@$unix_timestamp" +%Y/%m/%d)" basename="$(echo "$j" | grep -Eo '^[^\.]*')" destination="../dated/$date" mkdir -p -- "$destination" -
jivanpal revised this gist
Jul 15, 2023 . 1 changed file with 5 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,19 +18,11 @@ IFS=$'\n' cd undated for j in *.json; do unix_timestamp="$(jq -r .photoTakenTime.timestamp "$j")" date="$(date -d "@$unix_timestamp" +%Y/%m/%d)" basename="$(echo "$j" | grep -Eo -- '^[^\.]*')" destination="../dated/$date" mkdir -p -- "$destination" mv -- "$basename"* "$destination/" done -
jivanpal created this gist
Jun 9, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ #!/bin/bash ## Works with the Google Takeout format from 2020 and earlier, in which ## items are already within directories of the form "YYYY-MM-DD", and you ## want a directory hierarchy of the form "YYYY/MM/DD". ## ## You must run this script from the directory which contains all the ## directories of the form "YYYY-MM-DD". The resulting directories of the ## form "YYYY/MM/DD" will be created in this same location. trap '>&2 echo Interrupted. && exit 1' SIGINT if [ "$1" = "-n" ] || [ "$1" = "--dry-run" ]; then maybe_echo='echo' else maybe_echo='' fi for dir in ????-??-??*/ ; do year="$( echo "$dir" | grep -Po '^[0-9]{4}' )" month="$( echo "$dir" | grep -Po '(?<=^[0-9]{4}-)[0-9]{2}' )" rest="$( echo "$dir" | grep -Po '(?<=^[0-9]{4}-[0-9]{2}-).*(?=/$)' )" $maybe_echo mkdir -p "$year/$month" $maybe_echo mv "$dir" "$year/$month/$rest" done This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ #!/bin/bash ## Works with the Google Takeout format from 2021 and later, in which ## items are all in a single directory (no timestamp necessarily in file ## or directory names), but JSON files contain Unix timestamps, and you ## want a directory hierarchy of the form "YYYY/MM/DD". ## ## You must start with all items in a folder called `undated`, and run this ## script from its parent. A folder called `dated` will then be created with ## the "YYYY/MM/DD" hierarchy within it. This will leave all files which we ## cannot sort in the `undated` directory for you to sort yourself. trap '>&2 echo Interrupted. && exit 1' SIGINT OLDIFS=$IFS IFS=$'\n' cd undated for j in *.json; do unix_timestamp="$( \ (grep -EA1 photoTakenTime "$j" || >&2 echo "No photoTakenTime in $j") \ | (grep -E timestamp || >&2 echo "No timestamp in $j") \ | sed -E 's/ +/ /g' | sed -E 's/(^ | $)//g' \ | cut -d' ' -f2 \ | (grep -E '^\"[0-9]*\",$' || >&2 echo "Timestamp not in expected format in $j") \ | sed -E 's/^\"([0-9]*)\",$/\1/' \ )" date="$(date -d "@$unix_timestamp" +%Y/%m/%d)" basename="$(echo "$j" | grep -Eo '^[^\.]*')" destination="../dated/$date" mkdir -p "$destination" mv "$basename".* "$destination/" done