From 0a5eee28a0f4b1f08150f7aae28a24fc946647e4 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Thu, 8 Aug 2019 15:48:27 -0500 Subject: [PATCH] fix slack client usage --- scraper.py | 6 +++--- settings.py | 2 +- util.py | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scraper.py b/scraper.py index cddbca2..caa3482 100644 --- a/scraper.py +++ b/scraper.py @@ -5,7 +5,7 @@ from sqlalchemy.orm import sessionmaker from dateutil.parser import parse from util import post_listing_to_slack, find_points_of_interest -from slackclient import SlackClient +from slack import WebClient import time import settings @@ -115,7 +115,7 @@ def do_scrape(): """ # Create a slack client. - sc = SlackClient(settings.SLACK_TOKEN) + slack_client = WebClient(settings.SLACK_TOKEN) # Get all the results from craigslist. all_results = [] @@ -126,4 +126,4 @@ def do_scrape(): # Post each result to slack. for result in all_results: - post_listing_to_slack(sc, result) + post_listing_to_slack(slack_client, result) diff --git a/settings.py b/settings.py index cbe62e7..913d62a 100644 --- a/settings.py +++ b/settings.py @@ -124,4 +124,4 @@ try: from config.private import * except Exception: - pass \ No newline at end of file + pass diff --git a/util.py b/util.py index 15af261..19b3190 100644 --- a/util.py +++ b/util.py @@ -29,16 +29,18 @@ def in_box(coords, box): return True return False -def post_listing_to_slack(sc, listing): +def post_listing_to_slack(slack_client, listing): """ Posts the listing to slack. :param sc: A slack client. :param listing: A record of the listing. """ desc = "{0} | {1} | {2} | {3} | <{4}>".format(listing["area"], listing["price"], listing["bart_dist"], listing["name"], listing["url"]) - sc.api_call( - "chat.postMessage", channel=settings.SLACK_CHANNEL, text=desc, - username='pybot', icon_emoji=':robot_face:' + slack_client.chat_postMessage( + channel=settings.SLACK_CHANNEL, + text=desc, + username='pybot', + icon_emoji=':robot_face:' ) def find_points_of_interest(geotag, location):