-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcraft_response.py
More file actions
40 lines (34 loc) · 1.32 KB
/
craft_response.py
File metadata and controls
40 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
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
36
37
38
39
40
import os
class CraftResponse:
def __init__(self):
self.response = ""
def get_links(self, data):
self.response = ""
fields = data['data']
artist = fields['artists'][0]
album_name = fields['name']
links = fields['links']
spotify = ''
googleplay = ''
applemusic = ''
if 'spotify' in links:
spotify = links['spotify'][0]['link']
if 'googleplay' in links:
googleplay = links['googleplay'][0]['link']
if 'itunes' in links:
applemusic = self.format_apple_link(links['itunes'][0]['link'], "ca")
self.response += "The Linked Album is {} by {}\n".format(album_name, artist['name'])
self.response += "Spotify Link: {}\n".format(spotify)
self.response += "Google Play Link: {}\n".format(googleplay)
self.response += "Apple Music Link: {}\n".format(applemusic)
return { 'response_type': 'in_channel', 'text': self.response }
def format_apple_link(self, link, country):
pre = link.split("{")[0]
post = link.split("}")[1]
return pre + country + post
def init_response(self):
return {
'token': os.environ.get('TOKEN'),
'challenge': request.json['challenge'],
'type': 'url_verification'
}