-
Notifications
You must be signed in to change notification settings - Fork 0
/
shazam_lambda.py
62 lines (38 loc) · 1.48 KB
/
shazam_lambda.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import tweepy
import json
import logging
from cm_config import config
from cm_api import *
from helper_funct import *
from twitter_bot import *
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def tweet(event, context):
#################################################
rt = config['refresh_token']
api_token = get_api_token(rt)
################################################
#generate today's date to make api call with
date = generate_today_date()
#collects title, artist, velocity, and artist id for most viral shazam track
title, artist, velocity, artist_id = get_shazam_most_viral_track(api_token,date, country_code='US')
hashartist = artist.replace(" ", "",)
#get spotify url for artist
spot_url = get_spotify_url(api_token, artist_id)
message = "'{}' by #{} is catching alot of people's attention this past week on #shazam\nSo much so that its average change in rank over 7-days is {}\n#dataanalysis #velocity #viral Powered by @Chartmetric\n{}".format(title, hashartist, round(velocity, 2), spot_url)
#instantiatiate twitter bot object
bot = instantiate_twitter_bot()
bot.update_status(message)
#instantiatiate twitter bot object
bot = instantiate_twitter_bot()
bot.update_status(message)
body = {
"message": message,
"input": event
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
logger.info(message)
return response