pqVars.py
Define variables for use in app
#! python3
# pqVars.py
# functions to import for pubQuery.py
## CONSTANTS
urls = {"Google": "https://www.google.com/search?q=site%3Ancbi.nlm.nih.gov+", "Google Scholar": "https://scholar.google.com/scholar?q=site:ncbi.nlm.nih.gov+", "DuckDuckGo": "https://duckduckgo.com", "Yahoo": "https://yahoo.com"}
## MUTABLE VARIABLES
searchEngine = 'Google'
## create file within jupyterNB to prevent "file not found" error
with open("pqVars.py","w") as fh:
fh.write("""
#! python3
# pqVars.py
# functions to import for pubQuery.py
## CONSTANTS
urls = {"Google": "https://www.google.com/search?q=site%3Ancbi.nlm.nih.gov+", "Google Scholar": "https://scholar.google.com/scholar?q=site:ncbi.nlm.nih.gov+", "DuckDuckGo": "https://duckduckgo.com", "Yahoo": "https://yahoo.com"}
## MUTABLE VARIABLES
searchEngine = 'Google'
""")
pqFunc.py
Define functions for use in app
#! python3
# pqFuncs.py
# functions to import for pubQuery.py
## FUNCTIONS
def change_search_engine():
validInp = False
while validInp == False:
site = input("Please choose your Search Engine: \n(1) Google \n(2) Google Scholar \n(3) DuckDuckGo \n(4) Yahoo \nWhich site would you like to search? ")
if site== "1" or site.upper() == "GOOGLE":
search_engine = "Google"
validInp = True
elif site == "2":
search_engine = "Google Scholar"
validInp = True
elif site == "3":
print("Option still under construction...please restart...")
elif site == "4":
print("Option still under construction...please restart...")
else:
print("Invalid entry...please restart...")
return search_engine
def update_var(filename, var_name, var):
#var_name = str(var)
i = 0
new_lines = []
with open(filename,"r") as fh:
lines = fh.readlines()
for line in lines:
i += 1
print("CURRENT LINE ({1}): {0}".format(line, i))
if var_name in line.strip():
print("Overwriting line {} in temporary storage...".format(i))
updated_line = "{} = '{}'".format(var_name,var)
new_lines.append(updated_line)
print("Line {1} is now: {0}".format(updated_line, i))
else:
new_lines.append(line)
with open(filename, "w") as fd:
fd.seek(0)
fd.truncate()
for l in new_lines:
fd.write(l)
Main run script
NOTE: import of pqVars and pqFuncs has been commented out for Jupyter purposes; uncomment for use as separate files or combine all variables and functions into pubQuery.py
#! python3
# pubQuery.py
# uses google (or search engine of choice) to search within pubmed instead of pubmed search bar
import webbrowser as w
#import random as r
#from pqVars import *
#from pqFuncs import *
"""
## TODO:
# add GUI input field using tkinter
# importing tkinter
from tkinter import *
from tkinter import ttk
from tkinter.messagebox import askyesno
# creating root
root = Tk()
# specifying geometry
root.geometry('200x100')
# This is used to take input from user
# and show it in Entry Widget.
# Whatever data that we get from keyboard
# will be treated as string.
input_text = StringVar()
entry1 = ttk.Entry(root, textvariable = input_text, justify = CENTER)
# focus_force is used to take focus
# as soon as application starts
entry1.focus_force()
entry1.pack(side = TOP, ipadx = 30, ipady = 6)
save = ttk.Button(root, text = 'Save', command = lambda : askyesno(
'Confirm', 'Do you want to save?'))
save.pack(side = TOP, pady = 10)
root.mainloop()
"""
"________________________________________"
"""
## TODO:
# open text/csv file
with open("file_name") as fhand:
# do something?
## TODO:
# gather url's of top x# of citations
# search for all permutations of
stPerm = r.combo(term) # ** find or write function
stPerm = combo(term)
print("Gathering citations for keyword combination: '{}'".format(stPerm))
## TODO:
# filter out duplicate url's
print("Checking for duplicates...")
## TODO:
# write to file
print("Saving results to file '{}'...".format(fhand)
## TODO >> finish fn
def combo(search_term):
words = search_term.split()
# mix order of words
newST = newOrder.join(" ")
return newST
## NEXT STEP: gather pdf's when possible
try:
except:
## NEXT STEP:
# Gather text of abstract along with formatted title and author citation
# create visual way to present abstracts with citations (1 page per citation/abstract? list of citations/abstracts?)
"""
print("_"*60)
print("Search engine is currently set to: {}\nTo change search engine, enter 'X' or just hit 'Enter'".format(searchEngine))
print("_"*60)
term = input("Search term: ")
if searchEngine == "":
seSelect = change_search_engine()
update_var("pqVars.py","searchEngine", seSelect)
elif term == "" or term.upper() == "X":
seSelect = change_search_engine()
update_var("pqVars.py","searchEngine", seSelect)
else:
w.open(urls[searchEngine]+term)