Track REST API calls using google analytics/ - python

I want to track which resources are popular using the data from google analytics.
Is this possible with google analytics?

Is there a specific reason you would like to use google analytics?
You can instead log it to a log file with the python logging module.
You can also write it to a database (use FireBase for free if you are only counting).
Alternatively see this SO question.

Related

How to Trigger blob dataset as an input to a python code?

I have a requirement where I have to trigger a dataset in a blob to my python code where processing will happen and then store the processed dataset to the blob? Where should I do it? Any notebooks?
Azure functions dont have an option to write a Python code.
Any help would be appreciated.
Depending on your design, you could create 2 processes. The first one will search the data for whatever should "trigger", then notify the second processes of the "trigger" so it can read and modify the data.
You can work with the blob using python like the examples in azures docs.
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python
More info from this post:
Azure Blob - Read using Python
from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='myaccount', account_key='mykey')
block_blob_service.get_blob_to_path('mycontainer', 'myblockblob', 'out-sunset.png')
Azure Functions have support Python in preview, which is based on Linux. You can see the wiki page Azure Functions on Linux Preview to know about it.
Note
Python for Azure Functions is currently in preview. To receive important updates, subscribe to the Azure App Service announcements repository on GitHub.
There are two documents to introduce how to develop Azure Functions using Python.
Create your first Python function in Azure (preview)
Azure Functions Python developer guide
You need to follow the documents above to use Azure CLI to run the command func new and select Blob Trigger to create an Azure Functions for Python to satisfy your requirement.
You should also consider logic apps, which allows you to automate some of the tasks,and includes several actions on data sets. Please add more details to your question to get a more accurate answer to your request.
New Edit:
There is support of Python 3.0 in preview for Azure functions,per the following post
Also, steps on where you can store your code in functions can be found here

Upload and retrieve files from Google Cloud Storage/ Buckets in Python/Django

I want to upload and retrieve file (that includes image and csv) for my django application.
My project is currently hosted on Google App Engine Flexible. From my understanding, I need to use Google Cloud Buckets for the process. But I could not find relevant material online for the process.
GoogleAppEngineCloudStorageClient API also provides the feature of writing a file and reading it:
cloudstorage.open(filename, mode='r', content_type=None, options=None, read_buffer_size=storage_api.ReadBuffer.DEFAULT_BUFFER_SIZE, retry_params=None)
Please point me to the relevant resources for the same. Since I am new to Django and Google Cloud, I would really appreciate if you could share code snippets with me.
Thanks in advance.
Check the Google storage section of Django Storages. It may help to read generally about the storage system used in Django before going to Google storage in detail.
As per the official documentation of Google App Engine Flexible, you can configure upload and retrieve files in different runtimes environments. I went through the documentation and I found that you need to create a Cloud Storage bucket in order to stock your files.Keep in mind that it's only for static content. I recommend to take a look at this documentation where you may find valuable information.
Please let me know how it goes.

Which is the correct api to interact with google spreadsheets in python?

I've found two different APIs to interact with google spreadsheets, but don't know which is the one I should use.
I found these two:
1. google-api-python-client: http://github.com/google/google-api-python-client
2. gdata-python-client: https://code.google.com/p/gdata-python-client/
I thought the first one was the correct one but I can't find the way to get a spreadsheet's content.
By 'correct' I mean 'able to upload a new spreadsheet and modify or delete an existing one'.
Thanks for your help.
The Google API Python Client and the Google Data Python Client can access different APIs. As far as I understand, Google is migrating older APIs of their services to provide developers a clean and unified access to all services.
Google API Python Client is newer and meant for the newer Google API, including Google Drive API, which allows you to create/delete spreadsheets for example or access meta-data of spreadsheets. You cannot modify the content of these files. This library supports oAuth 2 for authentication, including service-accounts.
Google Data Python Client is much older and a little bit outdated and cumbersome. It provides you with access to the (older) Google Data API, including Google Spreadsheets API 3.0, which allows you to add/remove worksheets to/from a spreadsheet, querying or adding rows or cells, or modifying cells/rows. However, the Google Data API and so the Spreadsheets API feel very different from the other APIs, especially the newer ones.
Some tips: For spreadsheets, you will find many examples using the older SpreadsheetService, but I think the Service class restricts you to oAuth 1. For oAuth 2 you would need to use the newer SpreadsheetClient class. They also have different method names and some concepts are different too. If you don't want to use a normal Google user account, but need to use a service account (with a p12 file created in the developer console), you can find a working code pattern here.
UPDATE: You may also want to have a look into the gspread library. It's supposed to be much easier than gdata, but I haven't figured out yet oAuth2 service account authorizations with that one.

How can I query Google's Safebrowsing API to check a URL with Python?

I have a list of domains that I need to check for malware. Is there a way I could use Python to query Google's Safebrowsing API to get that information without the need for a database?
Google's Safe Browsing API page contains a Python reference client, take a look at that.

Is it possible to update a Google calendar from App Engine without logging in as the owner?

I'd like to be able to use the Google Data API from an AppEngine application to update a calendar while not logged in as the calendar's owner or the a user that the calendar is shared with. This is in contrast to the examples here:
http://code.google.com/appengine/articles/more_google_data.html
The login and password for the calendar's owner could be embedded in the application. Is there any way to accomplish the necessary authentication?
It should be possible using OAuth, i havent used it myself but my understanding is the user logs in and then gives your app permission to access their private data (e.g. Calendar records). Once they have authorised your app you will be able to access their data without them logging in.
Here is an article explaining oauth and the google data api.
http://code.google.com/apis/gdata/articles/oauth.html
It's possible to use ClientLogin as described here:
http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Response
Note the section at the bottom of the document that mentions handling a CAPTCHA challenge.
There's example code included in the gdata python client in
samples/calendar/calendarExample.py
You need to call run_on_app_engine with the right arguments to make this work as described in the Appendix here:
http://code.google.com/appengine/articles/gdata.html
Note that the same document recommends against using ClientLogin for web apps. Using OAuth or AuthSub is the correct solution, but this is simpler and good enough for testing.

Categories