The job command¶
The Code Behind The Command¶
The core functionality and implementation behind the /ljobs
command is handled by the job_posts
modules.
When the /ljobs
command is called the job_post_factory.py
module calls the job_scrapper.py
module to send a request to LinkedIn jobs with the provided search parameters (job title, location) or the default search parameters BI Data Analyst, Egypt. if none was provided.
Then the returned data is passed to the TgJobPost
data class in the job_post_creator.py
module to further parse and format the job data to make it ready for being sent in telegram chat using the send_job_posts
function in the job_post_sender.py
module.
The job_post_factory.py
module¶
Click to view the job_post_factory.py
module
channel_jobs_updater(bot: TeleBot) -> None
¶summary : This function updates the job posting in the channel using the CHANNEL_ID variable from .env file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bot |
TeleBot
|
description : bot instance |
required |
Source code in src/job_posts/job_post_factory.py
100 101 102 103 104 105 106 107 108 109 110 111 |
|
job_scrapper(scrapper: LinkedinScrapper, search_params: tuple[str, str] = None) -> list[dict]
¶summary : This function creates the linkedin scrapper object and retrieves the formatted data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scrapper |
LinkedinScrapper
|
description : The linkedin scrapper object. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
description : A list of dicts containing the scrapped jobs data for linkedin. |
Source code in src/job_posts/job_post_factory.py
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 |
|
jobs_factory(search_params: tuple[str, str] = None) -> list[dict]
¶summary : This function creates the scrapper object and the post creator objects.
Returns:
Type | Description |
---|---|
list[dict]
|
description : A list of dict containing the formatted posts ready to send to telegram chat. |
Source code in src/job_posts/job_post_factory.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
post_creator(data: list[dict], creator: TgJobPost) -> list[dict]
¶summary : This function creates the telegram job post creator objects to create job posts for the telegram channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
list[dict]
|
description : A list of dict containing the jobs data. |
required |
creator |
TgJobPost
|
description : The telegram job posts creator object. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
description: A list of dict containing the formatted posts ready to send to telegram chat. |
Source code in src/job_posts/job_post_factory.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
The job_post_factory
is the factory that handles creating the job posts process, from scrapping and parsing the data, formatting it for telegram messages, to sending it in chat.
How does it work
- It calls the scrapper class
LinkedinScrapper
from thejob_scrapper.py
module. - Passes the returned data from the
LinkedinScrapper
class to theTgJobPost
class in thejob_post_creator.py
module to extract jobs information and format it for telegram. - It uses the
send_job_posts
function from thejob_post_sender.py
module to send each created post as a separate message in the telegram chat.
The job_scrapper.py
module¶
The job_scrapper
module contains the LinkedinScrapper
data class which scrapes and collects job posts, parses, and formats them.
The LinkedinScrapper
uses the requests library to send the request to LinkedIn, and BeautifulSoap to parse the HTML response.
Click to view the LinkedinScrapper
data class
Bases: Scrapper
summary : This data class scraps linkedin for the specified search key word and location in the .ev file.
Source code in src/job_posts/job_scrapper.py
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
collect_data()
¶This Method sends calls the url using the request lib and gets back the data from linkedin
Source code in src/job_posts/job_scrapper.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
format_data()
¶This Method formats data after being parsed into a desired format
Source code in src/job_posts/job_scrapper.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
parse_data()
¶This Method parses data and extracts the job's details.
Source code in src/job_posts/job_scrapper.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
scrape_jobs() -> None
¶This method start the scrapping process.
Source code in src/job_posts/job_scrapper.py
71 72 73 74 75 76 77 78 79 80 81 82 |
|
set_search_params(job_tile: str, location: str) -> None
¶summary : This method sets the search parameters for the linkedin jobs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job_tile |
str
|
description : The jobs title to search linkedin jobs for. |
required |
location |
str
|
description : The location to search for jobs in. |
required |
Source code in src/job_posts/job_scrapper.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
The job_post_creator.py
module¶
The job_post_creator.py
module contains the TgJobPost
data class which takes in a dictionary of lists (created by the LinkedinScrapper
data class) containing the job title, company, location, and job post link.
It creates a dictionary of two key:value paris for each job post as the following: {job_details:str, job_link: str}
.
job_post_creator.py | |
---|---|
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
• The job_details: contains the job information as a string.
• The job_link: contains the job post URL on linkedin.
Click to view the TgJobPost
data class
Bases: TgPost
summary : This data class creates posts from the scrapped data.
Source code in src/job_posts/job_post_creator.py
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 62 63 64 65 66 67 68 69 70 |
|
create_posts(jobs_data: list[dict]) -> list[dict]
¶summary : This method loop over the jobs_data list and create a post for each job.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jobs_data |
list[dict]
|
description : This is the list of jobs data that will be used to create the posts. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
description : A list of dicts that contain 'job_details' and 'job_links' for each jobs. |
Source code in src/job_posts/job_post_creator.py
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 62 63 64 65 66 67 68 69 70 |
|
The job_post_sender.py
module¶
This module has only one simple function, send_job_posts
which takes in the dictionary of list containing the job details and job link key, value pairs (Created by the TgJobPost
data class) and sends each one in a separate message, with the job_details as the message body, and the job_link as an inline keyboard button directing to the job apply link.
Click to view the send_job_posts
function
summary : Loops over the provided job post list and send each post in a separate message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
posts |
list[dict]
|
description : The list of job posts created by the telegram post creator. |
required |
bot |
TeleBot
|
description |
required |
msg |
Message
|
description : The Message Object |
None
|
channel_id |
str
|
description, by default None : The channel id. |
None
|
Source code in src/job_posts/job_post_sender.py
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 |
|
The send_job_posts
function uses the jobs_post_inline_kb
function from the keyboards module folder to create the inline keyboard.
Click to view the jobs_post_inline_kb
function
summary : This function creates the inline keyboard markup for the job links.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job_link |
str
|
description : job link URL. |
required |
Returns:
Type | Description |
---|---|
InlineKeyboardMarkup
|
description : The inline keyboard markup for the job links. |
Source code in src/tgbot/keyboards/inline/inline_keyboards.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
Using The Command¶
The ljobs
command can be used alone or with arguments (search parameters) to scrap LinkedIn jobs for last week posted jobs returning each job in a separate message with the job information and the job link for applying.
Default Search¶
If the /ljobs
command was sent in chat without any arguments or search parameters it will default to searching for BI Data Analyst Roles in Egypt like in the following GIF.
Searching With Arguments¶
The /ljob
command also supports custom job search by providing search parameters after the command in chat following the job title, location
pattern | format as demonstrated in the following GIF.
Please note that
If you don't follow the job title, location
pattern the bot will through an error telling you
that this is an invalid search pattern, specifying the correct one to follow.
Search Format | Pattern¶
The /ljob
command uses python's Regex library to verify the provided search parameters using param_validator
function in the job_commands.py
module.
The param_validator
function does the validation using the following pattern.
# Compiling the command valid pattern.
pattern = re.compile(r"\D+,\D+")
Click to view the param_validator
function
summary : This function takes in the job command parameter and validates it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameter |
str
|
description : The parameter extracted from the message. |
required |
Returns:
Type | Description |
---|---|
bool
|
description : True if is valid, False it not. |
Source code in src/tgbot/commands/job_commands.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
Here's a live example of the bot's behavior when provided with invalid parameters.