0% found this document useful (0 votes)
14 views2 pages

Main Py

Uploaded by

betsmasherhelp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Main Py

Uploaded by

betsmasherhelp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import os

import smtplib
import sqlite3
from email.mime.text import MIMEText
from apscheduler.schedulers.blocking import BlockingScheduler
import pytz
import requests
from bs4 import BeautifulSoup

# --- Database Setup ---


conn = sqlite3.connect("jobs.db")
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS jobs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
company TEXT,
location TEXT,
link TEXT UNIQUE
)
""")
conn.commit()

# --- Email Setup ---


EMAIL_SENDER = "[email protected]"
EMAIL_PASSWORD = os.environ.get("EMAIL_PASSWORD") # Read from environment
variable
EMAIL_RECEIVER = "[email protected]"

def send_email(subject, body):


msg = MIMEText(body, "html")
msg["Subject"] = subject
msg["From"] = EMAIL_SENDER
msg["To"] = EMAIL_RECEIVER

with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:


server.login(EMAIL_SENDER, EMAIL_PASSWORD)
server.sendmail(EMAIL_SENDER, EMAIL_RECEIVER, msg.as_string())

# --- Job Search (Example for UN Jobs, extendable to other sites) ---
def fetch_jobs():
url = "https://careers.un.org/jobsearch/?jobtitle=analyst"
r = requests.get(url)
soup = BeautifulSoup(r.text, "html.parser")
jobs = []
for item in soup.select(".job-item"): # Adjust selector if needed
title = item.select_one(".job-title").text.strip()
company = "United Nations"
location = item.select_one(".job-location").text.strip()
link = "https://careers.un.org" + item.a["href"]
jobs.append((title, company, location, link))
return jobs

# --- Main Task ---


def daily_job_task():
new_jobs = []
jobs = fetch_jobs()

for job in jobs:


try:
cursor.execute("INSERT INTO jobs (title, company, location, link) VALUES (?, ?, ?, ?)",
job)
conn.commit()
new_jobs.append(job)
except sqlite3.IntegrityError:
continue # Already stored

if new_jobs:
body = ""
for i, (title, company, location, link) in enumerate(new_jobs, 1):
body += f"{i}. {title} – {company} ({location}) <a href='{link}'>Apply Here</a><br>"
send_email("New Job Alerts", body)

# --- Scheduler ---


scheduler = BlockingScheduler(timezone=pytz.timezone("Africa/Lagos"))
scheduler.add_job(daily_job_task, "cron", hour=8, minute=0) # 8:00 AM WAT
scheduler.start()

You might also like