Skip to content

Instantly share code, notes, and snippets.

@ilyes-d
Last active June 2, 2022 15:09
Show Gist options
  • Save ilyes-d/15fe81ef217115ace5579f55305b3b39 to your computer and use it in GitHub Desktop.
Save ilyes-d/15fe81ef217115ace5579f55305b3b39 to your computer and use it in GitHub Desktop.
from .models import Researcher
from django.shortcuts import render
from serpapi import GoogleSearch
def get_researchers_citations(request, author_gs_url):
context = {}
author_gs_id = author_gs_url.partition('user=')[2][:12] # this to get only the id part from the given url
params = {
"engine": "google_scholar_author",
"author_id": author_gs_id,
"api_key": "<your-api-key>"
}
search = GoogleSearch(params)
results = search.get_dict()
if 'author' in results : # this check if the id is valid
author_citations = results["cited_by"]["table"][0]["citations"]["all"]
context["author_name"] = results["author"]["name"]
context["author_citations"] = author_citations
else:
context["error"] = "the author id not valid"
return render(request , 'template.html' , context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment