I have a durable activity function which downloads a file from an api. The activity function receives the href for the file to download as an input.
I’d like to extract the filename part from the href and set this in the path parameter. E.g. container/directory/{filename}.txt
From the docs, I see that is possible to access input bindings but I cannot find and example for an activityTrigger.
I’m using the Python worker.
To achieve the above requirement ,
You can use os.path.basename as shown in below example:
print(os.path.basename("https://example.com/file.html"))
NOTE:- There is no such output binding available as mentioned in this Open GitHub Issue yet to use input binding please refer this MICROSOFT DOCUMENTATION.
For more information please refer this GitHub|How to set Storage Blob Filename, Content-Type, etc. on output binding?
Related
I want to use the imgkit.from_url function to download a specific Google sheet for use in my python code.
Problem is that, while access to the sheet via Google sheets api using oauth2 works just fine, in order for from_url to work I need to access the sheet like a human user would. That is logging in with username and password. I.e. I can use from_url just fine but instead of the actual sheet it creates a jpg of the Google login mask.
As a workaround I am able to download the page as a zip file to a temporary folder via export?format=zip URL parameter using the api, unzip it, find the correct html, use the imgkit.from_file function and convert it back to an byte object, but this is a lot more convoluted, requires handling temporary files/folders and also causes trouble with accessing the css file.
Since from_url allows me to circumvent a lot of steps and would work if I was able to access it, I'd very much prefer that method over from_file
I couldn't find anything online so that's why I'm posting it despite the question being simple.
I'm writing a script that download an application's binary and puts it in a file. I would like the use the PyGitHub API to retrieve some information. The problem is that I don't want to enter any credentials when accessing GitHub. I don't need to modify anything, I just want to download the latest release and get information on it. I tried to do it with request, but it's very complicated to use, especially if I only want specific files in the repo. Is there any way I can access the repo using the API without needing credentials?
You can simply pass nothing to the main class, to use the API without authenticating.
from github import Github
g = Github()
r = g.get_repo("REPO_USER/REPO_NAME")
The Link URL at the Object details in the GoogleCloudStorage browser follows the template:
https://storage.cloud.google.com/<project_name>/<file_name>?authuser=0&organizationId=<org_id>
I'm trying to get the exact same link using the python package google-cloud-storage. Diving into the blob properties I've found the followings (none of which are exactly what I need):
self_link: https://www.googleapis.com/storage/v1/b/<project_name>/o/<file_name>
media_link: https://storage.googleapis.com/download/storage/v1/b/<project_name>/o/<file_name>?generation=<gen_id>&alt=media
Note: If I replace storage.googleapis.com with storage.cloud.google.com at the media_link I get to download the file as I expect (getting asked for a valid Google Account with the required permissions).
Is there any way to get the link directly from the blob object?
Here the pattern:
https://storage.googleapis.com/<BUCJET_NAME>/path/to/file
For example, for a bucket my_bucket and a file stored in this path folder_save/2020-01-01/backup.zip, you have this url https://storage.googleapis.com/my_bucket/folder_save/2020-01-01/backup.zip
I think that the best approach is manually generate the URL that you need by replacing the domain of the URL.
In client library source I couldn’t find any reference to a method/property in the blob class that uses the domain “storage.cloud.google.com”
even using the public url property the result is the URL that points to googleapis
I'm building a dashboard in Data Studio and want to add a 'button' like feature that basically calls/runs a python function that downloads some content locally(on the client machine). I have the python function almost ready.
The question I have is where do I host this function so that it is callable from Data Studio?
Ideally, I wanted to create a Cloud function that would host the python function and get triggered when the button is clicked. This would work till this point but, will not download content locally. What options do I have to accomplish this?
Currently it is not possible to trigger Cloud Function or something similar from the Data Studio Front end, especially when you are intending to download content locally.
The only thing I can think of is, you can create a custom connector which will call the Cloud Function (via URL trigger). Then use the connector to create a data source and attach that data source to a table or chart. That way, every time that page (with the table/chart) is refreshed, the connector will call the Cloud Function and retrieve the associated data.
A function can be triggered by HTTP, so you can make it publicly available and just drop a link to it in a dashboard.
Just add a gray square around this link and make it look like a button. You may want to check the box to open the URL in a new tab, so your dashboard is not closed when the link is clicked.
I'm trying to make the hello world example work for python via azure functions. The basic function tries to retrieve a name as input through the url and then respond "Hello Name". It turns out that the example-template which is available through the azure portal does not work out of the box. The basic example looks like this:
import os
import json
postreqdata = json.loads(open(os.environ['req']).read())
response = open(os.environ['res'], 'w')
response.write("hello world from "+postreqdata['name'])
response.close()
The two environment variables req and res are paths to temporary files storing input and output from the function as json. The idea is that input passed through the url should be available in the dictionary returned by json.loads(). The only dilemma is that the file located at os.environ['req'] is empty no matter what I do.
os.path.isfile(os.environ['req'])
# Returns True so the file is located at:
# D:\local\Temp\Functions\Binding\79fcec12-baf3-470e-87c3-113f64ffcef0\req
# during the execution
I tried the Hello world JavaScript example as well which works directly out of the box on azure-functions. My python script works fine when executing in within the azure-portal, but fails when triggering it from a web browser.
The function runs on Python 2.7.13 with extension &name=MyName to the https adress.
I believe the bug is not in the script itself, but hidden in the backbone somewhere. Anyone tried the same?
The default sample you refer to (source here) accepts an http POST request, and requires your request body to be a JSON payload with a "name" property.
To access URL query parameters, we make them available to you as distinct environment variables. For example, if you send query parameter "foo", you can access it via os.environ['req_query_foo'].
I was also having this issue.
The example at this link says to test it with a url of type
https://<app_name>.azurewebsites.net/api/MyHttpTrigger?name=<yourname>
When testing locally this format works, but I finally figured out that when testing once deployed that the link it gives in the command line of type
https://<appname>.azurewebsites.net/api/MyHttpTrigger?code=<randomcode>/<randomcode>==
is what you really need. Add on your &name=<yourName> to this link instead. Mine worked for
https://<appname>.azurewebsites.net/api/MyHttpTrigger?code=<randomcode>/<randomcode>==&name=<yourName>
Not sure if you have already tried this since your question wasn't entirely clear, but hope this helps.