forked from tokee/juxta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_instagram.sh
executable file
·117 lines (96 loc) · 3.47 KB
/
demo_instagram.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
#
# Takes a csv from digfemig
# - Extracts the post urls from the csv
# - Generates a collage using the images with links back to the posts
#
# The format of the instagram.csv is: file_name,username,post_url,caption
#
# Requirements:
# - digfemig (pip install digfemig)
# - csvcut (pip install csvkit)
#
###############################################################################
# CONFIG
###############################################################################
pushd ${BASH_SOURCE%/*} > /dev/null
: ${IMAGE_BUCKET_SIZE:=20000}
: ${MAX_IMAGES:=99999999999}
: ${THREADS:=3}
: ${TIMEOUT:=60}
: ${TEMPLATE:="$(pwd)/demo_instagram.template.html"}
: ${DOWNLOAD_CACHE:=""} # Will default to collagename_downloads
: ${BACKGROUND:="000000"}
: ${RAW_W:=2}
: ${RAW_H:=2}
: ${ALLOW_UPSCALE:=true}
: ${JUXTA_HOME:="$(pwd)"}
popd > /dev/null
export JUXTA_HOME
################################################################################
# FUNCTIONS
################################################################################
usage() {
echo "./demo_instagram.sh instagram.csv path-to-images [collage_name]"
exit "$1"
}
parse_arguments() {
INSTAGRAM_CSV="$1"
IMAGES_PATH="$2"
COLLAGE_NAME="$3"
if [[ -z "$INSTAGRAM_CSV" || ! -f "$INSTAGRAM_CSV" || ! -r "$INSTAGRAM_CSV" ]]; then
>&2 echo "Error: No valid CSV file found at '$INSTAGRAM_CSV'"
usage 1
fi
if [[ ! -d "$IMAGES_PATH" ]]; then
>&2 echo "Error: '$IMAGES_PATH' is not a valid directory"
usage 1
fi
if [[ "." == ".$COLLAGE_NAME" ]]; then
COLLAGE_NAME=$(basename "$INSTAGRAM_CSV")
COLLAGE_NAME="${COLLAGE_NAME%.*}"
COLLAGE_NAME="instagram_${COLLAGE_NAME}"
echo "No collage name specified, using $COLLAGE_NAME"
fi
if [[ "." == .$(which csvcut) ]]; then
>&2 echo "Error: csvcut not available. Install with 'pip install csvkit'"
exit 9
fi
: ${DOWNLOAD:="${COLLAGE_NAME}_downloads"}
}
prepare_juxta_input() {
if [[ -z "$INSTAGRAM_CSV" || ! -f "$INSTAGRAM_CSV" || ! -r "$INSTAGRAM_CSV" ]]; then
>&2 echo "Error: No valid CSV file found at '$INSTAGRAM_CSV'"
return 1
fi
if [[ ! -d "$IMAGES_PATH" ]]; then
>&2 echo "Error: Image path '$IMAGES_PATH' does not exist or is not a directory"
return 1
fi
OUTPUT_FILE="$COLLAGE_NAME/juxta_instagram_images.dat"
> "$OUTPUT_FILE"
csvcut -c 1,3 "$INSTAGRAM_CSV" | tail -n +2 | while IFS=, read -r file_name post_url; do
if [[ "$file_name" =~ \.jpg$ ]]; then
if [[ "$file_name" =~ -([0-9]{14})- ]]; then
raw_timestamp="${BASH_REMATCH[1]}"
formatted_timestamp=$(date -d "${raw_timestamp:0:8} ${raw_timestamp:8:2}:${raw_timestamp:10:2}:${raw_timestamp:12:2}" "+%Y-%m-%d %H:%M:%S")
echo "$IMAGES_PATH/$file_name|$post_url $formatted_timestamp" >> "$OUTPUT_FILE"
else
>&2 echo "Warning: Could not extract timestamp from filename '$file_name'"
fi
else
>&2 echo "Skipping non-JPG file: $file_name"
fi
done
}
###############################################################################
# CODE
###############################################################################
parse_arguments "$@"
mkdir $COLLAGE_NAME
prepare_juxta_input
export TEMPLATE
export RAW_W
export RAW_H
export THREADS
INCLUDE_ORIGIN=false . ${JUXTA_HOME}/juxta.sh "$COLLAGE_NAME/juxta_instagram_images.dat" "$COLLAGE_NAME"