예제 #1
0
async def delete_job(job_id: int, token: str = Header(None)):
    authenticated_user = verify_token(token)
    if not authenticated_user:
        response = {'detail': 'UNAUTHORIZED ACCESS', 'status': 401}
        return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
                            content=response)

    query = Job.select().where(Job.c.id == job_id)
    is_exist = await database.fetch_one(query)
    if not is_exist:
        response = {'detail': 'JOB NOT FOUND', 'status': 404}
        return JSONResponse(status_code=status.HTTP_404_NOT_FOUND,
                            content=response)

    if is_exist.created_by != authenticated_user['user_id']:
        response = {
            'detail': 'UNAUTHORIZED ACCESS(YOU CAN DELETE YOUR JOB ONLY)',
            'status': 401
        }
        return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
                            content=response)

    query = Job.update().where(Job.c.id == job_id).values(status='d')
    await database.execute(query)
    response = {
        'detail': "JOB ID: {} DELETED SUCCESSFULLY".format(job_id),
        'status': 200
    }
    return JSONResponse(status_code=status.HTTP_200_OK, content=response)
예제 #2
0
async def get_job(job_id: int):
    query = Job.select().where(Job.c.id == job_id)
    is_exist = await database.fetch_one(query)
    if not is_exist:
        response = {'detail': 'JOB NOT FOUND', 'status': 404}
        return JSONResponse(status_code=status.HTTP_404_NOT_FOUND,
                            content=response)

    return is_exist
예제 #3
0
def crawling(task):
    payload = {
        'first': False,
        'kd': task[0],
        'pn': task[2],
    }
    params = {
        'city': task[1]
    }

    print str(os.getpid())+' Crawling '+task[0]+' '+task[1]+' '+str(task[2])
    response = requests_post(
        'http://www.lagou.com/jobs/positionAjax.json',
        params=params,
        payload=payload)

    result = response.json()['content']['result']

    if result:
        try:
            with mysql_db.atomic():
                for res in result:
                    job = Job.select().where(Job.position_id == res['positionId']).exists()
                    if not job:
                        item = {}
                        item['position_id'] = res['positionId']
                        item['city'] = params['city']
                        item['company_name'] = res['companyName']
                        item['company_short_name'] = res['companyShortName']
                        item['company_size'] = res['companySize']
                        item['create_time'] = res['createTime']
                        item['education'] = res['education']
                        item['finance_stage'] = res['financeStage']
                        item['industry_field'] = res['industryField']
                        item['position_name'] = payload['kd']
                        item['position_first_type'] = res['positionFirstType']
                        item['position_type'] = res['positionType']
                        item['job_nature'] = res['jobNature']
                        item['salary'] = res['salary']
                        item['work_year'] = res['workYear']

                        Job.create(**item)
        except:
            print str(os.getpid())+' mysql insert exception'
        for i in range(1, 5):

            queue.put((task[0], task[1], task[2]+i))
        return
    else:
        return
예제 #4
0
def main():
    python = Job.select().where(Job.position_name == 'python')
    java = Job.select().where(Job.position_name == 'java')
    php = Job.select().where(Job.position_name == 'php')
    c_plus = Job.select().where(Job.position_name == 'c++')
    c = Job.select().where(Job.position_name == 'c')

    positions = {
        'python': python,
        'java': java,
        'php': php,
        'c++': c_plus,
        'c': c
    }
    cities = ['北京', '上海', '广州', '深圳', '杭州']
    # cities = ['北京']

    # positionnum_city(positions, cities)
    # salary_city(positions, cities)
    # companysize_city(positions, cities)
    # salary_workyear(positions)
    # salary_education(positions)
    positionnum_workyear(positions)
    positionnum_education(positions)
예제 #5
0
async def update_job(job_id: int, job: JobValidator,
                     token: str = Header(None)):
    query = Job.select().where(Job.c.id == job_id)
    is_exist = await database.fetch_one(query)
    if not is_exist:
        response = {'detail': 'JOB NOT FOUND', 'status': 404}
        return JSONResponse(status_code=status.HTTP_404_NOT_FOUND,
                            content=response)

    authenticated_user = verify_token_with_role(token,
                                                expected_role='recruiter')
    if not authenticated_user or is_exist.created_by != authenticated_user[
            'user_id']:
        response = {
            'detail': 'UNAUTHORIZED ACCESS(ONLY JOB OWNER CAN UPDATE THE JOB)',
            'status': 401
        }
        return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
                            content=response)

    query = Job.update().where(Job.c.id == job_id).values(
        company_name=job.company_name
        if job.company_name else is_exist.company_name,
        job_title=job.job_title if job.job_title else is_exist.job_title,
        job_type=job.job_type if job.job_type else is_exist.job_type,
        experiance_min=job.experiance_min
        if job.experiance_min else is_exist.experiance_min,
        experiance_max=job.experiance_max
        if job.experiance_max else is_exist.experiance_max,
        job_count=job.job_count if job.job_count else is_exist.job_count,
        location=job.location if job.location else is_exist.location,
        status=job.status if job.status else is_exist.status,
        description_short=job.description_short
        if job.description_short else is_exist.description_short,
        description_long=job.description_long
        if job.description_long else is_exist.description_long,
    )
    last_record_id = await database.execute(query)
    await database.execute(query)
    return {**job.dict(), "ID": last_record_id}
예제 #6
0
async def apply_job(job_id: int,
                    job: AppliedJobValidator,
                    token: str = Header(None)):
    authenticated_user = verify_token(token)
    if not authenticated_user:
        response = {'detail': 'UNAUTHORIZED ACCESS', 'status': 401}
        return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED,
                            content=response)

    query = Job.select().where(Job.c.id == job_id)
    is_exist = await database.fetch_one(query)
    if not is_exist:
        response = {'detail': 'REQUESTED JOB NOT FOUND', 'status': 404}
        return JSONResponse(status_code=status.HTTP_404_NOT_FOUND,
                            content=response)

    query = session.query(AppliedJob).filter(
        AppliedJob.c.job_id == job_id,
        AppliedJob.c.user_id == authenticated_user['user_id']).first()
    if query:
        response = {'detail': 'ALREADY APPLIED', 'status': 406}
        return JSONResponse(status_code=status.HTTP_406_NOT_ACCEPTABLE,
                            content=response)

    query = AppliedJob.insert().values(
        user_id=authenticated_user['user_id'],
        job_id=job_id,
        status='applied',
    )
    apply = AppliedJob.insert().values(user_id=authenticated_user['user_id'],
                                       job_id=job_id,
                                       status='a')
    session.execute(apply)
    session.commit()
    response = {'detail': 'SUCCESSFULLY APPLIED', 'status': 200}
    return JSONResponse(status_code=status.HTTP_200_OK, content=response)
예제 #7
0
async def get_all_jobs(skip: int = 0, paginate: int = 20):
    jobs = Job.select().offset(skip).limit(paginate)
    return await database.fetch_all(jobs)