-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
61 lines (54 loc) · 1.79 KB
/
Copy pathdatabase.py
File metadata and controls
61 lines (54 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import sqlite3
import os
from datetime import date
DB_PATH = os.path.join(os.path.dirname(__file__), "jobs.db")
def init_db():
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
c.execute("""
CREATE TABLE IF NOT EXISTS jobs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
job_title TEXT NOT NULL,
company TEXT NOT NULL,
location TEXT,
date_posted TEXT,
apply_url TEXT,
source_site TEXT,
easy_apply INTEGER DEFAULT 0,
first_seen DATE NOT NULL,
UNIQUE(company, job_title)
)
""")
conn.commit()
conn.close()
def insert_jobs(jobs):
"""Insert a list of job dicts. Returns only the newly inserted ones."""
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
today = date.today().isoformat()
new_jobs = []
for job in jobs:
try:
c.execute(
"""
INSERT INTO jobs
(job_title, company, location, date_posted, apply_url, source_site, easy_apply, first_seen)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""",
(
job.get("job_title", "").strip(),
job.get("company", "").strip(),
job.get("location", "").strip(),
job.get("date_posted", "").strip(),
job.get("apply_url", "").strip(),
job.get("source_site", "").strip(),
1 if job.get("easy_apply") else 0,
today,
),
)
new_jobs.append(job)
except sqlite3.IntegrityError:
pass # Already seen before — skip
conn.commit()
conn.close()
return new_jobs