Share
Embed
Savage Garden Hotline
A show and tell of my personal project.
I built a hotline that when called, caller will hear my favorite song from Savage Garden, and my twitter bot will tweet about it.
The project is built using Python 3.6. It uses aiohttp library, Twython library, Twilio service, and deployed to Heroku.
Mariatta
October 19, 2017
Transcript
48 slides
-
SAVAGE GARDEN HOTLINE Python-powered @Mariatta Code and Coffee YVR -
Oct 2017 +1-604-706-2558 -
NATIONAL RICK ASTLEY HOTLINE Paul Fenwick’s Australia: +61-3-8652-1453 New Zealand:
+64-9-886-0565 UK: +44-11-7325-7425 USA: +1-760-706-7425 https://github.com/pjf/rickastley -
Building the Hotline • Phone Number • MP3 • Webservice
• Twitter bot -
Building the Hotline • Phone Number • MP3 • Webservice
• Twitter bot Python 3.6 -
Twilio Python API from twilio.twiml.voice_response import VoiceResponse def hello_world(): resp
= VoiceResponse() resp.say("Hello world.") return str(resp) -
aiohttp from aiohttp import web from twilio.twiml.voice_response import VoiceResponse async
def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.say("Hello world.") return web.Response(text=str(response)) app = web.Application() app.router.add_get('/', handle) web.run_app(app) http://aiohttp.readthedocs.io/ server.py -
web: python3 -m server Web process failed to bind to
$PORT within 60 seconds of launch Procfile ☠ 500 -
make it work server.py import os from aiohttp import web
from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.say("Hello world.") return web.Response(text=str(response)) app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) -
make it work server.py import os from aiohttp import web
from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.say("Hello world.") return web.Response(text=str(response)) app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) 200 -
play the music server.py import os from aiohttp import web
from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.say("Hello world.") return web.Response(text=str(response)) app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) -
play the music server.py import os from aiohttp import web
from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.play("https://s3.ca-central-1.amazonaws.com/strangerelationship/ Savage+Garden+-+Crash+And+Burn.mp3") return web.Response(text=str(response)) app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) -
play the music server.py import os from aiohttp import web
from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.play("https://s3.ca-central-1.amazonaws.com/strangerelationship/ Savage+Garden+-+Crash+And+Burn.mp3") return web.Response(text=str(response)) app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) 200 -
play the music server.py import os from aiohttp import web
from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.play("https://s3.ca-central-1.amazonaws.com/strangerelationship/ Savage+Garden+-+Crash+And+Burn.mp3") return web.Response(text=str(response)) app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) 200 -
make it work (for real) server.py import os from aiohttp
import web from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.play("https://s3.ca-central-1.amazonaws.com/strangerelationship/ Savage+Garden+-+Crash+And+Burn.mp3") return web.Response(text=str(response), content_type='application/xml') app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) -
make it work (for real) server.py import os from aiohttp
import web from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.play("https://s3.ca-central-1.amazonaws.com/strangerelationship/ Savage+Garden+-+Crash+And+Burn.mp3") return web.Response(text=str(response), content_type='application/xml') app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) 200 -
make it work (for real) server.py import os from aiohttp
import web from twilio.twiml.voice_response import VoiceResponse async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.play("https://s3.ca-central-1.amazonaws.com/strangerelationship/ Savage+Garden+-+Crash+And+Burn.mp3") return web.Response(text=str(response), content_type='application/xml') app = web.Application() app.router.add_get('/', handle) port = os.environ.get("PORT") if port is not not None: port = int(port) web.run_app(app, port=port) 200 -
the GET request at=info method=GET path="/? Called=%2B16047062558&ToState=BC&CallerCountry=CA&Direction=inbound&CallerStat e=BC&ToZip=&To=%2B16047062558&CallerZip=&ToCountry=CA&ApiVersion=2010-04-01&Ca lledZip=&CalledCity=Vancouver&CalledCountry=CA&CallerCity=NEW+WESTMINSTER&From Country=CA&ToCity=Vancouver&FromCity=NEW+WESTMINSTER&CalledState=BC&FromZip=&F
romState=BC" host=crashandburnhotline.herokuapp.com request_id=e162d82f-94dc-43be-8b5b-f6d864161bb5 fwd="54.144.213.39" dyno=web.1 connect=0ms service=269ms status=200 bytes=370 protocol=https -
the GET request at=info method=GET path="/? Called=%2B16047062558&ToState=BC&CallerCountry=CA&Direction=inbound&CallerStat e=BC&ToZip=&To=%2B16047062558&CallerZip=&ToCountry=CA&ApiVersion=2010-04-01&Ca lledZip=&CalledCity=Vancouver&CalledCountry=CA&CallerCity=NEW+WESTMINSTER&From Country=CA&ToCity=Vancouver&FromCity=NEW+WESTMINSTER&CalledState=BC&FromZip=&F
romState=BC" host=crashandburnhotline.herokuapp.com request_id=e162d82f-94dc-43be-8b5b-f6d864161bb5 fwd="54.144.213.39" dyno=web.1 connect=0ms service=269ms status=200 bytes=370 protocol=https -
twitter bot Register an APP at https://dev.twitter.com/apps Access level: Read
and write Receive API token & secret -
Twython server.py from twython import Twython twitter = Twython( os.getenv("TW_API_KEY"),
os.getenv("TW_API_SECRET"), os.getenv("TW_ACCESS_TOKEN"), os.getenv("TW_TOKEN_SECRET")) ) async def handle(request): """Respond to incoming requests.""" response = VoiceResponse() response.play("https://s3.ca-central-1.amazonaws.com/ strangerelationship/Savage+Garden+-+Crash+And+Burn.mp3") twitter.update_status(status="Thanks for dialing in.") return web.Response(text=str(response), content_type='application/xml') https://twython.readthedocs.io/ -
THANK YOU! @Mariatta Code and Coffee YVR - Oct 2017
Savage Garden Hotline: +1-604-706-2558 https://github.com/Mariatta/crash_and_burn_hotline/