Sha256: 8c62634cae951774953c78313a75c15b4d2013a0267ed413381dd5cbc5cdb91a

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

#!/usr/bin/env ruby
# DuckGo is a RubyGem library and command line tool for searching with DuckDuckGo.
# By default, it puts out only the relevant information, but when told, it will dump
# all the data you could ask for. This tool aims to give access to most of the
# features from the official API.
# Daniel Ethridge

require "duckgo"
include DuckGo
require "duckgo/version"

# If there are no arguments...
if ARGV.length == 0
  puts "Hmm..."
  exit
end

help = """DuckGo lets you search duckduckgo.com for instant answers

duckgo something searchable         :  Auto-handle the search
duckgo [--help | -h]                :  Display this help
duckgo [--version | -V]             :  Display version
duckgo [--favicon | -f] google.com  :  Get google's favicon
duckgo \\!gem duckgo                 :  Use !bang syntax to search a specific site

If you do not see an answer, please shorten the search string.
e.g. 'something with tons of extra information' => 'something'
This is an aspect of DuckGo I can control, because the official API does not
allow a full search. More information - https://duckduckgo.com/api

View docs and API on https://github.com/wlib/duckgo
Made by Daniel Ethridge | git.io/de
"""

# Argument "parser" if you want to call it that
case ARGV[0]
  when "--help", "-h"
    puts help
    exit
  when "--version", "-V"
    puts "DuckGo v#{VERSION}"
    exit
  when "--favicon", "-f"
    site = ARGV[1]
    file = File.open("#{site}-favicon.ico", "w")
    favicon = get_favicon(site)
    file.write(favicon)
    puts "Queried favicon from #{site}."
    file.close
    exit
  when "--infobox", "-i"
    data = get_data(ARGV[1..-1].join(" "))
    extras_data = find_extras(data)
    if extras_data["Infobox"]
      puts extract_infobox(data).to_yaml
      exit
    else
      puts "No infobox retrieved, try more clear search keywords or remove 'the --infobox|-i flag'"
      exit
    end
  else
    handle(ARGV[0..-1].join(" "))
    exit
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duckgo-1.2.1 bin/duckgo