Skip to content

Commit

Permalink
2.4.0 SERPER example
Browse files Browse the repository at this point in the history
  • Loading branch information
palladius committed Sep 30, 2024
1 parent f776fcb commit cefaa66
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bin/gcloud-whoami
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ gcloud config list
yellow "3. Some stats:"
echo Projects: $(gcloud projects list |wc -l)
echo Orgs: $(gcloud organizations list |egrep -v DISPLAY_NAME | wc -l )

red "4. Evil actions. Lets look at credentials: TODO someday now im busy see comments"
# echo 'SELECT * from credentials;' |sqlite3 /usr/local/google/home/ricc/.config/gcloud/credentials.db
# find ~/.config/gcloud/ -name \*.json -print0 | xargs -0 fgrep _token
# TODO(ricc): check all info you get from the ADC.json of your current config
# and chck config in ADC: find ~/.config/gcloud/ -name \*.json
# particularly /usr/local/google/home/ricc/.config/gcloud/.last_update_check.json
25 changes: 25 additions & 0 deletions bin/serper-google-search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env ruby

require "uri"
require "json"
require "net/http"

SERPER_API_KEY = ENV.fetch('SERPER_API_KEY',nil)
$stderr.puts("Note: this API KEY has a monthly cap. Consider doing some caching and using sparingly.")
$stderr.puts("Tip: Try feeding STDOUT to `jq` for nicer output.")
raise "ENV[SERPER_API_KEY] not provided! Get one here://serper.dev/" unless SERPER_API_KEY

url = URI("https://google.serper.dev/search")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = SERPER_API_KEY
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"q": "Riccardo Carlesso"
})

response = https.request(request)
puts response.read_body

0 comments on commit cefaa66

Please sign in to comment.