-
-
Save fmartingr/88a258bfad47fb00a3ef9d6c38e5699e to your computer and use it in GitHub Desktop.
script to import pocket entries into shiori with text, images etc. instead of plain bookmarks.
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 characters
#!/bin/sh | |
# Extracting URLs from the exported HTML from getpocket.com/export | |
# In the following line $1 is the exported HTML from pocket | |
# which will be passed to this script as a CLI parameter | |
grep -Eoi '<a [^>]+>' $1 | grep -Eo 'href="[^\"]+"' | cut -d'=' -f 2- | tr -d '"' | tac > pocket2shiori.txt | |
# Reading the URLs one by one and adding to shiori | |
while IFS= read -r line; do | |
shiori add $line | |
done < pocket2shiori.txt | |
rm pocket2shiori.txt | |
exit 0 |
Pocket exports are now a CSV file, so inspired by the above I came up with a working solution using csvkit to prepare the data:
#!/bin/bash
# Extract URL, title and tags from getpocket.com/export CSV export
# and pass to shiori for import ($1 is the CSV file)
# Requires csvkit
# Use csvkit to reorder the columns to something more convenient
csvcut -c "url,tags,title" $1 > pocket2shiori.csv
# Remove the header row so it's not processed by the while loop
sed -i '1d' pocket2shiori.csv
# Track errors
fail=0
# Now we can use cut
while IFS= read -r line; do
# Extract the relevant fields
link=$(echo "$line" | cut -d ',' -f1)
tags=$(echo "$line" | cut -d ',' -f2)
title=$(echo "$line" | cut -d ',' -f3-)
# Remove any quotes around the title, since they will be added at the import step anyway
title="${title%\"}"
title="${title#\"}"
# Convert tags to comma-separated since the Pocket export uses | instead
tags=${tags//|/,}
if [ -n "$tags" ]; then
if [ "$link" == "$title" ]; then
shiori add "$link" -t "$tags"
ec=$?
else
shiori add "$link" -t "$tags" -i "$title"
ec=$?
fi
else
if [ "$link" == "$title" ]; then
shiori add "$link"
ec=$?
else
shiori add "$link" -i "$title"
ec=$?
fi
fi
# Check if the import was successful
if [ $ec -ne 0 ]; then
fail=1
echo "Failed to import $link"
echo "$link" >> pocket2shiori.failed
fi
done < pocket2shiori.csv
if [ $fail -eq 0 ]; then
rm pocket2shiori.csv
fi
exit $fail
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a little slower, but I have used it to add tags from the export as well.