So I'm building a quite simple script which I originally built on bash but I want to reuse it on multiple platforms so I decided to do it in python. I did get it working in bash and I got the querying using JMESPath working but Python seems to complain about quoting. Or at least that's what I think it's the issue, so couple of other pair of eyes would be really appreciated to point me to the issue please.
Here's the code:
from azure.cli.core import get_default_cli as azcli
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
#extensions = [".jpg", ".pdf"]
storageAccounts = []
while True:
selected = input ("Enter the storage account names one per line, when ready to continue type 'done': ")
if selected.lower() == "done":
break
elif not selected:
print (f"{selected}")
continue
storageAccounts.append(selected)
print ("Selected accounts:")
for account in storageAccounts:
print(account)
print (f"these are the selected accounts {storageAccounts}")
date = input("Enter the date you want to query from in the YYYY-MM-DD format: ")
for blobs in storageAccounts:
azcli().invoke(['storage', 'blob', 'list',
'--account-name ', '%s' % blobs ,
'--container-name ' , 'backup',
'--num-results', "*",
'--auth-mode', 'key',
'--output', 'table',
'--query', "[?properties.creationTime>=\'%s\'.{name:name, created:properies.creationTime}" % date])
so when it's going to the last line which is the JMESPath query it says that it's an invalid jmespath_type value. I tried escaping the single quotes, I tried also single quoting the whole query but none seem to work and I am sure it's something stupid that I am missing but it already frustrated me enough! :(
Here's the output and the error:
Selected accounts:
account1
account2
Enter the storage account names one per line, when ready to continue type 'done': done
these are the selected accounts ['account1', 'account2']
Enter the date you want to query from in the YYYY-MM-DD format: 2022-02-15
argument --query: invalid jmespath_type value: "[?properties.creationTime>='2022-02-15'.{name:name, created:properies.creationTime}"
To learn more about --query, please visit: 'https://learn.microsoft.com/cli/azure/query-azure-cli'
Process finished with exit code 2
OS - Windows 10
IDE - PyCharm 2021.3.2 (Community Edition)
Python - 3.9.10