-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
237 lines (221 loc) · 7.42 KB
/
index.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
from flask import Flask
from fastapi import FastAPI, Request, Depends, BackgroundTasks,Form,Cookie,File, UploadFile,Query,HTTPException
from fastapi.staticfiles import StaticFiles
from starlette.responses import RedirectResponse, Response
from fastapi.templating import Jinja2Templates
import json
from pydantic import BaseModel
from datetime import datetime
import os
import re
import shutil
from main import *
# import tablib
from werkzeug.utils import secure_filename
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from mongoengine import *
from starlette.requests import *
from starlette.responses import *
# from pymsgbox import *
# import tkinter
# from tkinter import messagebox
# import win32api
# import js2py
# import pandas
# import ctypes
import os.path
login=False
username=None
templates =Jinja2Templates(directory="templates")
app = FastAPI()
DB_URI="mongodb+srv://test:[email protected]/test?retryWrites=true&w=majority"
connect(host=DB_URI)
class placement(Document):
firstname=StringField(required=True)
lastname=StringField(required=True)
email=EmailField(unique=True,required=True)
password=StringField(required=True)
admin=BooleanField(default=False)
date_created=DateTimeField(default=datetime.utcnow)
student=BooleanField(default=False)
recruiter=BooleanField(default=False)
app.mount("/css", StaticFiles(directory="css"), name="css")
app.mount("/fonts", StaticFiles(directory="fonts"), name="fonts")
app.mount("/img", StaticFiles(directory="img"), name="img")
app.mount("/js", StaticFiles(directory="js"), name="js")
@app.get('/upload')
async def m(response: Response,request: Request):
if(login is True):
return templates.TemplateResponse("rupload.html",{
"request":request,
"message":None
})
else:
return RedirectResponse(url="/login",status_code=302)
@app.get('/')
async def home(response: Response,request: Request):
print(login)
if(login is True):
global username
print(username)
print("helllllooooo")
return templates.TemplateResponse("index.html",{
"request":request,
"message":username
})
else:
return RedirectResponse(url="/login",status_code=302)
@app.get('/login')
async def home(response: Response,request: Request):
return templates.TemplateResponse("login.html",{
"request":request
})
@app.get('/signup')
async def home(response: Response,request: Request):
return templates.TemplateResponse("signup.html",{
"request":request,
"email_m":False,
"pass_m":False
})
@app.get('/logout')
async def logout(response: Response,request: Request):
global login
login=False
return RedirectResponse(url="/login",status_code=302)
@app.post('/upload')
async def create_upload_file(request: Request,response: Response,file: UploadFile = File(...),rskills: str = Form(None)):
path="C:\\Users\\User\\Desktop\\Resume-Rater-master\\src\\data\\test"
global upload_folder
file_object = file.file
upload_folder=path
upload_folder = open(os.path.join(upload_folder, file.filename), 'wb+')
shutil.copyfileobj(file_object, upload_folder)
upload_folder.close()
#print(rskills)
a="fixed"
b="C:\\Users\\User\\Desktop\\Resume-Rater-master\\src\\data\\test\\"+file.filename
if(rskills is not None):
required=rskills.split(',')
else:
required=None
myset={
}
if(required is not None):
for word in required:
word=word.strip()
word=word.lower()
myset[word]=False
#print(required)
#print(b)
#return RedirectResponse(url="/",status_code=302)
c="model"
extension = os.path.splitext(file.filename)[1]
print(extension)
if(extension=='.pdf' or extension=='.docx' or extension =='.docx'):
fdata=res(a,b,c)
data=jsonable_encoder(fdata[0])
print(data)
print(fdata[1])
y=json.loads(data)
out_skill=y["Skills"].split(',')
for word in out_skill:
word=word.strip()
word=word.lower()
rword=word[:len(word)-1]
if(word in myset):
myset[word]=True
if(rword in myset):
myset[rword]=True
words=word.split(' ')
for j in words:
j=j.strip()
j=j.lower()
rj=j[:len(j)-1]
if(j in myset):
myset[j]=True
if(rj in myset):
myset[rj]=True
print(myset)
d=0
c=0
for i,j in myset.items():
if(j==True):
d=d+1
c=c+1
print(d)
print(c)
return templates.TemplateResponse("upload.html",{
"request":request,
"rating":fdata[1],
"y":y,
"myset":myset,
"d":d,
"c":c
})
else:
return templates.TemplateResponse("rupload.html",{
"request":request,
"message":1
})
@app.post('/signup')
async def signup(request: Request,response: Response,fname: str = Form(None),lname: str = Form(None),email: str = Form(None),password: str = Form(None),type1: str= Form(None)):
fname=fname.lower()
lname=lname.lower()
email=email.lower()
check=placement.objects(email=email)
if(len(check)!=0):
#error message
return templates.TemplateResponse("signup.html",{
"request":request,
"email_m":True,
"pass_m":False
})
if re.search("^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$",password) ==None:
#error
return templates.TemplateResponse("signup.html",{
"request":request,
"email_m":False,
"pass_m":True
})
else:
inp=placement()
inp.firstname=fname
inp.lastname=lname
inp.email=email
inp.password=password
inp.admin=False
if(type1=="o1"):
inp.recruiter=True
inp.student=False
else:
inp.student=True
inp.recruiter=False
inp.date_created=datetime.utcnow
inp.save()
return RedirectResponse(url="/login",status_code=302)
@app.post('/login')
async def login(request: Request,response: Response,password: str = Form(None),email: str = Form(None)):
email=email.lower()
valid=placement.objects(email=email)
if valid is not None:
valid=valid.get()
if not placement.objects(email=email):
#error
return templates.TemplateResponse("login.html",{
"request":request,
"message":True
})
elif valid.password!=password:
#valid=log.objects(username=user).get()
#error
return templates.TemplateResponse("login.html",{
"request":request,
"message":True
})
else:
global username
username=valid.firstname
global login
login=True
return RedirectResponse(url="/",status_code=302)