-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-public-archive.sh
More file actions
337 lines (287 loc) Β· 9.71 KB
/
create-public-archive.sh
File metadata and controls
337 lines (287 loc) Β· 9.71 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/bin/bash
# Create a safe public Twitter archive
# This script creates a minimal archive with only public tweets
set -e
echo "π¦ Twitter archive public release generator"
echo "==========================================="
echo ""
# Check if we're in the right directory
if [ ! -f "index.html" ] || [ ! -d "data" ]; then
echo "β Error: Please run this script from your Twitter archive folder"
echo " (the folder containing index.html and data/ directory)"
exit 1
fi
# Create output directory
PUBLIC_DIR="public-twitter-archive"
if [ -d "$PUBLIC_DIR" ]; then
echo "π Public archive folder already exists"
read -p " Do you want to overwrite it? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo " Cancelled."
exit 1
fi
rm -rf "$PUBLIC_DIR"
fi
echo "π¦ Creating public archive in: $PUBLIC_DIR"
mkdir -p "$PUBLIC_DIR/data"
# Copy the viewer
echo "π Copying index.html..."
if [ ! -f "$PUBLIC_DIR/index.html" ] || [ "index.html" -nt "$PUBLIC_DIR/index.html" ]; then
cp index.html "$PUBLIC_DIR/"
echo " β index.html copied"
else
echo " βοΈ index.html already up to date"
fi
# Copy tweets data
echo ""
echo "π Copying tweet data..."
if [ -f "data/tweets.js" ]; then
if [ ! -f "$PUBLIC_DIR/data/tweets.js" ] || [ "data/tweets.js" -nt "$PUBLIC_DIR/data/tweets.js" ]; then
cp "data/tweets.js" "$PUBLIC_DIR/data/"
echo " β tweets.js copied"
else
echo " βοΈ tweets.js already up to date"
fi
fi
# Copy tweet parts if they exist
tweet_parts_found=0
for file in data/tweets-part*.js; do
if [ -f "$file" ]; then
tweet_parts_found=$((tweet_parts_found + 1))
filename=$(basename "$file")
if [ ! -f "$PUBLIC_DIR/data/$filename" ] || [ "$file" -nt "$PUBLIC_DIR/data/$filename" ]; then
cp "$file" "$PUBLIC_DIR/data/"
echo " β $filename copied"
else
echo " βοΈ $filename already up to date"
fi
fi
done
if [ $tweet_parts_found -eq 0 ] && [ ! -f "data/tweets.js" ]; then
echo " β οΈ No tweet data files found!"
fi
# Copy public profile data (removing email from account.js)
echo ""
echo "π€ Processing profile data..."
if [ -f "data/account.js" ]; then
echo " π Creating safe account.js (removing email)..."
# Create account.js without email
sed 's/"email" : "[^"]*",//' "data/account.js" > "$PUBLIC_DIR/data/account.js"
echo " β account.js copied (email removed)"
fi
if [ -f "data/profile.js" ]; then
if [ ! -f "$PUBLIC_DIR/data/profile.js" ] || [ "data/profile.js" -nt "$PUBLIC_DIR/data/profile.js" ]; then
cp "data/profile.js" "$PUBLIC_DIR/data/"
echo " β profile.js copied"
else
echo " βοΈ profile.js already up to date"
fi
fi
# Copy public follower/following data
if [ -f "data/follower.js" ]; then
if [ ! -f "$PUBLIC_DIR/data/follower.js" ] || [ "data/follower.js" -nt "$PUBLIC_DIR/data/follower.js" ]; then
cp "data/follower.js" "$PUBLIC_DIR/data/"
echo " β follower.js copied"
else
echo " βοΈ follower.js already up to date"
fi
fi
if [ -f "data/following.js" ]; then
if [ ! -f "$PUBLIC_DIR/data/following.js" ] || [ "data/following.js" -nt "$PUBLIC_DIR/data/following.js" ]; then
cp "data/following.js" "$PUBLIC_DIR/data/"
echo " β following.js copied"
else
echo " βοΈ following.js already up to date"
fi
fi
# Copy public likes data
if [ -f "data/like.js" ]; then
if [ ! -f "$PUBLIC_DIR/data/like.js" ] || [ "data/like.js" -nt "$PUBLIC_DIR/data/like.js" ]; then
cp "data/like.js" "$PUBLIC_DIR/data/"
echo " β like.js copied"
else
echo " βοΈ like.js already up to date"
fi
fi
# Copy essential media and assets
echo ""
echo "π¬ Copying media and assets..."
# Function to show progress bar
show_progress() {
local current=$1
local total=$2
local width=50
local percentage=$((current * 100 / total))
local completed=$((current * width / total))
printf "\r ["
for ((i=0; i<completed; i++)); do printf "#"; done
for ((i=completed; i<width; i++)); do printf "-"; done
printf "] %d%% (%d/%d)" "$percentage" "$current" "$total"
}
# Function to copy with progress
copy_with_progress() {
local source=$1
local dest=$2
local desc=$3
local total_files=$(find "$source" -type f | wc -l)
echo " $desc"
# Use pv if available for better progress, otherwise use basic progress
if command -v pv >/dev/null 2>&1; then
echo " π Copying with pv..."
tar -cf - -C "$source" . | pv -n -s $(du -sb "$source" | cut -f1) | tar -xf - -C "$dest"
elif command -v rsync >/dev/null 2>&1; then
# Simple rsync with file counting progress
mkdir -p "$dest"
echo " π Copying $total_files files..."
# Start rsync in background
rsync -ah "$source/" "$dest/" &
local rsync_pid=$!
# Monitor progress by counting files
local last_count=0
while kill -0 $rsync_pid 2>/dev/null; do
sleep 0.5
local current_files=$(find "$dest" -type f 2>/dev/null | wc -l)
if [ "$current_files" -ne "$last_count" ] && [ "$total_files" -gt 0 ]; then
local percentage=$((current_files * 100 / total_files))
if [ "$percentage" -gt 100 ]; then percentage=100; fi
local filled=$((percentage / 2))
local empty=$((50 - filled))
printf "\r ["
printf '%*s' "$filled" '' | tr ' ' '#'
printf '%*s' "$empty" '' | tr ' ' '-'
printf "] %d%% (%d/%d)" "$percentage" "$current_files" "$total_files"
last_count=$current_files
fi
done
wait $rsync_pid
else
# Fallback: Use cp with spinning indicator
echo " π Copying $total_files files..."
cp -r "$source" "$dest" &
local cp_pid=$!
local spin='-\|/'
local i=0
while kill -0 $cp_pid 2>/dev/null; do
i=$(( (i+1) %4 ))
printf "\r ${spin:$i:1} Copying files... (%d files total)" "$total_files"
sleep 0.5
done
wait $cp_pid
fi
printf "\r [$(printf '%50s' | tr ' ' 'β')] 100%% (%d files copied)" "$total_files"
echo ""
}
if [ -d "data/tweets_media" ]; then
if [ ! -d "$PUBLIC_DIR/data/tweets_media" ]; then
media_count=$(find "data/tweets_media" -type f | wc -l)
echo " πΈ Copying tweets media ($media_count files, this may take a while)..."
if [ "$media_count" -gt 100 ]; then
# Use rsync with progress for large archives
copy_with_progress "data/tweets_media" "$PUBLIC_DIR/data/tweets_media"
else
# Simple copy for small archives
cp -r "data/tweets_media" "$PUBLIC_DIR/data/"
printf "\r [$(printf '%50s' | tr ' ' '#')] 100%%"
echo ""
fi
echo " β $media_count media files copied"
else
echo " βοΈ tweets_media already exists (skipping for speed)"
echo " π‘ Delete $PUBLIC_DIR/data/tweets_media to force refresh"
fi
else
echo " βΉοΈ No tweets_media folder found"
fi
if [ -d "data/profile_media" ]; then
if [ ! -d "$PUBLIC_DIR/data/profile_media" ]; then
profile_count=$(find "data/profile_media" -type f | wc -l)
echo " π€ Copying profile media ($profile_count files)..."
cp -r "data/profile_media" "$PUBLIC_DIR/data/"
printf "\r [$(printf '%50s' | tr ' ' '#')] 100%%"
echo ""
echo " β Profile media copied"
else
echo " βοΈ profile_media already exists"
fi
else
echo " βΉοΈ No profile_media folder found"
fi
if [ -d "assets" ]; then
if [ ! -d "$PUBLIC_DIR/assets" ]; then
echo " π¨ Copying assets..."
cp -r "assets" "$PUBLIC_DIR/"
printf "\r [$(printf '%50s' | tr ' ' '#')] 100%%"
echo ""
echo " β Assets copied"
else
echo " βοΈ assets already exists"
fi
else
echo " βΉοΈ No assets folder found"
fi
# Create a README for the public archive
cat > "$PUBLIC_DIR/README.md" << 'EOF'
# Public Twitter Archive
This is a public-safe version of a Twitter archive, containing only public tweets.
## What's included
- Public tweets only
- Media files from public tweets
- Profile images
- Assets folder (CSS, JS, icons)
## What's NOT included
- Email addresses or personal information
- Direct messages
- Following/follower lists
- Liked tweets
- Any private or sensitive data
## Usage
Open `index.html` in your web browser to view the archive.
## Privacy
This archive has been cleaned of sensitive personal information and is safe for public sharing.
EOF
# Create gitignore for the public version
cat > "$PUBLIC_DIR/.gitignore" << 'EOF'
# This is a public-safe archive
# Only tweet data should be here
# Just in case - ignore any accidentally added sensitive files
account.js
direct-messages*.js
follower.js
following.js
like.js
personalization.js
**/node_modules/
.DS_Store
EOF
echo ""
echo "β
Public archive created successfully!"
echo ""
echo "π Your public archive is ready in: $PUBLIC_DIR"
echo ""
echo "π What was included:"
if [ -f "$PUBLIC_DIR/data/tweets.js" ]; then
tweet_count=$(grep -o '"tweet"' "$PUBLIC_DIR/data/tweets.js" | wc -l || echo "unknown")
echo " β’ $tweet_count tweets (approximately)"
fi
for file in "$PUBLIC_DIR"/data/tweets-part*.js; do
if [ -f "$file" ]; then
part_count=$(grep -o '"tweet"' "$file" | wc -l || echo "unknown")
echo " β’ $(basename "$file"): $part_count tweets (approximately)"
fi
done
if [ -d "$PUBLIC_DIR/data/tweets_media" ]; then
media_count=$(find "$PUBLIC_DIR/data/tweets_media" -type f | wc -l)
echo " β’ $media_count media files"
fi
if [ -d "$PUBLIC_DIR/assets" ]; then
echo " β’ Assets folder (viewer dependencies)"
fi
echo ""
echo "π Next steps:"
echo " 1. Test the archive by opening $PUBLIC_DIR/index.html in your browser"
echo " 2. Review your tweets to ensure you're comfortable sharing them"
echo " 3. Upload the $PUBLIC_DIR folder to your hosting platform"
echo ""
echo "β οΈ IMPORTANT: Only share the contents of $PUBLIC_DIR - never your original archive!"
echo ""