Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
Page opens in the browser after every search.
added new function text() to adjust repetition.
  • Loading branch information
Siddhesh-Agarwal authored Jun 8, 2021
1 parent a3e9877 commit 45f70a3
Showing 1 changed file with 39 additions and 69 deletions.
108 changes: 39 additions & 69 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,29 @@ def google_search(search_term, api_key, cse_id, **kwargs):

results = google_search(searchterm, my_api_key, my_cse_id, num=10, start=nextPage)

def text(input_str, page=page):
return f"""<!DOCTYPE html>
<html>
<title>blogSearch | Search Results</title>
<link rel='shortcut icon' href='b.ico'>
<link rel = 'stylesheet' href = 'style.css'>
<link href='https://fonts.googleapis.com/css2?family=Prompt:wght@300&display=swap' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css2?family=Righteous&display=swap' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css2?family=Cuprum&display=swap' rel='stylesheet'>
<link href="https://fonts.googleapis.com/css2?family=PT+Serif&display=swap" rel="stylesheet">
<img src='blogSearch-logo.png' alt='blogSearch logo' align='middle'>
<br>
<pageno>You're on Page {page} of 10</pageno>\n")
<br>
<br>
<searchresult>Your search results for "{input_str}" are:</searchresult>
<br>
<br>"""

with open('myOutFile.html', 'w') as f:
f.write('')
f.write("<html>\n")
f.write("<title>blogSearch | Search Results</title>\n")
f.write("<link rel='shortcut icon' href='b.ico'>\n")
f.write("<link rel = 'stylesheet' href = 'style.css'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Prompt:wght@300&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Righteous&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Cuprum&display=swap' rel='stylesheet'>\n")
f.write('<link href="https://fonts.googleapis.com/css2?family=PT+Serif&display=swap" rel="stylesheet">\n')
f.write("<img src='blogSearch-logo.png' alt='blogSearch logo' align='middle'>\n")
f.write("<br>\n")
f.write("<pageno>You're on Page " + str(page) + " of 10</pageno>\n")
f.write("<br>\n")
f.write("<br>\n")
f.write("<searchresult>Your search results for '" + searchinput + "' are:</searchresult>\n")
f.write("<br>\n")
f.write("<br>\n")
f.write(text(searchinput))
webbrowser.open_new_tab('myOutFile.html')

for result in results:
omitSocials = ['instagram', 'twitter', 'facebook', 'amazon', 'linkedin', 'youtube', 'vimeo', 'google', 'pinterest']
Expand Down Expand Up @@ -73,8 +76,10 @@ def google_search(search_term, api_key, cse_id, **kwargs):
f.write("<br>\n")
f.write("<description>Description: " + result.get('snippet') + "</description>")
f.write("</p>\n")

#with open("myOutFile.html", "w") as outF:
#outF.write(for_title + result.get('title'))

else: pass

with open('myOutFile.html', 'a') as f:
Expand All @@ -97,34 +102,16 @@ def check_if_digit(input_str):
global nextPage
page = int(input_str)
nextPage = (page - 1) * 10 + 1
results = google_search(
searchterm, my_api_key, my_cse_id, num = 10, start = nextPage)
results = google_search(searchterm, my_api_key, my_cse_id, num = 10, start = nextPage)
with open('myOutFile.html', 'w') as f:
f.write('')
f.write("<html>\n")
f.write("<title>blogSearch | Search Results</title>\n")
f.write("<link rel='shortcut icon' href='b.ico'>\n")
f.write("<link rel = 'stylesheet' href = 'style.css'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Prompt:wght@300&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Righteous&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Cuprum&display=swap' rel='stylesheet'>\n")
f.write('<link href="https://fonts.googleapis.com/css2?family=PT+Serif&display=swap" rel="stylesheet">\n')
f.write("<img src='blogSearch-logo.png' alt='blogSearch logo' align='middle'>\n")
f.write("<br>\n")
f.write("<pageno>You're on Page " + str(page) + " of 10</pageno>\n")
f.write("<br>\n")
f.write("<br>\n")
f.write("<searchresult>Your search results for '" + searchinput + "' are:</searchresult>\n")
f.write("<br>\n")
f.write("<br>\n")
f.write(text(searchinput))
webbrowser.open_new_tab('myOutFile.html')

for result in results:
omitSocials = ['instagram', 'twitter', 'facebook', 'amazon', 'linkedin', 'youtube', 'vimeo', 'google', 'pinterest']
blog_str = ['blog']
#omitSocials = ['https://www.instagra', 'https://twitt', 'https://www.faceboo', 'https://www.pinterest',
#'https://business.faceboo', 'https://www.amazon', 'https://m.faceboo', 'https://vimeo',
#'https://www.youtu', 'https://play.google', 'https://support.goog']
#omitSocials = ['https://www.instagra', 'https://twitt', 'https://www.faceboo', 'https://www.pinterest',
#'https://business.faceboo', 'https://www.amazon', 'https://m.faceboo', 'https://vimeo',
#'https://www.youtu', 'https://play.google', 'https://support.goog']
urls = str(result.get('link'))
#snippo = result.get('snippet')
#For getting only socials: if any(social in urls for social in omitSocials):
Expand All @@ -144,8 +131,10 @@ def check_if_digit(input_str):
f.write("<br>\n")
f.write("<description>Description: " + result.get('snippet') + "</description>" + '\n\n')
f.write("</p>\n")

#with open("myOutFile.html", "w") as outF:
#outF.write(for_title + result.get('title'))

else: pass

with open('myOutFile.html', 'a') as f:
Expand All @@ -156,32 +145,16 @@ def check_if_digit(input_str):
input_str = input("Enter a search term: ")
searchterm = input_str + " blog"
results = google_search(searchterm, my_api_key, my_cse_id, num=10, start=nextPage)

with open('myOutFile.html', 'w') as f:
f.write('')
f.write("<html>\n")
f.write("<title>blogSearch | Search Results</title>\n")
f.write("<link rel='shortcut icon' href='b.ico'>\n")
f.write("<link rel = 'stylesheet' href = 'style.css'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Prompt:wght@300&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Indie+Flower&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Righteous&display=swap' rel='stylesheet'>\n")
f.write("<link href='https://fonts.googleapis.com/css2?family=Cuprum&display=swap' rel='stylesheet'>\n")
f.write('<link href="https://fonts.googleapis.com/css2?family=PT+Serif&display=swap" rel="stylesheet">\n')
f.write("<img src='blogSearch-logo.png' alt='blogSearch logo' align='middle'>\n")
f.write("<br>\n")
f.write("<pageno>You're on Page " + str(page) + " of 10</pageno>\n")
f.write("<br>\n")
f.write("<br>\n")
f.write("<searchresult>Your search results for '" + input_str + "' are:</searchresult>\n")
f.write("<br>\n")
f.write("<br>\n")
f.write(text(input_str))
webbrowser.open_new_tab('myOutFile.html')

for result in results:
omitSocials = ['instagram', 'twitter', 'facebook', 'amazon', 'linkedin', 'youtube', 'vimeo', 'google', 'pinterest']
blog_str = ['blog']
#omitSocials = ['https://www.instagra', 'https://twitt', 'https://www.faceboo', 'https://www.pinterest',
#'https://business.faceboo', 'https://www.amazon', 'https://m.faceboo', 'https://vimeo',
#'https://www.youtu', 'https://play.google', 'https://support.goog']
#omitSocials = ['https://www.instagra', 'https://twitt', 'https://www.faceboo', 'https://www.pinterest',
#'https://business.faceboo', 'https://www.amazon', 'https://m.faceboo', 'https://vimeo',
#'https://www.youtu', 'https://play.google', 'https://support.goog']
urls = str(result.get('link'))
#snippo = result.get('snippet')
#For getting only socials: if any(social in urls for social in omitSocials):
Expand All @@ -201,6 +174,7 @@ def check_if_digit(input_str):
f.write("<br>\n")
f.write("<description>Description: " + result.get('snippet') + "</description>" + '\n\n')
f.write("</p>\n")

#with open("myOutFile.html", "w") as outF:
#outF.write(for_title + result.get('title'))
else: pass
Expand All @@ -209,11 +183,7 @@ def check_if_digit(input_str):
f.write("</body>\n")
f.write("</html>\n")

else:
print("Thank you for using our service!")

else: print("Thank you for using our service!")

input_str = input("Type 's' to search again or 'p' to go to a different page or 'e' to end the session: ")
check_if_digit(input_str)

webbrowser.open_new_tab('myOutFile.html')

0 comments on commit 45f70a3

Please sign in to comment.