From fbdf40008362877f9fd8821bc220a8b0f22cbaa9 Mon Sep 17 00:00:00 2001
From: saeidnahali <63702251+saeidnahali@users.noreply.github.com>
Date: Sat, 14 Nov 2020 20:35:48 -0800
Subject: [PATCH 1/2] Final edited on Jobhunter
I added and edited lines
---
JobHunter/.idea/JobHunter.iml | 5 +-
.../inspectionProfiles/Project_Default.xml | 71 ++++++++++++++++
JobHunter/.idea/misc.xml | 2 +-
JobHunter/.idea/vcs.xml | 6 ++
JobHunter/.idea/workspace.xml | 28 +++++++
JobHunter/JobHunter.py | 81 ++++++++++++++-----
6 files changed, 166 insertions(+), 27 deletions(-)
create mode 100644 JobHunter/.idea/inspectionProfiles/Project_Default.xml
create mode 100644 JobHunter/.idea/vcs.xml
diff --git a/JobHunter/.idea/JobHunter.iml b/JobHunter/.idea/JobHunter.iml
index 85c7612..0e4e9fa 100644
--- a/JobHunter/.idea/JobHunter.iml
+++ b/JobHunter/.idea/JobHunter.iml
@@ -4,10 +4,7 @@
-
+
-
-
-
\ No newline at end of file
diff --git a/JobHunter/.idea/inspectionProfiles/Project_Default.xml b/JobHunter/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..fb12032
--- /dev/null
+++ b/JobHunter/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JobHunter/.idea/misc.xml b/JobHunter/.idea/misc.xml
index 3d7df4f..d1e22ec 100644
--- a/JobHunter/.idea/misc.xml
+++ b/JobHunter/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/JobHunter/.idea/vcs.xml b/JobHunter/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/JobHunter/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JobHunter/.idea/workspace.xml b/JobHunter/.idea/workspace.xml
index 4979846..645db88 100644
--- a/JobHunter/.idea/workspace.xml
+++ b/JobHunter/.idea/workspace.xml
@@ -75,6 +75,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/JobHunter/JobHunter.py b/JobHunter/JobHunter.py
index 0ddd895..db9f43d 100644
--- a/JobHunter/JobHunter.py
+++ b/JobHunter/JobHunter.py
@@ -1,12 +1,13 @@
# This script pulls from a job website and stores positions into a database. If there is a new posting it notifies the user.
-# CNA 330
-# Zachary Rubin, zrubin@rtc.edu
+# Saeid Nahali
+# CNA330 11/14/2020
import mysql.connector
import sys
import json
import urllib.request
import os
import time
+from datetime import datetime
# Connect to database
# You may need to edit the connect function based on your local settings.
@@ -15,40 +16,62 @@ def connect_to_sql():
host='127.0.0.1',
database='cna330')
return conn
-
# Create the table structure
def create_tables(cursor, table):
## Add your code here. Starter code below
- cursor.execute('''CREATE TABLE IF NOT EXISTS tablename (id INT PRIMARY KEY); ''')
+ cursor.execute('''CREATE TABLE IF NOT EXISTS Jobs (ID INT PRIMARY KEY auto_increment,
+ Type varchar(10),
+ Title varchar(100),
+ Description text CHARSET utf8,
+ Job_id varchar(36),
+ Created_at DATE,
+ Company varchar(100),
+ Location varchar(100),
+ How_to_apply varchar(1000)); ''')
return
-
# Query the database.
# You should not need to edit anything in this function
def query_sql(cursor, query):
cursor.execute(query)
return cursor
-
# Add a new job
def add_new_job(cursor, jobdetails):
## Add your code here
query = "INSERT INTO"
+ type = jobdetails['type']
+ created_at = time.strptime(jobdetails['created_at'], "%a %b %d %H:%M:%S %Z %Y")
+ company = jobdetails['company']
+ location = jobdetails['location']
+ title = jobdetails['title']
+ description = jobdetails['description']
+ how_to_apply = jobdetails['how_to_apply']
+ job_id = jobdetails['id']
+ query = cursor.execute("INSERT INTO Jobs(Type, "
+ "Title, Description, "
+ "Job_id, Created_at, "
+ "Company, Location, "
+ "How_to_apply" ") "
+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s)", (type, title, description, job_id,
+ created_at, company, location, how_to_apply))
return query_sql(cursor, query)
-
# Check if new job
def check_if_job_exists(cursor, jobdetails):
## Add your code here
query = "SELECT"
+ job_id = jobdetails['id']
+ query = "SELECT * FROM Jobs WHERE Job_id = \"%s\"" % job_id
return query_sql(cursor, query)
-
def delete_job(cursor, jobdetails):
## Add your code here
query = "UPDATE"
+ job_id = jobdetails['id']
+ query = "DELETE FROM Jobs WHERE Job_id = \"%s\"" % job_id
return query_sql(cursor, query)
-
# Grab new jobs from a website
def fetch_new_jobs(arg_dict):
# Code from https://github.com/RTCedu/CNA336/blob/master/Spring2018/Sql.py
- query = "https://jobs.github.com/positions.json?" + "location=seattle" ## Add arguments here
+ #query = "https://jobs.github.com/positions.json?" + "location=seattle" ## Add arguments here
+ query = "https://jobs.github.com/positions.json?search=SQL&location=Remote"
jsonpage = 0
try:
contents = urllib.request.urlopen(query)
@@ -57,7 +80,6 @@ def fetch_new_jobs(arg_dict):
except:
pass
return jsonpage
-
# Load a text-based configuration file
def load_config_file(filename):
argument_dictionary = 0
@@ -73,23 +95,39 @@ def load_config_file(filename):
file = open(filename, "w")
file.write("")
file.close()
-
## Add in information for argument dictionary
return argument_dictionary
-
# Main area of the code.
def jobhunt(cursor, arg_dict):
# Fetch jobs from website
jobpage = fetch_new_jobs(arg_dict)
# print (jobpage)
+ add_or_delete_job(cursor, jobpage)
+def add_or_delete_job(cursor, jobpage):
## Add your code here to parse the job page
-
+ for jobdetails in jobpage:
## Add in your code here to check if the job already exists in the DB
-
- ## Add in your code here to notify the user of a new posting
-
- ## EXTRA CREDIT: Add your code to delete old entries
-
+ check_if_job_exists(cursor, jobdetails)
+ is_job_found = len(cursor.fetchall()) > 0
+ if is_job_found:
+ ## EXTRA CREDIT: Add your code to delete old entries
+ now = datetime.now()
+ job_date = datetime.strptime(jobdetails['created_at'], "%a %b %d %H:%M:%S %Z %Y")
+ if (now - job_date).days > 30:
+ print("Delete job: " +
+ jobdetails["title"] +
+ " from " + jobdetails["company"] +
+ ", Created at: " + jobdetails["created_at"] +
+ ", JobID: " + jobdetails['id'])
+ delete_job(cursor, jobdetails)
+ else:
+ ## Add in your code here to notify the user of a new posting
+ print("New job is found: " +
+ jobdetails["title"] +
+ " from " + jobdetails["company"] +
+ ", Created at: " + jobdetails["created_at"] +
+ ", JobID: " + jobdetails['id'])
+ add_new_job(cursor, jobdetails)
# Setup portion of the program. Take arguments and set up the script
# You should not need to edit anything here.
def main():
@@ -98,11 +136,10 @@ def main():
cursor = conn.cursor()
create_tables(cursor, "table")
# Load text file and store arguments into dictionary
- arg_dict = load_config_file(sys.argv[1])
+ arg_dict = 0
while(1):
jobhunt(cursor, arg_dict)
conn.commit()
- time.sleep(3600) # Sleep for 1h
-
+ time.sleep(3600) # Sleep for 1h
if __name__ == '__main__':
main()
From a7f0696b6b7e8619683014a5d005e259e3b3155e Mon Sep 17 00:00:00 2001
From: saeidnahali <63702251+saeidnahali@users.noreply.github.com>
Date: Sat, 28 Nov 2020 22:50:58 -0800
Subject: [PATCH 2/2] 1
---
JobHunter/.idea/JobHunter.iml | 2 +-
.../inspectionProfiles/Project_Default.xml | 2 +
JobHunter/.idea/misc.xml | 2 +-
JobHunter/.idea/workspace.xml | 121 +++++-------------
JobHunter/JobHunter.py | 10 +-
5 files changed, 39 insertions(+), 98 deletions(-)
diff --git a/JobHunter/.idea/JobHunter.iml b/JobHunter/.idea/JobHunter.iml
index 0e4e9fa..8b7bd39 100644
--- a/JobHunter/.idea/JobHunter.iml
+++ b/JobHunter/.idea/JobHunter.iml
@@ -4,7 +4,7 @@
-
+
\ No newline at end of file
diff --git a/JobHunter/.idea/inspectionProfiles/Project_Default.xml b/JobHunter/.idea/inspectionProfiles/Project_Default.xml
index fb12032..d5468aa 100644
--- a/JobHunter/.idea/inspectionProfiles/Project_Default.xml
+++ b/JobHunter/.idea/inspectionProfiles/Project_Default.xml
@@ -64,6 +64,8 @@
+
+
diff --git a/JobHunter/.idea/misc.xml b/JobHunter/.idea/misc.xml
index d1e22ec..f56ad02 100644
--- a/JobHunter/.idea/misc.xml
+++ b/JobHunter/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/JobHunter/.idea/workspace.xml b/JobHunter/.idea/workspace.xml
index 645db88..132120c 100644
--- a/JobHunter/.idea/workspace.xml
+++ b/JobHunter/.idea/workspace.xml
@@ -2,32 +2,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -35,46 +16,20 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
@@ -103,6 +58,7 @@
+
@@ -116,46 +72,29 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JobHunter/JobHunter.py b/JobHunter/JobHunter.py
index db9f43d..a33bc38 100644
--- a/JobHunter/JobHunter.py
+++ b/JobHunter/JobHunter.py
@@ -1,6 +1,6 @@
# This script pulls from a job website and stores positions into a database. If there is a new posting it notifies the user.
-# Saeid Nahali
-# CNA330 11/14/2020
+# Mohammad Pakizeh Jam
+# CNA330 11/12/2020
import mysql.connector
import sys
import json
@@ -12,8 +12,8 @@
# Connect to database
# You may need to edit the connect function based on your local settings.
def connect_to_sql():
- conn = mysql.connector.connect(user='root', password='',
- host='127.0.0.1',
+ conn = mysql.connector.connect(user='pythoneverything', password='python123',
+ host='18.216.19.4',
database='cna330')
return conn
# Create the table structure
@@ -70,7 +70,7 @@ def delete_job(cursor, jobdetails):
# Grab new jobs from a website
def fetch_new_jobs(arg_dict):
# Code from https://github.com/RTCedu/CNA336/blob/master/Spring2018/Sql.py
- #query = "https://jobs.github.com/positions.json?" + "location=seattle" ## Add arguments here
+ query = "https://jobs.github.com/positions.json?" + "location=seattle" ## Add arguments here
query = "https://jobs.github.com/positions.json?search=SQL&location=Remote"
jsonpage = 0
try: