Search the web from the terminal

Forum Forums General Tips and Tricks Search the web from the terminal

  • This topic has 5 replies, 4 voices, and was last updated Dec 22-9:49 pm by Brian Masinick.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #96050
    Member
    PPC

      I’ve dabbled into trying to do web searching from the terminal before. Now I tried it again, with more success:

      At least in the computer that I’m on, a package that allows the user to do web searches using duckduckgo is available in the repository: “ddgr”
      I installed it, but it fails to provide search results.

      So I went straight to the source, so to say: https://github.com/jarun/ddgr/releases

      Since I’m no antiX 19, 64bits, I downloaded and installed this deb: https://github.com/jarun/ddgr/releases/download/v1.9/ddgr_1.9-1_debian10.amd64.deb

      Once on the terminal, I like to do web searches and be able to run other commands, so I run the command like so:

      ddgr –np [term_I_want_to_search_on-line]

      Example:

      ddgr --np -n 20 portugal

      ( the “-n 20” is how many results I want to see. the default is 10)
      You can click the link and it will open in the default browser.

      Pretty nifty trick to perform a quick search, without needing to open the browser- it would be particularly handy, if it had a working 32bits version- since you know, most 64bits machines can run a browser that performs web searches… Anyway, it’s handy, if you want, for example, to search for something while working at the terminal.
      If the version that is in the repos worked, I would even consider making a yad script for searching and getting the results, without needing a browser- that would be a nice extra functionality to add to FT10 (it already offers a GUI to use translation services, get news, get weather forecasts, why not add also web searches to the mix?).

      P.

      • This topic was modified 4 months, 2 weeks ago by PPC.
      #96053
      Forum Admin
      anticapitalista
        Helpful
        Up
        0
        ::

        Nice find, however I get this on antiX-22

        ddgr --np -n 20 portugal
        [ERROR] HTTP Error 403: Forbidden
        No results.

        OK – found a fix.

        Here is a deb that should work on 32 and 64 bit.

        https://download.tuxfamily.org/antix/Testing/

        • This reply was modified 4 months, 2 weeks ago by anticapitalista. Reason: found fix

        Philosophers have interpreted the world in many ways; the point is to change it.

        antiX with runit - leaner and meaner.

        #96059
        Moderator
        Brian Masinick
          Helpful
          Up
          0
          ::

          ddgr –np -n 20 “South Carolina” shows stuff about South Carolina.

          ddgr –np -n 20 “Local News” shows local news in various areas. For me, the first abstract shows news abstracts from WYFF Channel 4, a local television station in Greenville, SC, about five miles from where I’m currently sitting. It also shows news stories from around the country, including Cincinnati, Ohio and Sacramento, California, to name two of the many others. I’m sure with creativity, you can find news abstracts from many different sources.

          ddgr –np -n 20 “antiX Linux” gives quite a few topics too; try it out!

          --
          Brian Masinick

          #96061
          Member
          PPC
            Helpful
            Up
            0
            ::

            Many thanks, anticapitalista: I tested this .deb in antiX 19, 64bits, and it works fine. When I can, I’ll test it in antiX 22, 32bits and report back – if all goes well, this will be a nice little app for antiX’s repo!

            I made a nice little GUI for this CLI app (clicking the links, opens them in the default browser).

            The code:

            #!/bin/bash
            # The script was created by PPC, for antiX Linux; GPL license, please keep this attribution
            # Script to perform web searches using DuckDuckGo and show the results in a yad window
            # Requirements: yad (comes by default in antiX Full) and ddgr
            
            #Get what the user wants que search on-line
            query=$(yad --title="Duckduckgo" --width=400 --window-icon=/usr/share/icons/numix-square-antix/48x48/apps/web-duckduckgo.png --center --image=/usr/share/icons/numix-square-antix/48x48/apps/web-duckduckgo.png  --entry --button="⌕")
            
            #If nothing was entered, exit the script
            [[ -z "$query" ]] && { echo "Search parameter is empty, exiting" ; exit 1; }
            
            #perform the search, using ddgr
            ddgr --np -n20 -x $query > /tmp/web-search0.txt
            
            #Split very big lines (but don't split very long words because they probably are web addresses)
            cat /tmp/web-search0.txt | fmt -100 > /tmp/web-search.txt
            
            #display text, with clickable links
            yad  --title="Duckduckgo"   --window-icon=/usr/share/icons/numix-square-antix/48x48/apps/web-duckduckgo.png --center --width=800  --height=650 --button="⌕":1 --text-info <  /tmp/web-search.txt --show-uri --fontname="ubuntu 12"
            
            #Listen for user selection:
            foo=$?
            
            #IF user clicked the "Search" button on the results window, restart script:
            if [[ $foo -eq 1 ]]; then
              #Get script name and path
              script_name1=$(basename $0)
              script_path1=$(dirname $(readlink -f $0))
              script_path_with_name="$script_path1/$script_name1"
              #restart current script
              eval "$script_path_with_name"
            fi
            

            Edit: I had to change the “script_name1″… line, near the end, because, as usual, the forum software mangled it- it should work perfectly now, as displayed above…
            Edit2: I created this script basicly for the same reason the most used OS in the world has a GUI, built right into the toolbar, to search for stuff (both in the file system and in the Web)- We already have a GUI to search for files (Searchmonkey) and now he have also web search, without needing a browser, without risking our privacy (using the CLI or the provided GUI).
            Not many people know that antiX comes with a GUI to perform websearches (the search bar) – this cli tool and a GUI like the one above, simply make performing web searches in DDG, without needing a browser something that can be integrated into antiX’s future, if so the Dev team wishes.

            Note: there are countless ways in which my script can be improved- the more relevant settings that should be added are the number of results (I think 20 is a nice number) and localization of the results – a new “Configuration” file for this GUI could be created, to store such info (and that could be edited in a simple yad GUI)

            • This reply was modified 4 months, 2 weeks ago by PPC.
            • This reply was modified 4 months, 2 weeks ago by Brian Masinick. Reason: Fixed two minor typos
            • This reply was modified 4 months, 2 weeks ago by Brian Masinick. Reason: Fixed two minor typos
            #96076
            Member
            blur13
              Helpful
              Up
              0
              ::

              Whats the use case for this?

              How is this better than opening a text based browser in the terminal and doing the search there

              ie links2 google.com

              type in search term.

              I’m sure there must be a good use case, I just cant figure it out.

              EDIT: I mean use case for ddgr, not PPCs script

              • This reply was modified 4 months, 2 weeks ago by blur13.
              #96079
              Moderator
              Brian Masinick
                Helpful
                Up
                0
                ::

                @blur13: I don’t know whether or not you are familiar with the News Feed readers that used to be commonplace (perhaps a decade ago now). ddgr still provides a similar aggregation service. Yes indeed, there are many other ways to accomplish this, but it’s a handy tool, slightly different, yet similar to those now deprecated aggregation services.

                So yes there are other ways to do this, but the advantage to this approach is that it’s very fast and convenient, uses modest resources like the best antiX tools, so for some people it can come in handy.

                --
                Brian Masinick

              Viewing 6 posts - 1 through 6 (of 6 total)
              • You must be logged in to reply to this topic.