Skip to content

Import from snippet‐box

dhop90 edited this page Dec 1, 2024 · 1 revision

Steps:

  1. Save snippet-box snippets to json file sqlite3 db.sqlite3 '.mode json' '.once snippet.json' 'select * from snippets'

  2. run convert_snippet_to_bytestash.sh script ##change username


# Check if input file exists
if [ ! -f "snippet.json" ]; then
  echo "Input file 'snippet.json' not found!"
  exit 1
fi

# Define the output file name
output_file="bytestash-export.json"

# Define the current timestamp in the format required for 'exported_at'
#exported_at=$(date --utc +"%Y-%m-%dT%H:%M:%S.000Z")
exported_at="2024-11-30 15:22:24Z"
username="USERNAME"
#
# Read the input snippet.json and transform it into the new format
jq --arg exported_at "$exported_at" --arg username "$username" '{
  "version": "1.0",
  "exported_at": $exported_at,
  "snippets": [
    .[] | {
      "id": .id,
      "title": .title,
      "description": .description ,  # Default to empty if description is missing
      "updated_at": .updatedAt,
      "user_id": 3,  # Assuming static user_id for now
      "is_public": 0,  # Assuming static value for public access
      "username": $username,  # Assuming static username for now
      "categories": [ .language ],  # Assuming no categories provided in snippet.json
      "share_count": 0,  # Assuming static share_count for now
      "fragments": [
        {
          "id": .id,
          "file_name": "main",
          "code": .code,
          "language": .language,
          "position": 0
        }
      ]
    }
  ]
}' snippet.json > "$output_file"

# Check if the conversion was successful
if [ $? -eq 0 ]; then
  echo "Conversion successful! Output written to '$output_file'."
else
  echo "An error occurred during conversion."
  exit 1
fi

  1. import into bytestash

This script does not grab tags from snippet-box

Clone this wiki locally