Porting api.ai to Glitch (previously Heroku) - How to configure app.run and port var for Glitch using Python[Flask]


#1

Greetings // Glitch Community

I’m from Accenture Team at Google [ Test/Support for api(dot)ai ]

Task-at-hand //

** (currently uses Heroku)

In Glitch //

  • I went ahead and Remixed python-flask(dot)glitch(dot)me to get Flask up on Glitch – It works! Yay Glitch!
  • I added the following dependency to my remix [ within requirements.txt ] called future 0.16.0
    learn about future at pypi(dot)python(dot)org/pypi/future

Observations //

My Remix is currently public at API.ai Webhook and I’m about to test it . . .

Differences from Heroku // Within the following if statements block . . .

  • port var is assigned return of int( os.getenv(...) )
  • ignoring print call in this topic
  • app.run is called with three params

Reference statement // for Differences . . .

if __name__ == '__main__':

 port = int(os.getenv('PORT', 5000))

 print("Starting app on port %d" % port)

 app.run(debug=False, port=port, host='0.0.0.0')

Differences from Heroku // Within the following if statements block . . .

  • app.run is called with no params (for pure Python-Flask implementation not using external api)

if __name__ == "__main__":

 app.run()

Questions //

Is there a proper/preferred way using Glitch to assign a value to a port var?

Is there a proper/preferred way using Glitch to call app.run for this implementation? With and/or Without params?


#2

Hey st-fresh,

Glitch will technically work with python - but only 2.7, which I think treats print differently, among other things.

The supported and recommended server-side language is Node only, for community and feature development reasons (see: Putting multi-language support on hold for more details).