Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Savage Garden Hotline

Mariatta
October 19, 2017

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
Tweet

More Decks by Mariatta

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. web: python3 -m server Web process failed to bind to

    $PORT within 60 seconds of launch Procfile ☠ 500
  4. 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)
  5. 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
  6. MP3

  7. MP3

  8. 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)
  9. 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)
  10. 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
  11. 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
  12. 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)
  13. 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
  14. 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
  15. 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/
  16. THANK YOU! @Mariatta Code and Coffee YVR - Oct 2017

    Savage Garden Hotline: +1-604-706-2558 https://github.com/Mariatta/crash_and_burn_hotline/