Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
fix slack client usage
Browse files Browse the repository at this point in the history
  • Loading branch information
echentw committed Aug 8, 2019
1 parent bf0dc59 commit 0a5eee2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = []
Expand All @@ -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)
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@
try:
from config.private import *
except Exception:
pass
pass
10 changes: 6 additions & 4 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0a5eee2

Please sign in to comment.