Running Python script from Azure WebJob

后端 未结 1 1108
天命终不由人
天命终不由人 2020-12-18 05:42

I\'m trying to run python script from Azure webjob. This is what I\'ve done following this link

  1. Access the kudu tool via the url https://
相关标签:
1条回答
  • 2020-12-18 06:15

    I tried to realize your needs with Python in WebJob and successfully make it works.

    Here is my steps and sample code. My local environment is Python 3.7 on Windows 10.

    1. Create a Python virtual environment and install python-telegram-bot package via commands as below.

      $ mkdir telegram-webjob
      $ virtualenv telegram-webjob
      $ cd telegram-webjob
      $ Scripts\active
      $ pip install python-telegram-bot
      $ pip freeze
      

    2. I changed your code as my sample code, then run it works fine on local, as below.

      import telegram
      from datetime import datetime as dt
      
      my_token = '<my token>'
      bot = telegram.Bot(token = my_token)
      
      chat_id = '<chat id>'
      message = f"Hello at {dt.now()}"
      bot.sendMessage(chat_id=chat_id, text=message)
      

    3. I created a new directoy named webjob and copy my trading.py file and all directories with their files into it, as below.

    4. Write the startup bat script named run.bat, the code as below.

      D:\home\python364x86\python.exe trading.py
      

      The D:\home\python364x86\python.exe path is the python364x86 site extension installed path as the figure below.

    5. Then, I packaged the all directories and files in the webjob directory as a zip file, as below.

    6. I uploaded it to Azure WebApp as a webjob, as the figure below, and start it.

    Finally, it works fine for me and I can see the message interval 10 sec displayed in my telegram client.

    0 讨论(0)
提交回复
热议问题