mirror of
https://github.com/minoplhy/duckduckgo-images-api.git
synced 2025-04-19 22:56:57 +00:00
Compare commits
No commits in common. "main" and "v1.0.2" have entirely different histories.
71
.github/workflows/codeql-analysis.yml
vendored
71
.github/workflows/codeql-analysis.yml
vendored
@ -1,71 +0,0 @@
|
|||||||
# For most projects, this workflow file will not need changing; you simply need
|
|
||||||
# to commit it to your repository.
|
|
||||||
#
|
|
||||||
# You may wish to alter this file to override the set of languages analyzed,
|
|
||||||
# or to provide custom queries or build logic.
|
|
||||||
#
|
|
||||||
# ******** NOTE ********
|
|
||||||
# We have attempted to detect the languages in your repository. Please check
|
|
||||||
# the `language` matrix defined below to confirm you have the correct set of
|
|
||||||
# supported CodeQL languages.
|
|
||||||
#
|
|
||||||
name: "CodeQL"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ main ]
|
|
||||||
pull_request:
|
|
||||||
# The branches below must be a subset of the branches above
|
|
||||||
branches: [ main ]
|
|
||||||
schedule:
|
|
||||||
- cron: '38 15 * * 3'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
analyze:
|
|
||||||
name: Analyze
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
language: [ 'go' ]
|
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
|
||||||
# Learn more:
|
|
||||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v1
|
|
||||||
with:
|
|
||||||
languages: ${{ matrix.language }}
|
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
||||||
# By default, queries listed here will override any specified in a config file.
|
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
|
||||||
- name: Autobuild
|
|
||||||
uses: github/codeql-action/autobuild@v1
|
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
|
||||||
# 📚 https://git.io/JvXDl
|
|
||||||
|
|
||||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
||||||
# and modify them (or add more) to build your code if your project
|
|
||||||
# uses a compiled language
|
|
||||||
|
|
||||||
#- run: |
|
|
||||||
# make bootstrap
|
|
||||||
# make release
|
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v1
|
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2022 Minoplhy
|
Copyright (c) 2021 Minoplhy
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
10
README.md
10
README.md
@ -1,6 +1,6 @@
|
|||||||
# DuckDuckGo-images-api
|
# DuckDuckGo-image-api
|
||||||
|
|
||||||
This project is Go adaptation of Python3 forked [duckduckgo-images-api](https://github.com/joeyism/duckduckgo-images-api) . I made this modules because this module will be need in my future project .
|
This project is Go adaptation of Python3 forked [duckduckgo-image-api](https://github.com/joeyism/duckduckgo-images-api) . I made this modules because this module will be need in my future project .
|
||||||
|
|
||||||
Contribution are always welcome
|
Contribution are always welcome
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ Import
|
|||||||
# Example Use Cases
|
# Example Use Cases
|
||||||
|
|
||||||
#### Get Search Results
|
#### Get Search Results
|
||||||
```go
|
```
|
||||||
func main() {
|
func main() {
|
||||||
hunsen := goduckgo.Search(goduckgo.Query{Keyword: "duck"})
|
hunsen := goduckgo.Search(goduckgo.Query{Keyword: "duck"})
|
||||||
fmt.Print(hunsen.Results)
|
fmt.Print(hunsen.Results)
|
||||||
@ -19,7 +19,7 @@ func main() {
|
|||||||
|
|
||||||
```
|
```
|
||||||
#### Get Search Result Image
|
#### Get Search Result Image
|
||||||
```go
|
```
|
||||||
func main() {
|
func main() {
|
||||||
hunsen := goduckgo.Search(goduckgo.Query{Keyword: "duck"})
|
hunsen := goduckgo.Search(goduckgo.Query{Keyword: "duck"})
|
||||||
for _, somtam := range hunsen.Results {
|
for _, somtam := range hunsen.Results {
|
||||||
@ -30,7 +30,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
#### Specific P and S
|
#### Specific P and S
|
||||||
```go
|
```
|
||||||
func main() {
|
func main() {
|
||||||
hunsen := goduckgo.Search(goduckgo.Query{Keyword: "duck", P: "1", S: "200"})
|
hunsen := goduckgo.Search(goduckgo.Query{Keyword: "duck", P: "1", S: "200"})
|
||||||
fmt.Print(hunsen.Results)
|
fmt.Print(hunsen.Results)
|
||||||
|
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
|||||||
module github.com/minoplhy/duckduckgo-images-api
|
module github.com/minoplhy/duckduckgo-image-api
|
||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
38
goduckgo.go
38
goduckgo.go
@ -64,19 +64,24 @@ func Search(keyword Query) Gogo {
|
|||||||
|
|
||||||
requrl := url + "?q=" + keyword.Keyword
|
requrl := url + "?q=" + keyword.Keyword
|
||||||
req, err := http.NewRequest(http.MethodGet, requrl, nil)
|
req, err := http.NewRequest(http.MethodGet, requrl, nil)
|
||||||
log_err(err)
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0")
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0")
|
||||||
|
|
||||||
res, err := netreq.Do(req)
|
res, err := netreq.Do(req)
|
||||||
log_err(err)
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if res.Body != nil {
|
if res.Body != nil {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
body, readErr := ioutil.ReadAll(res.Body)
|
body, readErr := ioutil.ReadAll(res.Body)
|
||||||
log_err(readErr)
|
if readErr != nil {
|
||||||
|
log.Fatal(readErr)
|
||||||
|
}
|
||||||
|
|
||||||
hunsen := regexfind(regex_r{Regex: `vqd=([\d-]+)\&`, Body: string(body)})
|
hunsen := regexfind(regex_r{Regex: `vqd=([\d-]+)\&`, Body: string(body)})
|
||||||
|
|
||||||
@ -100,18 +105,23 @@ func Search(keyword Query) Gogo {
|
|||||||
resq.Header.Add("sec-fetch-mode", "cors")
|
resq.Header.Add("sec-fetch-mode", "cors")
|
||||||
resq.Header.Add("referer", "https://duckduckgo.com/")
|
resq.Header.Add("referer", "https://duckduckgo.com/")
|
||||||
resq.Header.Add("accept-language", "en-US,enq=0.9")
|
resq.Header.Add("accept-language", "en-US,enq=0.9")
|
||||||
log_err(err)
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
resqs, getErr := netreq.Do(resq)
|
resqs, getErr := netreq.Do(resq)
|
||||||
log_err(getErr)
|
if getErr != nil {
|
||||||
|
log.Fatal(getErr)
|
||||||
|
}
|
||||||
|
|
||||||
brudy, readErr := ioutil.ReadAll(resqs.Body)
|
brudy, readErr := ioutil.ReadAll(resqs.Body)
|
||||||
log_err(readErr)
|
if readErr != nil {
|
||||||
|
log.Fatal(readErr)
|
||||||
|
}
|
||||||
duckduck := Gogo{}
|
duckduck := Gogo{}
|
||||||
jsonErr := json.Unmarshal(brudy, &duckduck)
|
jsonErr := json.Unmarshal(brudy, &duckduck)
|
||||||
log_err(jsonErr)
|
if jsonErr != nil {
|
||||||
|
log.Fatal(jsonErr)
|
||||||
|
}
|
||||||
log.Println("\nHitting Url Success : " + requrl)
|
log.Println("\nHitting Url Success : " + requrl)
|
||||||
return duckduck
|
return duckduck
|
||||||
}
|
}
|
||||||
@ -121,9 +131,3 @@ func regexfind(hitin regex_r) string {
|
|||||||
hunsen := gexgex.FindString(string(hitin.Body))
|
hunsen := gexgex.FindString(string(hitin.Body))
|
||||||
return hunsen
|
return hunsen
|
||||||
}
|
}
|
||||||
|
|
||||||
func log_err(err error) {
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user