-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcannlypedia.py
More file actions
30 lines (25 loc) · 1.12 KB
/
cannlypedia.py
File metadata and controls
30 lines (25 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from rest_framework.decorators import api_view
from rest_framework.response import Response
@api_view(["GET"])
def scholars(request, format=None):
"""Get information about scholars."""
if request.method == "GET":
author = request.query_params.get("q", None)
if author:
from scholarly import scholarly
search_query = scholarly.search_author(author)
author_source = next(search_query)
author_data = {
"author": author,
"affiliation": author_source["affiliation"],
"cited_by": author_source["citedby"],
"email_domain": author_source["email_domain"],
"interests": author_source["interests"],
"photo_url": author_source["url_picture"],
}
return Response(author_data, content_type="application/json")
# Return an error if no author is specified.
error_message = (
"Author not found in request. Specify ?q={url_encoded_author_name}"
)
return Response({"error": error_message}, content_type="application/json")