mirror of
https://github.com/minoplhy/duckduckgo-images-api.git
synced 2025-04-10 11:17:58 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
64457ac31d | |||
2cc2b811ed | |||
8bc2c1808d | |||
d8f1f37a29 | |||
fbc797bedb | |||
a2268a0b07 | |||
91097f137d |
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
71
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# 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) 2021 Minoplhy
|
Copyright (c) 2022 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
|
||||||
|
12
README.md
12
README.md
@ -1,6 +1,6 @@
|
|||||||
# DuckDuckGo-image-api
|
# DuckDuckGo-images-api
|
||||||
|
|
||||||
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 .
|
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 .
|
||||||
|
|
||||||
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,10 +30,10 @@ 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-image-api
|
module github.com/minoplhy/duckduckgo-images-api
|
||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
38
goduckgo.go
38
goduckgo.go
@ -64,24 +64,19 @@ 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)
|
||||||
if err != nil {
|
log_err(err)
|
||||||
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)
|
||||||
if err != nil {
|
log_err(err)
|
||||||
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)
|
||||||
if readErr != nil {
|
log_err(readErr)
|
||||||
log.Fatal(readErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
hunsen := regexfind(regex_r{Regex: `vqd=([\d-]+)\&`, Body: string(body)})
|
hunsen := regexfind(regex_r{Regex: `vqd=([\d-]+)\&`, Body: string(body)})
|
||||||
|
|
||||||
@ -105,23 +100,18 @@ 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")
|
||||||
if err != nil {
|
log_err(err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
resqs, getErr := netreq.Do(resq)
|
resqs, getErr := netreq.Do(resq)
|
||||||
if getErr != nil {
|
log_err(getErr)
|
||||||
log.Fatal(getErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
brudy, readErr := ioutil.ReadAll(resqs.Body)
|
brudy, readErr := ioutil.ReadAll(resqs.Body)
|
||||||
if readErr != nil {
|
log_err(readErr)
|
||||||
log.Fatal(readErr)
|
|
||||||
}
|
|
||||||
duckduck := Gogo{}
|
duckduck := Gogo{}
|
||||||
jsonErr := json.Unmarshal(brudy, &duckduck)
|
jsonErr := json.Unmarshal(brudy, &duckduck)
|
||||||
if jsonErr != nil {
|
log_err(jsonErr)
|
||||||
log.Fatal(jsonErr)
|
|
||||||
}
|
|
||||||
log.Println("\nHitting Url Success : " + requrl)
|
log.Println("\nHitting Url Success : " + requrl)
|
||||||
return duckduck
|
return duckduck
|
||||||
}
|
}
|
||||||
@ -131,3 +121,9 @@ 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