#!/usr/bin/bash # # pocket2csv # # Copyright (c) 2020 Christopher Crawford. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. Neither the name of the copyright holder nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # read -r -d '' LOGO <<'EOF' ... _ _ ___ | | | | |__ \ _ __ ___ ___ | | __ ___ | |_ ) | ___ ___ __ __ | '_ \ / _ \ / __|| |/ // _ \| __| / / / __|/ __|\ \ / / | |_) || (_) || (__ | <| __/| |_ / /_| (__ \__ \ \ V / | .__/ \___/ \___||_|\_\\___| \__||____|\___||___/ \_/ | | |_| ... EOF echo "" echo "$LOGO" echo "" echo "" read -p '[1] Enter Your Pocket API Consumer Key: ' CONSUMER_KEY read -r -d '' MY_DATA <] Creating intermediate file bookmarks-tmp.json..." jq '.list | .[]' bookmarks.json \ | jq ' if .tags == null then .tags = {} else .tags = .tags end ' \ | jq '.favorite = (.favorite | tonumber)' \ | jq '.has_video = (.has_video | tonumber)' \ | jq '.has_image = (.has_image | tonumber)' \ | jq '.word_count = (.word_count | tonumber)' \ | jq '.time_added = (.time_added | tonumber | todate)' \ | jq '.year_added = (.time_added | split("T") | .[0] | split("-") | .[0] | tonumber)' \ | jq '.month_added = (.time_added | split("T") | .[0] | split("-") | .[1] | tonumber)' \ | jq '.day_added = (.time_added | split("T") | .[0] | split("-") | .[2] | tonumber)' \ | jq '.hour_added = (.time_added | split("T") | .[1] | split(":") | .[0] | tonumber)' \ | jq '.tags = (.tags | keys)' \ | jq '.ntags = (.tags | length)' \ | jq '.tags = (.tags | join(" AND "))' \ | jq '.given_domain = (.given_url | split ("/") | .[2])' \ | jq '.n_given_domain = (.given_url | split (".") | length)' \ | jq '.resolved_domain = (.resolved_url | split ("/") | .[2])' \ | jq '.n_resolved_domain = (.resolved_url | split (".") | length)' \ | jq '.n_domain_equal = (.n_given_domain == .n_resolved_domain)' \ | jq '.given_tld1 = (.given_domain | tostring | split(".") | .[length-1])' \ | jq '.given_tld2 = (.given_domain | tostring | split(".") | .[length-2])' \ | jq '.resolved_tld1 = (.resolved_domain | tostring | split(".") | .[length-1])' \ | jq '.resolved_tld2 = (.resolved_domain | tostring |split(".") | .[length-2])' \ | jq '.titles_match = (.given_title == .resolved_title)' \ | jq '.urls_match = (.given_url == .resolved_url)' \ | jq '.domains_match = (.given_domain == .resolved_domain)' \ | jq '.excerpt = (.excerpt | gsub("[\\n\\t]"; ""))' \ | jq '.given_title = (.given_title | gsub("[\\n\\t]"; ""))' \ | jq '{ time_added: .time_added, year_added: .year_added, month_added: .month_added, day_added: .day_added, hour_added: .hour_added, favorite: .favorite, has_video: .has_video, has_image: .has_image, word_count: .word_count, n_given_domain: .n_given_domain, n_resolved_domain: .n_resolved_domain, n_domain_equal: .n_domain_equal, ntags: .ntags, tags: .tags, titles_match: .titles_match, domains_match: .domains_match, urls_match: .urls_match, given_title: .given_title, given_domain: .given_domain, given_tld1: .given_tld1, given_tld2: .given_tld2, given_url: .given_url, resolved_title: .resolved_title, resolved_domain: .resolved_domain, resolved_tld1: .resolved_tld1, resolved_tld2: .resolved_tld2, resolved_url: .resolved_url, excerpt: .excerpt}' > bookmarks-tmp.json jq -r -s '.[0] | keys_unsorted | @csv' < bookmarks-tmp.json > bookmarks.csv echo " [>] Writing to bookmarks.csv..." jq 'map(.)' bookmarks-tmp.json \ | jq -r '@csv' >> bookmarks.csv echo "[+] Done."