asdf
This commit is contained in:
parent
456ad55d01
commit
6d9396cafa
|
@ -14,3 +14,4 @@ alembic.ini
|
||||||
/files
|
/files
|
||||||
hello.py
|
hello.py
|
||||||
/test
|
/test
|
||||||
|
/logs
|
||||||
|
|
12748
logs/app.log
12748
logs/app.log
File diff suppressed because it is too large
Load Diff
49594
logs/app.log.1
49594
logs/app.log.1
File diff suppressed because it is too large
Load Diff
63311
logs/app.log.2
63311
logs/app.log.2
File diff suppressed because one or more lines are too long
|
@ -50,6 +50,21 @@ class JsonData(BaseModel):
|
||||||
json_data: Union[dict, str]
|
json_data: Union[dict, str]
|
||||||
|
|
||||||
|
|
||||||
|
class jobs_delete(BaseModel):
|
||||||
|
user_id: int
|
||||||
|
job_id:int
|
||||||
|
|
||||||
|
|
||||||
|
class avtopilots(BaseModel):
|
||||||
|
user_id: int
|
||||||
|
avtopilot:bool
|
||||||
|
|
||||||
|
class update(BaseModel):
|
||||||
|
user_id: int
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/client/")
|
@router.post("/client/")
|
||||||
async def client(data: JsonData, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
async def client(data: JsonData, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
||||||
if x_api_key != "4545454":
|
if x_api_key != "4545454":
|
||||||
|
@ -126,139 +141,76 @@ async def client(data: JsonData, x_api_key: str = Header(...), db: Session = Dep
|
||||||
|
|
||||||
|
|
||||||
@router.post("/client_update")
|
@router.post("/client_update")
|
||||||
async def client_update(data: JsonData, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
async def client_update(data: update, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
||||||
|
|
||||||
if x_api_key != "4545454":
|
if x_api_key != "4545454":
|
||||||
raise HTTPException(status_code=403, detail="Invalid API Key")
|
raise HTTPException(status_code=403, detail="Invalid API Key")
|
||||||
|
|
||||||
|
try:
|
||||||
# Если json_data строка, декодируем её в словарь
|
user_id = data.user_id # Обратите внимание на точку вместо квадратных скобок
|
||||||
if isinstance(data.json_data, str):
|
|
||||||
try:
|
print(f"Полученные данные: user_id={user_id}")
|
||||||
data.json_data = json.loads(data.json_data) # Декодируем строку в словарь
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid JSON format")
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
if isinstance(data.json_data, dict):
|
print(f"Ошибка при обработке данных: {e}")
|
||||||
try:
|
raise HTTPException(status_code=400, detail="Error processing data")
|
||||||
|
|
||||||
user_id = data.json_data['user_id']
|
|
||||||
|
|
||||||
|
|
||||||
print(f"Полученные заявки: {get_jobs}")
|
|
||||||
|
|
||||||
except KeyError as e:
|
return {"status": "ok", "message": "Data received", "user_id": user_id, }
|
||||||
print(f"Ошибка при извлечении данных: {e}")
|
|
||||||
raise HTTPException(status_code=400, detail="Missing required field in json_data")
|
|
||||||
|
|
||||||
else:
|
|
||||||
print(f"Неверный формат данных: {type(data.json_data)}")
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid data format")
|
|
||||||
|
|
||||||
return {"status": "ok", "message": "JSON получен" }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/client_jobs/")
|
@router.post("/client_jobs/")
|
||||||
async def client_jobs(data: JsonData, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
async def client_jobs(data: update, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
||||||
if x_api_key != "4545454":
|
if x_api_key != "4545454":
|
||||||
raise HTTPException(status_code=403, detail="Invalid API Key")
|
raise HTTPException(status_code=403, detail="Invalid API Key")
|
||||||
|
|
||||||
|
try:
|
||||||
# Если json_data строка, декодируем её в словарь
|
user_id = data.user_id # Обратите внимание на точку вместо квадратных скобок
|
||||||
if isinstance(data.json_data, str):
|
get_jobs = await get_applied_jobs(db, user_id)
|
||||||
try:
|
print(f"Полученные данные: user_id={user_id}")
|
||||||
data.json_data = json.loads(data.json_data) # Декодируем строку в словарь
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid JSON format")
|
|
||||||
|
|
||||||
# Если json_data строка — декодируем
|
except Exception as e:
|
||||||
# Теперь data.json_data гарантированно является словарем
|
print(f"Ошибка при обработке данных: {e}")
|
||||||
if isinstance(data.json_data, dict):
|
raise HTTPException(status_code=400, detail="Error processing data")
|
||||||
try:
|
|
||||||
|
|
||||||
user_id = data.json_data['user_id']
|
|
||||||
|
|
||||||
get_jobs = await get_applied_jobs(db, user_id)
|
|
||||||
print(f"Полученные заявки: {get_jobs}")
|
|
||||||
|
|
||||||
except KeyError as e:
|
return {"status": "ok", "message": "Data received", "get_jobs": get_jobs}
|
||||||
print(f"Ошибка при извлечении данных: {e}")
|
# return {"message": "JSON получен", "data": get_jobs}
|
||||||
raise HTTPException(status_code=400, detail="Missing required field in json_data")
|
|
||||||
|
|
||||||
else:
|
|
||||||
print(f"Неверный формат данных: {type(data.json_data)}")
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid data format")
|
|
||||||
|
|
||||||
return {"message": "JSON получен", "data": get_jobs}
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/avtopilot")
|
@router.post("/avtopilot")
|
||||||
async def avtopilot(data: JsonData, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
async def avtopilot(data: avtopilots, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
||||||
|
|
||||||
if x_api_key != "4545454":
|
if x_api_key != "4545454":
|
||||||
raise HTTPException(status_code=403, detail="Invalid API Key")
|
raise HTTPException(status_code=403, detail="Invalid API Key")
|
||||||
|
|
||||||
|
try:
|
||||||
# Если json_data строка, декодируем её в словарь
|
user_id = data.user_id # Обратите внимание на точку вместо квадратных скобок
|
||||||
if isinstance(data.json_data, str):
|
avtopilotss = data.avtopilot # Так как data - это объект Pydantic модели
|
||||||
try:
|
|
||||||
data.json_data = json.loads(data.json_data) # Декодируем строку в словарь
|
print(f"Полученные данные: user_id={user_id}, avtopilotss={avtopilotss}")
|
||||||
except json.JSONDecodeError:
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid JSON format")
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
if isinstance(data.json_data, dict):
|
print(f"Ошибка при обработке данных: {e}")
|
||||||
try:
|
raise HTTPException(status_code=400, detail="Error processing data")
|
||||||
|
|
||||||
user_id = data.json_data['user_id']
|
|
||||||
|
|
||||||
|
|
||||||
print(f"Полученные заявки: {get_jobs}")
|
|
||||||
|
|
||||||
except KeyError as e:
|
return {"status": "ok", "message": "Data received", "user_id": user_id, "avtopilotss": avtopilotss}
|
||||||
print(f"Ошибка при извлечении данных: {e}")
|
|
||||||
raise HTTPException(status_code=400, detail="Missing required field in json_data")
|
|
||||||
|
|
||||||
else:
|
|
||||||
print(f"Неверный формат данных: {type(data.json_data)}")
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid data format")
|
|
||||||
|
|
||||||
return {"status": "ok", "message": "JSON получен" }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/jobs_delete")
|
@router.post("/jobs_delete")
|
||||||
async def jobs_delete(data: JsonData, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
async def jobs_delete(data: jobs_delete, x_api_key: str = Header(...), db: Session = Depends(get_async_session)):
|
||||||
|
|
||||||
if x_api_key != "4545454":
|
if x_api_key != "4545454":
|
||||||
raise HTTPException(status_code=403, detail="Invalid API Key")
|
raise HTTPException(status_code=403, detail="Invalid API Key")
|
||||||
|
|
||||||
|
try:
|
||||||
# Если json_data строка, декодируем её в словарь
|
user_id = data.user_id # Обратите внимание на точку вместо квадратных скобок
|
||||||
if isinstance(data.json_data, str):
|
job_id = data.job_id # Так как data - это объект Pydantic модели
|
||||||
try:
|
|
||||||
data.json_data = json.loads(data.json_data) # Декодируем строку в словарь
|
print(f"Полученные данные: user_id={user_id}, job_id={job_id}")
|
||||||
except json.JSONDecodeError:
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid JSON format")
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
if isinstance(data.json_data, dict):
|
print(f"Ошибка при обработке данных: {e}")
|
||||||
try:
|
raise HTTPException(status_code=400, detail="Error processing data")
|
||||||
|
|
||||||
user_id = data.json_data['user_id']
|
|
||||||
|
|
||||||
|
|
||||||
print(f"Полученные заявки: {get_jobs}")
|
|
||||||
|
|
||||||
except KeyError as e:
|
return {"status": "ok", "message": "Data received", "user_id": user_id, "job_id": job_id}
|
||||||
print(f"Ошибка при извлечении данных: {e}")
|
|
||||||
raise HTTPException(status_code=400, detail="Missing required field in json_data")
|
|
||||||
|
|
||||||
else:
|
|
||||||
print(f"Неверный формат данных: {type(data.json_data)}")
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid data format")
|
|
||||||
|
|
||||||
return {"status": "ok", "message": "JSON получен" }
|
|
||||||
|
|
||||||
|
|
4596
search_jobes2.json
4596
search_jobes2.json
File diff suppressed because it is too large
Load Diff
31
utils/app.py
31
utils/app.py
|
@ -41,7 +41,7 @@ password = os.getenv('PASSWD')
|
||||||
# Authenticate using any Linkedin user account credentials
|
# Authenticate using any Linkedin user account credentials
|
||||||
api = Linkedin(username, password)
|
api = Linkedin(username, password)
|
||||||
|
|
||||||
def pars_jobs(geo):
|
async def pars_jobs(geo):
|
||||||
search_jobs = api.search_jobs(location_geo_id = geo)
|
search_jobs = api.search_jobs(location_geo_id = geo)
|
||||||
search_jobes = [
|
search_jobes = [
|
||||||
{
|
{
|
||||||
|
@ -234,7 +234,10 @@ async def get_vakansi():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# geo = '100025096'
|
# geo = '100025096' #ON
|
||||||
|
# geo = '101174742' #Canada
|
||||||
|
# geo = '103644278' #USA
|
||||||
|
|
||||||
# pars_jobs(geo)
|
# pars_jobs(geo)
|
||||||
|
|
||||||
|
|
||||||
|
@ -244,7 +247,7 @@ async def get_vakansi():
|
||||||
|
|
||||||
|
|
||||||
#[]TODO!!!
|
#[]TODO!!!
|
||||||
async def main():
|
async def process_jobs():
|
||||||
async for db in get_async_session(): # Асинхронный генератор сессий
|
async for db in get_async_session(): # Асинхронный генератор сессий
|
||||||
query = select(Job).filter(Job.days_posted == 7)
|
query = select(Job).filter(Job.days_posted == 7)
|
||||||
result = await db.execute(query)
|
result = await db.execute(query)
|
||||||
|
@ -254,13 +257,35 @@ async def main():
|
||||||
print(job.job_id)
|
print(job.job_id)
|
||||||
await get_job(db, job.job_id)
|
await get_job(db, job.job_id)
|
||||||
|
|
||||||
|
|
||||||
# if __name__ == "__main__":
|
# if __name__ == "__main__":
|
||||||
# asyncio.run(main())
|
# asyncio.run(main())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# import asyncio
|
||||||
|
|
||||||
|
# async def pars_jobs(geo):
|
||||||
|
# print(f"Parsing jobs for {geo}")
|
||||||
|
# await asyncio.sleep(1) # Имитация асинхронной операции
|
||||||
|
|
||||||
|
# async def get_vakansi():
|
||||||
|
# print("Fetching vacancies")
|
||||||
|
# await asyncio.sleep(1) # Имитация асинхронной операции
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
geo_list = ['100025096', '101174742', '103644278'] # ON, Canada, USA
|
||||||
|
for geo in geo_list:
|
||||||
|
await pars_jobs(geo)
|
||||||
|
await get_vakansi()
|
||||||
|
|
||||||
|
await process_jobs() # Вызываем обработку вакансий
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
||||||
|
|
||||||
# from sqlalchemy.orm import sessionmaker, declarative_base
|
# from sqlalchemy.orm import sessionmaker, declarative_base
|
||||||
# from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
# from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue