-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TiDurak
committed
May 27, 2022
1 parent
56b4680
commit d9d887b
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# Google-Search-Parser | ||
Simple google search parser, based on https://rapidapi.com/apigeek/api/google-search3 api | ||
|
||
# Setup | ||
- Sign up on https://rapidapi.com/ website | ||
- Subscribe to https://rapidapi.com/apigeek/api/google-search3/ api (Don't worry, it's free) | ||
- Insert api key from https://rapidapi.com/ to `config.json` | ||
- Run `main.py` file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
import requests | ||
from rich import print | ||
|
||
from classes import exceptions | ||
|
||
class SearchEngine(): | ||
def __init__(self, user_request, API_KEY): | ||
self.__user_request = user_request | ||
self.__user_request = self.__user_request.replace(" ", "+") | ||
self.__url = f"https://google-search3.p.rapidapi.com/api/v1/search/q={self.__user_request}" | ||
self.__headers = { | ||
"X-User-Agent": "desktop", | ||
"X-Proxy-Location": "EU", | ||
"X-RapidAPI-Host": "google-search3.p.rapidapi.com", | ||
"X-RapidAPI-Key": API_KEY | ||
} | ||
self.__response = requests.request("GET", self.__url, headers=self.__headers) | ||
self.__json_data = json.loads(self.__response.text).get("results") | ||
|
||
|
||
def parse(self): | ||
if self.__json_data is None: | ||
raise(exceptions.MissingApiKey("\n\nYou are don't have API_KEY! Please, get it in https://rapidapi.com/, and subscribe to https://rapidapi.com/apigeek/api/google-search3/ api!")) | ||
else: | ||
for result in self.__json_data: | ||
print(f"[b blue]{result.get('title')}\n" | ||
f"[purple]{result.get('link')}\n" | ||
f"[green]{result.get('description')}\n\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class MissingApiKey(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"api_key": "INSERT API KEY HERE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from classes import engine | ||
import json | ||
|
||
if __name__ == '__main__': | ||
with open('config.json') as f: | ||
data = json.load(f) | ||
api_key = data.get('api_key') | ||
|
||
search = engine.SearchEngine(input("Search request: "), api_key) | ||
search.parse() |