Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created April 19, 2020 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/ce6030dd9f0404f9aa2ba7c26844da0a to your computer and use it in GitHub Desktop.
Save kyanny/ce6030dd9f0404f9aa2ba7c26844da0a to your computer and use it in GitHub Desktop.
require 'net/http'
require 'uri'
require 'json'
def usage
puts <<USAGE
Usage:
$ ruby #{$0} <consumer_key> <access_token>
USAGE
end
consumer_key, access_token = ARGV[0..1]
unless consumer_key && access_token
usage
exit!
end
# get all tags
uri = URI.parse('https://getpocket.com/v3/get')
params = {
'consumer_key' => consumer_key,
'access_token' => access_token,
'state' => 'all',
'contentType' => 'article',
'detailType' => 'complete',
}
res = Net::HTTP.post_form(uri, params)
if res.code != '200'
puts res.body
exit!
end
tags = []
data = JSON.parse(res.body)
puts data['list'].keys.size
data['list'].each do |item_id, item|
next if item['tags'].nil?
tags << item['tags'].keys
end
pp tags.flatten.uniq.sort
# delete all tags
tags.flatten.uniq.sort.each do |tag|
p tag
uri = URI.parse('https://getpocket.com/v3/send')
params = {
'consumer_key' => consumer_key,
'access_token' => access_token,
'actions' => [
{
'action' => 'tag_delete',
'tag' => tag,
}
].to_json
}
res = Net::HTTP.post_form(uri, params)
puts res.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment