Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SvennoNito opened this issue Jan 19, 2020 · 1 comment
Open

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

SvennoNito opened this issue Jan 19, 2020 · 1 comment

Comments

@SvennoNito
Copy link

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
Copy link
Author

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant