Skip to content

Commit

Permalink
Helps if I understand multi-line f strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Christensen committed Jun 5, 2019
1 parent 8dc4340 commit 3d73704
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions slappd/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ def fetch_untappd_activity():
request.encoding = 'utf-8'
return request.json()
except requests.exceptions.Timeout:
sys.exit(f"Error: Untappd API timed out after "
"{CONFIG['untappd']['timeout']} seconds")
sys.exit("Error: Untappd API timed out after "
f"{CONFIG['untappd']['timeout']} seconds")
except requests.exceptions.RequestException:
sys.exit('Error: There was an error connecting to the Untappd API')


def fetch_url(method):
""" Returns an API url with credentials inserted """
return (f"https://api.untappd.com/v4/{method}?"
"client_id={CONFIG['untappd']['id']}&"
"client_secret={CONFIG['untappd']['secret']}&"
"access_token={CONFIG['untappd']['token']}&"
"min_id={CONFIG['untappd']['lastseen']}")
f"client_id={CONFIG['untappd']['id']}&"
f"client_secret={CONFIG['untappd']['secret']}&"
f"access_token={CONFIG['untappd']['token']}&"
f"min_id={CONFIG['untappd']['lastseen']}")


def get_cfg_path():
Expand Down Expand Up @@ -143,8 +143,8 @@ def slack_message(images=None, msg_type=None, text=None):
}]

try:
requests.post(f"https://hooks.slack.com/services/"
"{CONFIG['slack']['token']}", json=payload)
requests.post("https://hooks.slack.com/services/"
f"{CONFIG['slack']['token']}", json=payload)
except requests.exceptions.RequestException:
sys.exit('Error: There was an error connecting to the Slack API')

Expand Down Expand Up @@ -178,8 +178,8 @@ def main():
# If any users earned badges, let's send individual messages
for badge in checkin['badges']['items']:
title = (f"{checkin['user']['first_name']} "
"{checkin['user']['last_name']} earned the "
"{badge['badge_name']} badge!")
f"{checkin['user']['last_name']} earned the "
f"{badge['badge_name']} badge!")
images['icon_url'] = badge['badge_image']['sm']
images['thumb_url'] = badge['badge_image']['md']
images['title'] = title
Expand All @@ -202,16 +202,11 @@ def main():
media = checkin['media']['items'].pop()
images['image_url'] = media['photo']['photo_img_md']
images['title'] = checkin['beer']['beer_name']
slack_message(
images=images,
msg_type='photo',
text=text)
slack_message(images=images, msg_type='photo', text=text)
text = ''
# We're sending regular check-ins one at a time this execution
elif not defer_sending:
slack_message(
images=images,
text=text)
slack_message(images=images, text=text)
text = ''

# We're not deferring, so lump all the messages together
Expand All @@ -228,8 +223,8 @@ def main():
elif data['meta']['error_type'] == 'invalid_limit':
sys.exit('Error: Untappd API rate limit reached, try again later')
else:
sys.exit(f"Error: Untappd API returned http code "
"{data['meta']['code']}")
sys.exit("Error: Untappd API returned http code "
f"{data['meta']['code']}")


if sys.version_info >= (3, 6):
Expand Down

0 comments on commit 3d73704

Please sign in to comment.