Skip to content

Commit

Permalink
[feat]: Slack Bot Added and .env file added
Browse files Browse the repository at this point in the history
  • Loading branch information
keenborder786 committed May 16, 2023
1 parent d6524be commit 7ec4861
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Upwork SlackBot
# Upwork SlackBot

## TO-DO
7 changes: 6 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import os
from dotenv import load_dotenv

load_dotenv()
CONSUMER_KEY = os.environ['CONSUMER_KEY']
CONSUMER_SECRET = os.environ['CONSUMER_SECRET']
QUERY = os.environ['QUERY']
QUERY = os.environ['QUERY']
SLACK_BOT_TOKEN = os.environ['SLACK_BOT_TOKEN']
SLACK_APP_TOKEN = os.environ['SLACK_APP_TOKEN']
CHANNEL_ID = os.environ['CHANNEL_ID']
12 changes: 12 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from slack_bot import Slackbot
from upwork_bot import UpworkBot
from config import (
QUERY,
SLACK_APP_TOKEN,CHANNEL_ID)
slack_bot = Slackbot(SLACK_APP_TOKEN,CHANNEL_ID)
upwork_bot = UpworkBot(QUERY)

html_data = upwork_bot.get_data()
jobs_data = upwork_bot.parse_data(html_data)
formatted_response = upwork_bot.format_data(jobs_data)
slack_bot.send_update(formatted_response)
1 change: 1 addition & 0 deletions slack_bot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from slack_bot.bot import Slackbot
32 changes: 32 additions & 0 deletions slack_bot/bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from slack_bolt import App
from slack.errors import SlackApiError
from slack_bolt.adapter.socket_mode import SocketModeHandler




class Slackbot:
def __init__(self, slack_app_token,channel_id):
"""
"""
self.app = App(token=slack_app_token)
# ID of channel you want to post message to
self.channel_id = channel_id
def send_update(self,message_payload):
"""
"""
try:
# Call the conversations.list method using the WebClient
result = self.app.client.chat_postMessage(
channel=self.channel_id,
text = message_payload,
mrkdwn=True
)
except SlackApiError as e:
print(f"Error: {e}")
2 changes: 0 additions & 2 deletions upwork/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions upwork_bot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from upwork_bot.bot import UpworkBot
from upwork_bot.client import Client
15 changes: 13 additions & 2 deletions upwork/bot.py → upwork_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bs4 import BeautifulSoup


class Bot:
class UpworkBot:
def __init__(self,query):
self.query = query
def get_data(self):
Expand All @@ -27,4 +27,15 @@ def parse_data(self, html_data):
jobs_data = {}
for job in job_list:
jobs_data[job.find('a')['href']] = job.text
return jobs_data
return jobs_data

def format_data(self,jobs_data):
"""
"""
job_formatted_list = f"*Following are the new {self.query} jobs that have been posted* \n"
for job_link,job_text in jobs_data.items(): job_formatted_list += f" - https://www.upwork.com{job_link} \n"
return job_formatted_list
File renamed without changes.

0 comments on commit 7ec4861

Please sign in to comment.