Skip to content

Instantly share code, notes, and snippets.

View ilyes-d's full-sized avatar

ilyes AEK ilyes-d

View GitHub Profile
@ilyes-d
ilyes-d / views.py
Created June 3, 2022 23:54
functions
from django.shortcuts import render
from serpapi import GoogleSearch
from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.getenv("api_key")
def index(request):
return render(request,'index.html')
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('accounts.urls')), # New
]
@ilyes-d
ilyes-d / urls.py
Last active June 3, 2022 23:51
app urls
from django.urls import path
from .views import *
urlpatterns = [
path('', index ),
path('profile/', get_author_profile , name='author-profile'),
]
<form action="/profile/" method="get">
<label for="author_url">author url</label>
<input name='author_url' type="text">
</form>
<ul>
<li> author name : {{name}}</li>
<li>author citations : {{total_citations}}</li>
</ul>
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
...
...
'google_scholar_serpapi', # New
from django.contrib import admin
admin.site.register(Researcher)
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,
@ilyes-d
ilyes-d / models.py
Last active June 2, 2022 14:47
simple researcher model
from django.db import models
# simple researcher model
class Researcher(models.Model):
first_name = models.CharField(max_length=150, default='')
last_name = models.CharField(max_length=150, default='')
email = models.EmailField(_('email adress'), unique=True)
citations = models.IntegerField(default=0, blank=True)