Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Created September 3, 2016 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsBergqvist/cb6c4ba3236ab32e8d92e7ba3d9e57c9 to your computer and use it in GitHub Desktop.
Save LarsBergqvist/cb6c4ba3236ab32e8d92e7ba3d9e57c9 to your computer and use it in GitHub Desktop.
Example on parsing the arguments to the start script for Python Flask
import sys, getopt
from basic_auth import app
def main(argv):
user = ''
password = ''
try:
opts, args = getopt.getopt(argv,"u:p:")
except getopt.GetoptError:
printHelp()
sys.exit(2)
for opt, arg in opts:
if opt in ("-u"):
user = arg
elif opt in ("-p"):
password = arg
if len(user) == 0 or len (password) == 0:
printHelp()
sys.exit(0)
print('User name is:', user)
print('Password is:', password)
app.config['USERNAME']=user
app.config['PASSWORD']=password
def printHelp():
print('Usage: ',__file__,'-u <user name> -p <password>')
if __name__ == '__main__':
main(sys.argv[1:])
context = ('ssl.cert', 'ssl.key')
app.run(host='0.0.0.0', port=80, ssl_context=context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment