ckreibich / scholar.py

A parser for Google Scholar, written in Python
2.11k stars 777 forks source link

Running scholar's main() function from another script #128

Open SvennoNito opened 4 years ago

SvennoNito commented 4 years ago

Hey everybody, I want to use the main()function from scholar.py in another script of mine. I saw a simmilar issue #50 but not a satisfying answer so far. Is it possible to call the script with optional input arguments in another script? It should be I guess. So far I've tried

import scholar

scholar.main(["-c", "1",
 "--author", "albert einstein",
 "--phrase", "quantum theory",
 "--citation", "bt",
 "--cookie-file", "~/.scholar-cookies.txt"
  ])

And I get the following error message: TypeError: main() takes 0 positional arguments but 1 was given

Makes sense, the main()function in scholar.py doesn't have any input argument. Maybe a super basic question, but any idea how to work around it?

SvennoNito commented 4 years ago

Not sure whether it is a clean solution, but what eventually worked for me was this

import scholar
import sys

sys.argv = ["-c", "1",
 "--author", "albert einstein",
 "--phrase", "quantum theory",
 "--citation", "bt",
 "--cookie-file", "~/.scholar-cookies.txt"
  ]

scholar.main()