-
Notifications
You must be signed in to change notification settings - Fork 72
/
wsSearchApi.ahk
112 lines (97 loc) · 3.26 KB
/
wsSearchApi.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
; Title: wsSearch(api) - Contextual Web Search
; Link: https://www.autohotkey.com/boards/viewtopic.php?f=10&t=88660
; Author: Bobo
; Date: 27.03.2021
; for: AHK_L
/*
*/
; https://rapidapi.com/user/contextualwebsearch
; https://rapidapi.com/contextualwebsearch/api/web-search : Quota 100/day, 5/sec
; https://rapidapi.com/contextualwebsearch/api/keyword-analysis : Quota 100/day
;
#SingleInstance, Force
MsgBox % wsAutoComplete("butterfinger") ; Suggest as-you-type completion.
MsgBox % wsImage("Taylor Swift") ; Get relevant images for a given query.
MsgBox % wsNews("Boris Johnson") ; Get news articles relevant for a given query.
MsgBox % wsSpell("Cranberry") ; Check spelling.
MsgBox % wsSearch("Ursula von der Leyen") ; Get relevant web pages for a given query.
MsgBox % wsQuerySites("Taylor Swift") ; Get the popular sites for a given search query.
MsgBox % wsQueryKeywords("cyberia game review") ; Get the main keywords for a given search query.
MsgBox % wsQuerySimilar("John Wick 3") ; Get similar queries for a given search query.
wsQuerySimilar(text) {
url := "api/query/SimilarQueries?q=" . text
Return URLDownloadToVar(url,A_ThisFunc)
}
wsQueryKeywords(text) {
url := "api/query/QueryKeywords?q=" . text
Return URLDownloadToVar(url,A_ThisFunc)
}
wsQuerySites(text) {
url := "api/query/PopularDomainsForQuery?q=" . text
Return URLDownloadToVar(url,A_ThisFunc)
}
wsAutoComplete(text) {
url := "api/spelling/AutoComplete?text=" . text
Return URLDownloadToVar(url,A_ThisFunc)
}
wsImage(query:="test",pNumber:=1,pSize:=50,ac:="false",ss="false") {
url := "api/Search/ImageSearchAPI?q="
. query ; string
. "&pageNumber="
. pNumber ; number
. "&pageSize="
. pSize ; number (maximum 50)
. "&autoCorrect="
. ac ; boolean
. "&safeSearch="
. ss ; boolean
Return URLDownloadToVar(url,A_ThisFunc)
}
wsNews(query:="test",pNumber:=1,pSize:=50,ac:="false",ss="false") {
url := "api/search/NewsSearchAPI?q="
. query
. "&pageNumber="
. pNumber
. "&pageSize="
. pSize
. "&autoCorrect="
. ac
. "&fromPublishedDate=null"
. "&toPublishedDate=null"
. "&safeSearch="
. ss
Return URLDownloadToVar(url,A_ThisFunc)
}
wsSpell(text) {
url := "api/spelling/SpellCheck?text=" . text
Return URLDownloadToVar(url,A_ThisFunc)
}
wsSearch(query:="test",pNumber:=1,pSize:=50,ac:="false",ss="false") {
url := "api/Search/WebSearchAPI?q="
. query
. "&pageNumber="
. pNumber
. "&pageSize="
. pSize
. "&autoCorrect="
. ac
. "&safeSearch="
. ss
Return URLDownloadToVar(url,A_ThisFunc)
}
URLDownloadToVar(url,func) {
myAPIKey := <your API key here> !!!
if func in wsQuerySimilar,wsQueryKeywords,wsQuerySites
host:="keyword-analysis.p.rapidapi.com", url:="https://" . host . "/" . url
else
host:="contextualwebsearch-websearch-v1.p.rapidapi.com", url:="https://" . host . "/" . url
url := StrReplace(url,A_Space,"%20")
req := ComObjCreate("Msxml2.XMLHTTP")
req.open("GET", url, False)
req.setRequestHeader("x-rapidapi-key", myAPIKey)
req.setRequestHeader("x-rapidapi-host", host)
req.setRequestHeader("Content-Type","application/json; charset=utf-8")
req.setRequestHeader("useQueryString","true")
req.Send(data)
Return req.responseText
}