diff --git a/.idea/cne340_jobhunter.iml b/.idea/cne340_jobhunter.iml
index 74d515a..aee9ef2 100644
--- a/.idea/cne340_jobhunter.iml
+++ b/.idea/cne340_jobhunter.iml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 1b334b0..a6218fe 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,7 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..76e9f98
--- /dev/null
+++ b/README.md
@@ -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.
\ No newline at end of file
diff --git a/jobhunter.py b/jobhunter.py
index ea9fb15..1e08f68 100644
--- a/jobhunter.py
+++ b/jobhunter.py
@@ -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
@@ -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
@@ -33,24 +39,31 @@ 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)
@@ -58,7 +71,6 @@ def delete_job(cursor, jobdetails):
def fetch_new_jobs():
query = requests.get("https://remotive.io/api/remote-jobs")
datas = json.loads(query.text)
-
return datas
@@ -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
@@ -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()
-
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..bfd4a34
--- /dev/null
+++ b/test.py
@@ -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)
\ No newline at end of file