Code Monkey home page Code Monkey logo

googler's Introduction

googler

Travis build status Lifecycle: experimental AppVeyor build status

This is a wrapper around the ‘googler’ command line tool.

Requirements

Python 3 must be installed and locatable

Installation

You can install the development version of {googler} from Github with:

remotes::install_github("mkearney/googler")

Examples

Search google with various options to specify things like the desired result count, google news, within a range of time, from a given site, etc.

Example #1: Basic google search

## search google for 'rstats'
googler("rstats")
#> # A tibble: 10 x 4
#>    abstract                        matches    title            url                        
#>    <chr>                           <list>     <chr>            <chr>                      
#>  1 "5h ago @akesslerdc tweeted: \… <df[,2] [… News about #rst… https://twitter.com/hashta…
#>  2 The latest Tweets from Rstats … <df[,2] [… Rstats (@rstats… https://twitter.com/rstats…
#>  3 The R Project for Statistical … <NULL>     The R Project f… https://www.r-project.org/ 
#>  4 Read writing about Rstats in T… <df[,2] [… Rstats – Toward… https://towardsdatascience…
#>  5 Right now I'm building a GLM f… <NULL>     Rstats - Reddit  https://www.reddit.com/r/r…
#>  6 This function is used to calcu… <NULL>     rstats function… https://www.rdocumentation…
#>  7 Jun 24, 2019 ... GitHub is whe… <NULL>     rstats · GitHub… https://github.com/topics/…
#>  8 Read writing about Rstats in l… <df[,2] [… Rstats – learn … https://blog.exploratory.i…
#>  9 Jul 24, 2019 ... Welcome to RS… <df[,2] [… RStats Institut… https://www.missouristate.…
#> 10 Today I pushed a preliminary v… <NULL>     Rstats - Once U… https://www.onceupondata.c…

Example #2: Advanced google search

## search google for 100 'rstats' or "R language" hits in English in past year
googler("rstats OR \"R language\"", count = 100, time = "y1", lang = "en")
#> # A tibble: 97 x 5
#>    abstract                   matches   title               url                   metadata
#>    <chr>                      <list>    <chr>               <chr>                 <chr>   
#>  1 "5h ago @akesslerdc tweet… <df[,2] … News about #rstats… https://twitter.com/… <NA>    
#>  2 Right now I'm building a … <NULL>    Rstats - Reddit     https://www.reddit.c… <NA>    
#>  3 This past year in R has b… <NULL>    My 2018 #rstats ye… https://leonawicz.gi… <NA>    
#>  4 GitHub is where people bu… <NULL>    rstats · GitHub To… https://github.com/t… <NA>    
#>  5 Welcome to RStats Institu… <df[,2] … RStats Institute -… https://www.missouri… <NA>    
#>  6 RStats Glossary. Find def… <df[,2] … Stats Tools - RSta… https://www.missouri… <NA>    
#>  7 Dec 13, 2018 - 77 min - U… <df[,2] … R Programming for … https://www.youtube.… <NA>    
#>  8 Why the R Language? R is … <df[,2] … Why use the R Lang… https://www.burns-st… <NA>    
#>  9 "The view_df() function f… <NULL>    Quickly create Cod… https://www.r-blogge… <NA>    
#> 10 Basically, this book is a… <df[,2] … A Complete Guide t… https://towardsdatas… <NA>    
#> # … with 87 more rows

Example #3: Search google news

## search google news for rstats/R language articles in the past three weeks
googler("rstats OR \"R language\"", news = TRUE)
#> # A tibble: 10 x 5
#>    abstract                matches   metadata       title             url                 
#>    <chr>                   <list>    <chr>          <chr>             <chr>               
#>  1 Quartz: How would you … <df[,2] … Quartz, Aug 1… What's next for … https://qz.com/1661…
#>  2 ... R package develope… <df[,2] … Yahoo Finance… R Consortium Com… https://finance.yah…
#>  3 'Brittany Runs a Marat… <NULL>    The Boston Gl… Jillian Bell lac… https://www.bostong…
#>  4 “A broad range of orga… <df[,2] … Datanami, Aug… Is Python Strang… https://www.datanam…
#>  5 ... data visualization… <df[,2] … Neowin, Aug 3… This 2019 Certif… https://www.neowin.…
#>  6 28 R (language) — Gary… <df[,2] … Valdosta Dail… Capsule reviews … https://www.valdost…
#>  7 The R language offers … <df[,2] … Toolbox (blog… Google's AI Plat… https://it.toolbox.…
#>  8 Her favorites are Data… <df[,2] … Quartz, Nov 1… What's the best … https://qz.com/1464…
#>  9 Big-data company Datab… <NULL>    SiliconANGLE … Databricks' MLfl… https://siliconangl…
#> 10 The R language was ori… <df[,2] … IT Jungle, Ap… R Comes To i      https://www.itjungl…

googler's People

Contributors

mkearney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

saso008 g-thomson

googler's Issues

python is detected but googler() sees otherwise

Reprex below.

Sys.setenv("RETICULATE_PYTHON" = "C:\\Users\\leungi\\AppData\\Local\\Continuum\\anaconda3\\python.exe")
reticulate::py_config()
#> python:         C:\Users\leungi\AppData\Local\Continuum\anaconda3\python.exe
#> libpython:      C:/Users/leungi/AppData/Local/Continuum/anaconda3/python37.dll
#> pythonhome:     C:\Users\leungi\AppData\Local\CONTIN~1\ANACON~1
#> version:        3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
#> Architecture:   64bit
#> numpy:          C:\Users\leungi\AppData\Local\CONTIN~1\ANACON~1\lib\site-packages\numpy
#> numpy_version:  1.16.4
#> 
#> NOTE: Python version was forced by RETICULATE_PYTHON

library(googler)
googler("rstats")
#> Warning in file.remove("NUL"): cannot remove file 'NUL', reason 'Permission
#> denied'
#> Error in windows_python(): object 'path' not found

# inspecting issue
googler:::windows_python()
#> Warning in file.remove("NUL"): cannot remove file 'NUL', reason 'Permission
#> denied'
#> Error in googler:::windows_python(): object 'path' not found

# checking windows_python()
windows_python <- function(x) {
  if (!grepl("python", googler:::sys_which("python"))) {
    stop("'googler' requires python, which does not appear to be installed.")
  }
  path
}

# checking sys_which()
x <- "python"

if (googler:::is_unix()) {
  return(Sys.which(x))
}
sys_win <- function(x) {
  suppressWarnings({
    path <- tryCatch(
      system(sprintf("where %s", x), intern = TRUE)[1],
      error = function(e) NA_character_
    )
  })
  if (file.exists("NUL")) {
    file.remove("NUL")
  }
  if (!is.na(path)) {
    return(`names<-`(path, x))
  }
  Sys.which(x)
}
vapply(x, sys_win, character(1))
#> Warning in file.remove("NUL"): cannot remove file 'NUL', reason 'Permission
#> denied'
#>                                                                python 
#> "C:\\Users\\leungi\\AppData\\Local\\Continuum\\anaconda3\\python.exe"

## python is detected, but yet path from sys_which() is NULL

path
#> Error in eval(expr, envir, enclos): object 'path' not found

Created on 2019-08-31 by the reprex package (v0.2.1)

Doesn't work

I don't understand why it doesn't work for me...

> googler("rstats", count = 2, lang = "en")
# A tibble: 0 x 0
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_France.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] googler_0.0.1

loaded via a namespace (and not attached):
 [1] compiler_3.6.2  tools_3.6.2     pillar_1.4.3    rstudioapi_0.10 tibble_2.1.3    crayon_1.3.4    fansi_0.4.1     jsonlite_1.6.1 
 [9] pkgconfig_2.0.3 rlang_0.4.2  

googler() with default arguments fails, but otherwise works

Reprex below.

I tried looking at source code, but can't find where the default arguments are set.

Sys.setenv("RETICULATE_PYTHON" = "C:\\Users\\leungi\\AppData\\Local\\Continuum\\anaconda3\\python.exe")
reticulate::py_config()
#> python:         C:\Users\leungi\AppData\Local\Continuum\anaconda3\python.exe
#> libpython:      C:/Users/leungi/AppData/Local/Continuum/anaconda3/python37.dll
#> pythonhome:     C:\Users\leungi\AppData\Local\CONTIN~1\ANACON~1
#> version:        3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
#> Architecture:   64bit
#> numpy:          C:\Users\leungi\AppData\Local\CONTIN~1\ANACON~1\lib\site-packages\numpy
#> numpy_version:  1.16.4
#> 
#> NOTE: Python version was forced by RETICULATE_PYTHON

library(googler)

## works
googler("rstats", count = 2, lang = "en")
#> # A tibble: 2 x 4
#>   abstract                      matches    title           url             
#>   <chr>                         <list>     <chr>           <chr>           
#> 1 "5h ago @akesslerdc tweeted:~ <df[,2] [~ News about #rs~ https://twitter~
#> 2 The R Project for Statistica~ <NULL>     The R Project ~ https://www.r-p~

## works
googler("rstats", count = 2)
#> # A tibble: 2 x 4
#>   abstract                       matches    title         url              
#>   <chr>                          <list>     <chr>         <chr>            
#> 1 "5h ago @akesslerdc tweeted: ~ <df[,2] [~ News about #~ https://twitter.~
#> 2 Read writing about Rstats in ~ <df[,2] [~ Rstats – Tow~ https://towardsd~

## fails
googler("rstats")
#> Warning in system2(cmd, args = args, stdout = TRUE): running command
#> '"C:\Users\leungi\AppData\Local\Continuum\anaconda3\python.exe" C:
#> \Users\leungi\AppData\Local\Temp\RtmpEVevEU/googler "rstats" -C --json' had
#> status 1
#> Error: lexical error: invalid char in json text.
#>                                        NA
#>                      (right here) ------^

Created on 2019-09-01 by the reprex package (v0.2.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.