Advertisement
MELAMOURI

Untitled

May 12th, 2023
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1.  
  2. import azure.functions as func
  3. import datetime
  4. import logging
  5. def main(req: func.HttpRequest) -> func.HttpResponse:
  6.     logging.info('Python HTTP trigger function processed a request.')
  7.  
  8.     name = req.params.get('name')
  9.     id = req.params.get('id')
  10.  
  11.     if not name:
  12.         try:
  13.             req_body = req.get_json()
  14.         except ValueError:
  15.             pass
  16.         else:
  17.             name = req_body.get('name')
  18.  
  19.     if not id:
  20.         try:
  21.             req_body = req.get_json()
  22.         except ValueError:
  23.             pass
  24.         else:
  25.             id = req_body.get('id')
  26.  
  27.     if name and id:
  28.         current_time = datetime.datetime.now().strftime("%Y-%m-%d")
  29.         response_message = f" {id}{name} {current_time} "
  30.         return func.HttpResponse(response_message)
  31.     else:
  32.         return func.HttpResponse(
  33.              "Need query string",
  34.              status_code=400
  35.         )
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement