Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/cne340_jobhunter.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# CNE340 Winter2024 - Job Hunter Project

## Objectives

* Using python to complete the following tasks:
- Connect to MySql on WAMP Server
- Create a database
- Grab new jobs from a website, parses JSON code and inserts the data into a list of dictionaries do not need to edit
- Import to database
- Perform Query commands

## Requirements:

* Project Fork
* GitHub Commits
* CREATE table
* Query table for already-existing job entries
* Add new job function
* Notify user of new jobs
* Meets specific design specifications listed below (covered in depth in the lecture recording)
- Run program once and leave running
- Upon load grabs configuration
- Load desired job keywords
- Connect to DB
- Check once per 4 hours for job
- Adds jobs to the DB
- Avoids duplicates
- Notify user of matches
- Extra Credit: if it deletes jobs over 14 days old

## Special Thanks

Thank you **Ixius Procopios** for the initial code and all the guidance for this project.
47 changes: 34 additions & 13 deletions jobhunter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# CNE 340 Fall 2024
# Student name: Van Vuong
# Project: Job Hunter

import datetime as dt
import mysql.connector
import time
import json
import requests
from datetime import date
import html2text


Expand All @@ -19,12 +23,14 @@ def create_tables(cursor):
# Creates table
# Must set Title to CHARSET utf8 unicode Source: http://mysql.rjweb.org/doc.php/charcoll.
# Python is in latin-1 and error (Incorrect string value: '\xE2\x80\xAFAbi...') will occur if Description is not in unicode format due to the json data
cursor.execute('''CREATE TABLE IF NOT EXISTS jobs (id INT PRIMARY KEY auto_increment, Job_id varchar(50) ,
company varchar (300), Created_at DATE, url varchar(30000), Title LONGBLOB, Description LONGBLOB ); ''')
cursor.execute('''CREATE TABLE IF NOT EXISTS jobs (id INT PRIMARY KEY auto_increment, Job_id varchar(50),
company varchar(300), Created_at DATE, url TEXT, Title LONGBLOB, Description LONGBLOB );''')
return


# Query the database.
# You should not need to edit anything in this function

def query_sql(cursor, query):
cursor.execute(query)
return cursor
Expand All @@ -33,32 +39,38 @@ def query_sql(cursor, query):
# Add a new job
def add_new_job(cursor, jobdetails):
# extract all required columns
job_id = jobdetails['id']
Company = jobdetails['company_name']
URL = jobdetails['url']
title = jobdetails['title']
description = html2text.html2text(jobdetails['description'])
# print(description)
date = jobdetails['publication_date'][0:10]
query = cursor.execute("INSERT INTO jobs( Description, Created_at " ") "
"VALUES(%s,%s)", ( description, date))
# %s is what is needed for Mysqlconnector as SQLite3 uses ? the Mysqlconnector uses %s
# print(date)
query = cursor.execute("INSERT INTO jobs (Job_id, company, url, Title, Description, Created_at)"
"VALUES(%s,%s,%s,%s,%s,%s)", (job_id, Company, URL, title, description, date))
# %s is what is needed for Mysqlconnector as SQLite3 uses ? the Mysqlconnector uses %s
return query_sql(cursor, query)


# Check if new job
def check_if_job_exists(cursor, jobdetails):
##Add your code here
query = "UPDATE"
query = "SELECT * FROM jobs WHERE Job_id = \"%s\" " % jobdetails['id']
return query_sql(cursor, query)


# Deletes job
def delete_job(cursor, jobdetails):
##Add your code here
query = "UPDATE"
query = "DELETE FROM jobs WHERE Job_id = \"%s\" " % jobdetails['id']
return query_sql(cursor, query)


# Grab new jobs from a website, Parses JSON code and inserts the data into a list of dictionaries do not need to edit
def fetch_new_jobs():
query = requests.get("https://remotive.io/api/remote-jobs")
datas = json.loads(query.text)

return datas


Expand All @@ -73,17 +85,27 @@ def jobhunt(cursor):

def add_or_delete_job(jobpage, cursor):
# Add your code here to parse the job page
for jobdetails in jobpage['jobs']: # EXTRACTS EACH JOB FROM THE JOB LIST. It errored out until I specified jobs. This is because it needs to look at the jobs dictionary from the API. https://careerkarma.com/blog/python-typeerror-int-object-is-not-iterable/
for jobdetails in jobpage['jobs']:
# EXTRACTS EACH JOB FROM THE JOB LIST. It errored out until I specified jobs. This is because it needs to look at the jobs dictionary from the API. https://careerkarma.com/blog/python-typeerror-int-object-is-not-iterable/
# Add in your code here to check if the job already exists in the DB
check_if_job_exists(cursor, jobdetails)
is_job_found = len(
cursor.fetchall()) > 0 # https://stackoverflow.com/questions/2511679/python-number-of-rows-affected-by-cursor-executeselect
is_job_found = len(cursor.fetchall()) > 0 # https://stackoverflow.com/questions/2511679/python-number-of-rows-affected-by-cursor-executeselect
if is_job_found:
current_date = dt.datetime.now()
post_date = dt.datetime.strptime(jobdetails['publication_date'], "%Y-%m-%dT%H:%M:%S")

# Delete if jobs over 14 days old
if (current_date.day - post_date.day) > 14:
print("Sorry, Job is not available!")
delete_job(cursor, jobdetails)
else:
# INSERT JOB
# Add in your code here to notify the user of a new posting. This code will notify the new user

print(f"Jobs found match for you. Title: " + jobdetails['title'] + ". Company: " + jobdetails[
'company_name'] + ", posted on " + jobdetails['publication_date'] + ", Job ID: " + str(
jobdetails['id']))
add_new_job(cursor, jobdetails)


# Setup portion of the program. Take arguments and set up the script
Expand All @@ -104,4 +126,3 @@ def main():
# If you want to test if script works change time.sleep() to 10 seconds and delete your table in MySQL
if __name__ == '__main__':
main()

8 changes: 8 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import datetime as dt

current_date = dt.datetime.now()
post_date = dt.datetime.strptime("2024-02-07T00:51:00", "%Y-%m-%dT%H:%M:%S")


print(current_date.day)
print(post_date.day)