<repo_name>DipeshYogi/api_jobseeker<file_sep>/jobseeker_api/api/views.py
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
import psycopg2
from api.serializers import recomm_serializer
from rest_framework import status
from rest_framework.renderers import JSONRenderer

import pandas as pd
import numpy as np
from sklearn.metrics.pairwise import linear_kernel,cosine_similarity
from sklearn.feature_extraction.text import CountVectorizer


try:
    conn = psycopg2.connect(   user='lvdbzgnnnthckg',
                                    password= '<PASSWORD>',
                                    host = 'ec2-184-72-237-95.compute-1.amazonaws.com',
                                    port = '5432',
                                    database = 'd32b9rckhe5166',

                                    )

    cursor = conn.cursor()
    print ('Connected')


except (Exception, psycopg2.Error) as error:
                    print ("error while connecting to postgres")


class GetConn(APIView):

    def get(self,request):
        cursor.execute('Select * from portal_jobs where owner_id=1')
        rec = cursor.fetchall()
        cursor.execute('select username from auth_user where id=1')
        usr_name = cursor.fetchone()

        return Response ({'user':usr_name,'Jobs posted':rec})

class GetRecomm(APIView):
    """Get recommendation for a Profile"""
    serializer_class = recomm_serializer
    renderer_classes = [JSONRenderer]

    def get(self,request):
        n1 = self.serializer_class(data=request.data)
        if n1.is_valid():
            n1 = n1.validated_data.get('n1')

            cursor.execute('select p_skills, s_skills, img, exp from  users_profile where user_id = %s', (n1,))
            rec = cursor.fetchall()

            rec = pd.DataFrame(rec, columns=['p_skills','s_skills','img','exp'])
            rec['id'] = n1


            cursor.execute('select id, title, req_skills, exp from portal_jobs where owner_id <> %s', (n1,))
            jobs = cursor.fetchall()
            jobs = pd.DataFrame(jobs, columns=['id', 'title', 'req_skills', 'exp'])

            users_dta = rec['p_skills']+ ' '+rec['s_skills']
            jobs_dta = jobs['title']+ ' '+jobs['req_skills']

            jobid = jobs['id']

            data1 = pd.concat([users_dta, jobs_dta]).reset_index(drop=True)
            count = CountVectorizer(stop_words='english', ngram_range=(1, 2))
            count = CountVectorizer(stop_words='english', ngram_range=(1, 2))
            mat = count.fit_transform(data1)
            score = linear_kernel(mat,mat)
            req_score = score[0]
            req1_score = list(enumerate(req_score))
            req1_score = req1_score[1:]
            req1_score = pd.DataFrame(req1_score,columns=['index','score'])
            req1_score['JobId'] = jobid
            req1_score = req1_score.sort_values(by='score', ascending=False)
            req1_score = req1_score[req1_score['score']>=1]['JobId']
            req1_score = tuple(req1_score)
            #print(req1_score)

            cursor.execute('select * from portal_jobs where id in %s',(req1_score,))
            recomm_jobs = cursor.fetchall()

            cursor.execute('select username from auth_user where id = %s', (n1,))
            name = cursor.fetchall()

            return Response(recomm_jobs)
        else:
            return Response(n1.errors, status = status.HTTP_400_BAD_REQUEST)
<file_sep>/requirements.txt
boto==2.49.0
boto3==1.9.236
botocore==1.12.236
dj-database-url==0.5.0
Django==2.1
django-crispy-forms==1.7.2
django-heroku==0.3.1
django-storages==1.7.2
docutils==0.15.2
gunicorn==19.9.0
jmespath==0.9.4
joblib==0.13.2

numpy==1.17.2
pandas==0.25.1
Pillow==6.1.0
psycopg2==2.8.3
python-dateutil==2.8.0
pytz==2019.2
s3transfer==0.2.1
scikit-learn==0.21.3
scipy==1.3.1
six==1.12.0
sklearn==0.0
urllib3==1.25.6
whitenoise==4.1.4
djangorestframework==3.11.0
<file_sep>/api_env/Scripts/django-admin.py
#!c:\users\slappy1012\desktop\2020\api_jobseeker\api_env\scripts\python.exe
from django.core import management

if __name__ == "__main__":
    management.execute_from_command_line()
<file_sep>/jobseeker_api/api/serializers.py
from rest_framework import serializers

class recomm_serializer(serializers.Serializer):
    """ Get recommendations for a Profile"""
    n1 = serializers.IntegerField()
<file_sep>/jobseeker_api/api/urls.py
from django.urls import path
from api import views

urlpatterns = [
        path('', views.GetConn.as_view(), name = 'test-conn'),
        path('recommend/', views.GetRecomm.as_view(), name = 'recommend'),

]
