From 7bb2e269eb70f9eb6af4d24b7f87cee90b4b20db Mon Sep 17 00:00:00 2001 From: Google Code Exporter Date: Fri, 7 Aug 2015 03:50:10 -0400 Subject: [PATCH] Migrating wiki contents from Google Code --- ProjectHome.md | 1 + Running.md | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 ProjectHome.md create mode 100644 Running.md diff --git a/ProjectHome.md b/ProjectHome.md new file mode 100644 index 0000000..fa188d7 --- /dev/null +++ b/ProjectHome.md @@ -0,0 +1 @@ +This project provides an easy way to automate downloading of data tables from Google Webmaster Tools. \ No newline at end of file diff --git a/Running.md b/Running.md new file mode 100644 index 0000000..14d2247 --- /dev/null +++ b/Running.md @@ -0,0 +1,70 @@ +How to download a file from Google Webmaster Tools. + +# Introduction # + +This documentation explains how to automate the file download process from Google Webmaster Tools by using the python script downloader.py. + +# Details # +The steps for running this example script are as follows: + + 1. Download and install the Google Data APIs Python Client Library. + 1. Create a folder and add the downloader.py script to it. + 1. In the same folder where you added downloader.py, create and run the following Python script. You’ll need to replace the example values for “website”, “email” and “password” with valid values for your site. + +``` +#!/usr/bin/python + +# Import the downloader +from downloader import Downloader + +# Email address and password used to sign-in to Webmaster Tools +email = 'user@example.com' +password = '********' +# Specify the website and the type of data to download +website = 'http://www.example.com/' +selected_downloads = ['TOP_QUERIES'] + +# Instantiate the downloader object +downloader = Downloader() +# Authenticate with your Webmaster Tools sign-in info +downloader.LogIn(email, password) +# Initiate the download +downloader.DoDownload(website, selected_downloads) +``` + +Here is a more advanced example of how to automatically download a file, then upload it to Google Docs. +``` +#!/usr/bin/python + +# Import the downloader +from downloader import Downloader +# Import gdata objects for uploading files to Google Docs +import gdata.docs +import gdata.docs.service + +# Email address and password used to sign-in to Webmaster Tools and Google Docs +email = 'user@example.com' +password = '********' +# Specify the website and the type of data to download +website = 'http://www.example.com/' +selected_downloads = ['TOP_QUERIES'] + +# Instantiate the downloader object +downloader = Downloader() +# Authenticate with your Webmaster Tools sign-in info +downloader.LogIn(email, password) +# Initiate the download +downloader.DoDownload(website, selected_downloads) + +# Create a client class which will make HTTP requests with Google Docs server +gd_client = gdata.docs.service.DocsService() +# Authenticate using your Google Docs sign-in info +gd_client.ClientLogin(email, password) + +# Get the csv file name that was generated by the downloader script and use it to upload the file to Google Docs +for line in downloader.GetDownloadedFiles(): + ms = gdata.MediaSource(file_path=line.strip(), content_type=gdata.docs.service.SUPPORTED_FILETYPES['CSV']) + entry = gd_client.Upload(ms, line.strip()) + # Display the URL of the uploaded file to the command line's standard-output + print 'Spreadsheet now accessible online at:', entry.GetAlternateLink().href +``` \ No newline at end of file