0

email user specific developer jobs at a given location

import requests # for api import smtplib # for emails import auth

class Jobs:

URL = "https://jobs.github.com/positions"  # base url for API

def _jobs_api(self):  # get json data (jobs)
    location = input("Where would you like to become a developer? \U0001f607\n")  # location parameter
    description = input("What type of developer are you interested in becoming? \U0001f608\n")  # search term

    response = requests.get(Jobs.URL,
                            headers={"Accept": "application/json"},
                            params={"location": location, "description": description}  # query params
                            )
    data = response.json()
    return data

def _job_links(self):
    data = self._jobs_api()
    if data:
        for job in data:
            links = job['url']
            return links
    else:
        print(f"Sorry, I was not able to find any {self.description} jobs in {self.location}...")

def send_jobs(self):  # email auth
    links = self._job_links()
    smpt_object = smtplib.SMTP('smtp.gmail.com', 587)
    smpt_object.ehlo()
    smpt_object.starttls()
    # use own authentication data
    email = auth.email()
    password = auth.password()
    smpt_object.login(email, password)
    # next, send the message
    from_address = email
    to_address = email
    subject = "Developer Jobs"
    message = "Here are some jobs you are looking for: {}".format(links)
    msg = "Subject: "+subject+"\n"+message
    print("Check your email for an update! \U0001f601")

    smpt_object.sendmail(from_address, to_address, msg)
    smpt_object.quit()

user = Jobs() user.send_jobs()

I'm trying to use the line Here are some jobs you are looking for: {}".format(links) (or an f string preferably) to send the links found from the API. But, when I check my email, it doesn't show the message with the links.

1 Answers1

0

You can try to send a html structured mail in python to send the url you want.

See this post to find out

Ajay Lingayat
  • 1,465
  • 1
  • 9
  • 25