{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-14T11:43:06.525300Z",
     "start_time": "2017-09-14T11:43:05.543036Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from dodoml.misc.googleapi import (\n",
    "    get_google_service,\n",
    "    walk_google_drive,\n",
    "    get_analytics_results)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Google drive"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-14T10:10:22.192872Z",
     "start_time": "2017-09-14T10:10:21.547343Z"
    }
   },
   "outputs": [],
   "source": [
    "# Get connection\n",
    "scope = ['https://www.googleapis.com/auth/drive']\n",
    "service = get_google_service('drive', 'v3', scope, '/Users/phi/client_secrets.json')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-14T10:10:24.428806Z",
     "start_time": "2017-09-14T10:10:23.722847Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'files': [{'id': '1A4BoH-ejlFGheK6dcUDB9ocYdf_aatE6jmXIulxBKXg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'Suivi KPI Marchés'},\n",
       "  {'id': '0B_YJ3iKN0b2SYkFJU3lmVzFnLXBOSk5BUklNaUlxTENHUVFV',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/pdf',\n",
       "   'name': 'CA - Services Digitaux Marché Pro vDef3.pdf'},\n",
       "  {'id': '0B_YJ3iKN0b2SMTFrOFZsdjBabm8',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Crédit Agricole - Marché PRO'},\n",
       "  {'id': '1UiFBP-0Ow6DeG29tXibjUiWGIPmo1KmtjE4TSgEt-HA',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'STAFFING UX LAB'},\n",
       "  {'id': '1G0-QjLT9Z7cStsofwDKmQLjNm1zWux06x8agzsO8UjA',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'Sourcing_13 09 17.xlsx'},\n",
       "  {'id': '0B6vYkDb-jNj1QmFLTU1UN3BuNHM',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.xmind.workbook',\n",
       "   'name': 'Espace Particuliers.xmind'},\n",
       "  {'id': '0B-mppvFN5p_0cFZ5MkZIeDMtT0k',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/jpeg',\n",
       "   'name': 'Espace Collectivités.jpg'},\n",
       "  {'id': '1NOcnZJndDUWq-JKkufN0ek-XtohvrhKRmd6_OJL2uxg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': 'LJN - EGC - MGEN - Growth Hacking'},\n",
       "  {'id': '0B5heeMmAzJJuX2VadUpKNEZVc1k',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'VRTUOZ client presentation v0.1.pptx'},\n",
       "  {'id': '1W-wRZxtenWWAsgxpvLEK5wG-GcoHv22P6qgbJ_UUPfs',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': 'Organigramme marché part.pptx'},\n",
       "  {'id': '1JFVP3RlmAO76SLiXMi4Yw5n0Wnc0GzUkCqNla5daa4Y',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.document',\n",
       "   'name': '14092017_EGC_PHASE AUDIT ET ANALYSE'},\n",
       "  {'id': '0B-mppvFN5p_0T0c3eEMxeEU2SW8',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Accompagnement Web'},\n",
       "  {'id': '0B8QHOkFzqhg-NGRvMmtzU09Kenc',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Eurogroup Consulting'},\n",
       "  {'id': '1PuJVgXky4Vt073B3idWdZ3J4YaM8d8ljmFjL3qCKLL4',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.document',\n",
       "   'name': 'Enedis - LJN - Projet de contrat - V1.docx'},\n",
       "  {'id': '0B_YJ3iKN0b2SMmlfZEFIdFdVUzg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n",
       "   'name': 'Enedis - LJN - Projet de contrat - V1.docx'},\n",
       "  {'id': '0B_YJ3iKN0b2SR2pBMXJ6UFhCckdreGsyUzcxa21Cb0J4aWZr',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/pdf',\n",
       "   'name': 'Enedis - Réclamation (1).pdf'},\n",
       "  {'id': '0B_YJ3iKN0b2SVTY0NnhsVXFJa2M',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': '03_Maquettes'},\n",
       "  {'id': '0B_YJ3iKN0b2SU0VlWnY4UFdDNkE',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': '02_Contrat'},\n",
       "  {'id': '0B_YJ3iKN0b2SRnNCVlBWcy1FMm8',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': '01_Propale'},\n",
       "  {'id': '1es4w8soLOjQu7rnDLWsD44X2IKe5I8idnTD5_YDyZAA',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'La Javaness - VRTUOZ - Chiffrage'},\n",
       "  {'id': '0B6vYkDb-jNj1X2tYMDhZQXgyZEE',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/octet-stream',\n",
       "   'name': \"L17090-1_Politiques-de-l'habitat_A4_2p.indd\"},\n",
       "  {'id': '0B6vYkDb-jNj1WF92c256YlViRnM',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Visuels'},\n",
       "  {'id': '0B6vYkDb-jNj1MVVIT1lrdWZjMEU',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.xmind.workbook',\n",
       "   'name': \"Suivi & mesure d'audience.xmind\"},\n",
       "  {'id': '13WDUpLLBQM7qcGAJ7dxx0SjmTgA7SU2UF_S7n6QUWEQ',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': 'chatbot arbre compte-V3.pptx'},\n",
       "  {'id': '0B6vYkDb-jNj1YXlqTVhLYzVvTDA',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Organigramme marché part.pptx'},\n",
       "  {'id': '0B2-rNcnRS4x5UG50LTBMT0E4aXM',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-analytics.rap.report',\n",
       "   'name': '[Sample] Google Merchandise Store Ecommerce Report\\xa0'},\n",
       "  {'id': '0B-mppvFN5p_0YjdFZDV6MXgwQzA',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/jpeg',\n",
       "   'name': 'Espace Entreprises.jpg'},\n",
       "  {'id': '17yZBXEHdH83AQDkFTJmhKaN9v7SuDcXXCi7fRL3CBVI',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': 'LJN - TestR - Pitch Août 2017 - FR'},\n",
       "  {'id': '0B5heeMmAzJJuQWxLdVM2TjZacjQ',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Brief design Mailbot 092017.pptx'},\n",
       "  {'id': '0B6vYkDb-jNj1Q2pEUWxBMkR5cGM',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/png',\n",
       "   'name': 'visualisation-arbo-espace-entreprises.png'},\n",
       "  {'id': '0B6vYkDb-jNj1VFV2WWNjNjZzTFk',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n",
       "   'name': 'ESPACE COLLECTIVITE.docx'},\n",
       "  {'id': '0B6vYkDb-jNj1eEl0Mmw3UU5wajg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Arborescence des espaces'},\n",
       "  {'id': '1Xo_4nEoPS_I2dAFI07tOFomHlTznTEG25AFRlB5OQE8',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.document',\n",
       "   'name': '07.09.2017_Ateliers Vision et commercialisation'},\n",
       "  {'id': '1nlpmKrsIuCY_bDwZnvk9YZlNTkGyzdb38TfyLAIUt5s',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': \"EGC - LJN - Thales - Programme d'accélération\"},\n",
       "  {'id': '0B1AlXFhV2Y4PdVdXQ3loeDRaaWM',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Lean canvas'},\n",
       "  {'id': '0B1AlXFhV2Y4PMlFOWnhMSF92Z3c',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/octet-stream',\n",
       "   'name': 'lean_canvas_A1.indd'},\n",
       "  {'id': '0B1AlXFhV2Y4PeE5hX0tXOEdabmM',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/x-font-otf',\n",
       "   'name': 'NeoSansStd-Italic.otf'},\n",
       "  {'id': '0B1AlXFhV2Y4PVnlkT1FmN2hlS3c',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/x-font-otf',\n",
       "   'name': 'NeoSansStd-Regular.otf'},\n",
       "  {'id': '0B1AlXFhV2Y4PTTRCMDlPekYxSEU',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/x-font-otf',\n",
       "   'name': 'NeoSansPro Bold.otf'},\n",
       "  {'id': '0B1AlXFhV2Y4Pd2NRTnZpOUwzYUE',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/x-zip',\n",
       "   'name': 'lean_canvas_A1.idml'},\n",
       "  {'id': '0B1AlXFhV2Y4PRDhCc1VaWHh1Wk0',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/postscript',\n",
       "   'name': 'AdobeFnt18.lst'},\n",
       "  {'id': '0B1AlXFhV2Y4PSm5FaUxWaDNBNGc',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/pdf',\n",
       "   'name': 'lean_canvasA1-TDC.pdf'},\n",
       "  {'id': '0B1AlXFhV2Y4PQkhxb2JJY0lWb1E',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/pdf',\n",
       "   'name': 'lean_canvas_A1.pdf'},\n",
       "  {'id': '0B1AlXFhV2Y4PQkY2QUNIb3Ztb1U',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/pdf',\n",
       "   'name': 'leanCanvasA1-OK.pdf'},\n",
       "  {'id': '0B1AlXFhV2Y4PNlVMM243VjJGYWs',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'text/plain',\n",
       "   'name': 'Instructions.txt'},\n",
       "  {'id': '0B1AlXFhV2Y4PeFJkcTladU1SbUE',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Document fonts'},\n",
       "  {'id': '0B1AlXFhV2Y4PNHp1a3UwSWU0Nk0',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': '_natifs-indesign'},\n",
       "  {'id': '1SKaTQ32MMbcozjOAHnLRvg4_UuJVDtuOC4ntFs-DFJg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': 'LJN - EGC - Accompagnement Marketing'},\n",
       "  {'id': '0B3PThKDheD0dN1A3R0hGM25kM3M',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n",
       "   'name': 'Sourcing_13 09 17.xlsx'},\n",
       "  {'id': '1hCrN17cbFm2eJtR16uZn2LBex_jM7hQQ8V-8U-k6LVY',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': 'Arbre Q&A V3.pptx'},\n",
       "  {'id': '0B0pVSIomrnn-U0tmcWEtLVMzcVE',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': '18072017_Enedis_Testr.pptx'},\n",
       "  {'id': '1Q7YKTkorm6uk9Vh1zyJLBl9qnW1wfuKZQrsgFQYQmMk',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'Matrice_outils.xlsx'},\n",
       "  {'id': '0B3PThKDheD0dRk5IYnUtSzNWTFk',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n",
       "   'name': 'Matrice_outils.xlsx'},\n",
       "  {'id': '0B5heeMmAzJJuOTVRMEdCeEhwT2dlS0tZWmIxQ01yQ1BJZXUw',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/pdf',\n",
       "   'name': 'dti-ai-report_final1.pdf'},\n",
       "  {'id': '0B5heeMmAzJJuNmhwSkwyRVJVbUk',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'VRTUOZ client presentation v0.2.pptx'},\n",
       "  {'id': '0B_YJ3iKN0b2SLWNSdFQ0VXVWSm8',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Mediapost'},\n",
       "  {'id': '0B3PThKDheD0dQ1dnQ2F2NnVPLVk',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Ref DATA_24 08 17.pptx'},\n",
       "  {'id': '0B1XiUtHvDS2lTFFxbC1ubExyS2JGclJoQnQ4MC1nVElteDA0',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/pdf',\n",
       "   'name': 'proposition POCDATA_Mediapost VFF maj post réunion de lancement.pdf'},\n",
       "  {'id': '0B1XiUtHvDS2lZXU2cG1zTi04emxWSzUtX3ljWC1GX3hBdkNN',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Mediapost_POC Data_Reu de lancement_V3.pptx'},\n",
       "  {'id': '0B1XiUtHvDS2ldnQtZUxnZTdkWS0tdTlSOUJadUYxMDR5QUtr',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Mediapost_POC Data_Sprint_2_transmis.pptx'},\n",
       "  {'id': '0B1XiUtHvDS2lSmJmNXNSSFp5X2JvcHZsTUZtM1hlMEM3YW93',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Mediapost_POC Data_Comex_VF (transmis).pptx'},\n",
       "  {'id': '0B1XiUtHvDS2lYkhmZV9MYmFpQkdjMldFdWdhVWktdU5nN3hB',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Mediapost_POC Data_Comex_VF.pptx'},\n",
       "  {'id': '0B1XiUtHvDS2lQWVSck10VU9GZjY1ajZ4OUc2aVNnQm1CWWFz',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Mediapost_POC Data_Sprint_1_V1 (transmis).pptx'},\n",
       "  {'id': '0B1XiUtHvDS2lVVR6dXpyUjFnMFZtSVRETWhjV19aZlVPY09J',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Mediapost_POC Data_Sprint_1_V1.pptx'},\n",
       "  {'id': '0B1XiUtHvDS2lTmdmZ2prQ3pnTktYemFrNEY5UVJoMkwxSGlR',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Mediapost_POC Data_Sprint_5 _V2.pptx'},\n",
       "  {'id': '0B1XiUtHvDS2lWTA0S0xwSjRQQ2ZaLTZoS3pGa0thNEVUNEdv',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n",
       "   'name': 'proposition POCDATA_Mediapost suite update 12 avril 2017.docx'},\n",
       "  {'id': '0B6vYkDb-jNj1NnJxeHZObzZ1Y0k',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Marché Particuliers'},\n",
       "  {'id': '0B6vYkDb-jNj1dXZBeXlhLUVYTTg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Marché Entreprises'},\n",
       "  {'id': '0B6vYkDb-jNj1SW5oWXVVZTQ0MUU',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Marché Collectivités'},\n",
       "  {'id': '0B6vYkDb-jNj1bklCYm12cWo3N3M',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Outils'},\n",
       "  {'id': '1KMe477euIXzZdYsuAveg2U1BZ4x36rLbjhw-b9Y_WgU',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': 'LJN - EGC - BabelCare - Accélération - V1'},\n",
       "  {'id': '1-eMlTY7QXcAX6u1uQoNWU1S-JohHQbPrNUtH8xvkGKA',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'Gooyave - P&L'},\n",
       "  {'id': '0B0pVSIomrnn-QVMwajJyVlROUWc',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': '00. Synthèse'},\n",
       "  {'id': '12gYZG98LB7bSaFUOjdoHlET_jnsC-z9mIzmkWbWluu0',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'Crazzyegg - Planning'},\n",
       "  {'id': '1dbXSzsua8UcwMa7EjD98-CvcndNEKRVzPl4ZJW1j99A',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.document',\n",
       "   'name': 'Objectifs, enjeux & états des lieux'},\n",
       "  {'id': '1uEcZCFzaKmm1oMIdO_nKDLZtYXZRCCL7iQRpV4csDew',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'Humanis - Happy Innov - Plan de Marquage'},\n",
       "  {'id': '0B8QHOkFzqhg-MFhOR2JWUFZid3c',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n",
       "   'name': 'SGMAC_FC_Planning.xlsx'},\n",
       "  {'id': '0B8QHOkFzqhg-MGdHZzJrMmhKdXc',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'SGMAP_FC_Plan de travail 2017_V1109 VADN.pptx'},\n",
       "  {'id': '0B6vYkDb-jNj1cUxra3pyWkJZWEk',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'video/webm',\n",
       "   'name': 'homepage-part-list.webm'},\n",
       "  {'id': '0B6vYkDb-jNj1VDUzZFF5VjljOGs',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'video/webm',\n",
       "   'name': 'creacomptes-part-list.webm'},\n",
       "  {'id': '0B6vYkDb-jNj1d2c0aC00NkRxQTg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/png',\n",
       "   'name': 'homepage-part-heatmap.png'},\n",
       "  {'id': '0B6vYkDb-jNj1MURfcmsyTThYTmc',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/png',\n",
       "   'name': 'homepage-part-scroll.png'},\n",
       "  {'id': '0B6vYkDb-jNj1aE9SYzl6YU5wbjA',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/png',\n",
       "   'name': 'creacomptes-part-scroll.png'},\n",
       "  {'id': '0B6vYkDb-jNj1QXMxaGhndkNtclE',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/png',\n",
       "   'name': 'creacomptes-part-heatmap.png'},\n",
       "  {'id': '0B6vYkDb-jNj1dTc4QWpYVEpHdzg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/png',\n",
       "   'name': 'homepage-part-confetti.png'},\n",
       "  {'id': '0B6vYkDb-jNj1RFlyNDJLQlBJazg',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'image/png',\n",
       "   'name': 'creacomptes-part-confetti.png'},\n",
       "  {'id': '0B6vYkDb-jNj1amJSWlpPeG4tQ28',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Homepage-Part-Juillet-2017'},\n",
       "  {'id': '0B6vYkDb-jNj1OHhHS2o0R3RQbE0',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'CreationComptes-Part-Juillet2017'},\n",
       "  {'id': '0B6vYkDb-jNj1cExUUlhtbTVQZVk',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Crazyegg'},\n",
       "  {'id': '0B8QHOkFzqhg-MnEwR1BkbTFaY3c',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'UGAP_Synthèse du diagnostic DMECC_20170912_V0.2.pptx'},\n",
       "  {'id': '0B5heeMmAzJJuTDk3QzB6ZFZSdUk',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n",
       "   'name': 'Script Video.docx'},\n",
       "  {'id': '0B5heeMmAzJJuWkRzSW14bVlhR1E',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Mailbot_Pitch_EN-082017.pptx'},\n",
       "  {'id': '1F_FCvNX5jEDFYF7EHd2cfrKj6-R8LKej_k181dNmtR8',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.spreadsheet',\n",
       "   'name': 'Repères conduite changement équipes pédagogiques - POC - Editorialisation et alimentation https://goo.gl/XqX7Hv'},\n",
       "  {'id': '0B6vYkDb-jNj1NjZFRWVhcDlUa2M',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.ms-excel',\n",
       "   'name': 'analyse-pages-maintenance-aout2017.xls'},\n",
       "  {'id': '0B6vYkDb-jNj1TzI2T1ZNNmtRR1E',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Technique'},\n",
       "  {'id': '0B6vYkDb-jNj1SXJnVmpGcFpqWUU',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.folder',\n",
       "   'name': 'Analyses'},\n",
       "  {'id': '0B5heeMmAzJJueS1sWHBLRTR2SnM',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n",
       "   'name': 'Predictor_Pitch-17072017.pptx'},\n",
       "  {'id': '1rOOA-3EAzv3sNPtjQ2MiFlf4kgLQY-ZwX9GecKQOnsI',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.presentation',\n",
       "   'name': 'chatbot arbre compte-V3.pptx'},\n",
       "  {'id': '1-bHR503UuvMAe8f99yg7SRIyQAzOyz86BiklhArIe88',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.document',\n",
       "   'name': 'Cond° particulieres ss 2 Guillaume.V0.doc'},\n",
       "  {'id': '10CxDxr9hCzGDzDVhGQjypYIFpDl23wyRomfPqF82rTc',\n",
       "   'kind': 'drive#file',\n",
       "   'mimeType': 'application/vnd.google-apps.document',\n",
       "   'name': 'Cond° particulieres ss 2 MH.V0.doc'}],\n",
       " 'incompleteSearch': False,\n",
       " 'kind': 'drive#fileList',\n",
       " 'nextPageToken': '~!!~AI9FV7Reh4QcITp0YTM7C6t7xBuYMKCb8yOQ2jDCptYLd4zmPivcjqqRYJECWpmd6XpjXAIsjZ9H_URFsBxsrPGhn8ooqvi9QXcONMTVhYnRANpc31yUIkN6ELpyQBxA4tm-eeQR2BEvjxQ7Uk_07zjigtLZnLdYhbY2Ge_IxUTjAaQt1DlHXN9WuPh2IClXjcwQEC_WVldbGxniDLib4b7RktU_ruOUjo-lkg6rsorjLMs-ay_5uH2SjD1wKzRv3ox5k1CuU2KFkusSJP0BowIVbAXQIjsNlRPI6asQcbk5qtgAqUlVT6pSxm4BaVU-zO6dVWxo5F9wbR1ivYMyrM_btEvNUnd73-60EQYq8usmcH9RLd8n_bae3ZOvgHDgxTbKQLIHQ6pH'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# List all files\n",
    "service.files().list().execute()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-14T10:11:46.704126Z",
     "start_time": "2017-09-14T10:11:40.912861Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LJN/LJN   9 12\n",
      "LJN/LJN/01. Propales   7 1\n",
      "LJN/LJN/02. Missions GG   61 3\n",
      "LJN/LJN/03. Startups   5 5\n",
      "LJN/LJN/04. Labs   7 0\n",
      "LJN/LJN/05. Initiatives   18 0\n"
     ]
    }
   ],
   "source": [
    "# Walk\n",
    "i = 0\n",
    "for path, root, dirs, files in walk_google_drive(service, 'LJN'):\n",
    "    print('%s   %d %d' % ('/'.join(path) + '/' + root['name'], len(dirs), len(files)))\n",
    "    i += 1\n",
    "    if i > 5:\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-14T11:25:20.050393Z",
     "start_time": "2017-09-14T11:25:20.047692Z"
    }
   },
   "source": [
    "# Google Analytics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-14T11:43:09.776231Z",
     "start_time": "2017-09-14T11:43:08.461715Z"
    }
   },
   "outputs": [],
   "source": [
    "# Get connection\n",
    "profile_id = '98944005'\n",
    "account_id = '54816004'\n",
    "scope = ['https://www.googleapis.com/auth/analytics.readonly']\n",
    "service = get_google_service('analytics', 'v3', scope, '/Users/phi/client_secrets.json')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2017-09-14T11:43:54.460035Z",
     "start_time": "2017-09-14T11:43:46.292818Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ga:dimension13</th>\n",
       "      <th>ga:Date</th>\n",
       "      <th>ga:sourceMedium</th>\n",
       "      <th>ga:browser</th>\n",
       "      <th>ga:eventsPerSessionWithEvent</th>\n",
       "      <th>ga:avgTimeOnPage</th>\n",
       "      <th>ga:uniqueEvents</th>\n",
       "      <th>ga:pageviewsPerSession</th>\n",
       "      <th>ga:pageviews</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>00CF09BD55CE4B0E1200010A01</td>\n",
       "      <td>20170205</td>\n",
       "      <td>bing / organic</td>\n",
       "      <td>Edge</td>\n",
       "      <td>6.0</td>\n",
       "      <td>150.0</td>\n",
       "      <td>5</td>\n",
       "      <td>6.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>00CF09BD55D617A43A00010801</td>\n",
       "      <td>20170207</td>\n",
       "      <td>google / organic</td>\n",
       "      <td>Chrome</td>\n",
       "      <td>4.0</td>\n",
       "      <td>275.8</td>\n",
       "      <td>4</td>\n",
       "      <td>6.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>00CF09BD55D74C26B600010801</td>\n",
       "      <td>20170205</td>\n",
       "      <td>bing / organic</td>\n",
       "      <td>Internet Explorer</td>\n",
       "      <td>12.0</td>\n",
       "      <td>62.45454545454545</td>\n",
       "      <td>11</td>\n",
       "      <td>12.0</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>00CF09BD55D97C9ABE00010801</td>\n",
       "      <td>20170204</td>\n",
       "      <td>google / organic</td>\n",
       "      <td>Internet Explorer</td>\n",
       "      <td>6.0</td>\n",
       "      <td>47.083333333333336</td>\n",
       "      <td>6</td>\n",
       "      <td>13.0</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>00CF09BD55DBB7463400010901</td>\n",
       "      <td>20170204</td>\n",
       "      <td>unica / email</td>\n",
       "      <td>Firefox</td>\n",
       "      <td>6.0</td>\n",
       "      <td>84.66666666666667</td>\n",
       "      <td>4</td>\n",
       "      <td>7.0</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>00CF09BD55E1F0E29200010801</td>\n",
       "      <td>20170201</td>\n",
       "      <td>(direct) / (none)</td>\n",
       "      <td>Firefox</td>\n",
       "      <td>4.0</td>\n",
       "      <td>31.0</td>\n",
       "      <td>4</td>\n",
       "      <td>3.0</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>00CF09BD55E1F0E29200010801</td>\n",
       "      <td>20170202</td>\n",
       "      <td>(direct) / (none)</td>\n",
       "      <td>Firefox</td>\n",
       "      <td>5.0</td>\n",
       "      <td>45.857142857142854</td>\n",
       "      <td>4</td>\n",
       "      <td>4.5</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>00CF09BD55E1F0E29200010801</td>\n",
       "      <td>20170203</td>\n",
       "      <td>(direct) / (none)</td>\n",
       "      <td>Firefox</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>00CF09BD55E1F0E29200010801</td>\n",
       "      <td>20170204</td>\n",
       "      <td>(direct) / (none)</td>\n",
       "      <td>Firefox</td>\n",
       "      <td>1.0</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>00CF09BD55E1F0E29200010801</td>\n",
       "      <td>20170205</td>\n",
       "      <td>(direct) / (none)</td>\n",
       "      <td>Firefox</td>\n",
       "      <td>17.0</td>\n",
       "      <td>65.86666666666666</td>\n",
       "      <td>12</td>\n",
       "      <td>8.5</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               ga:dimension13   ga:Date    ga:sourceMedium         ga:browser  \\\n",
       "0  00CF09BD55CE4B0E1200010A01  20170205     bing / organic               Edge   \n",
       "1  00CF09BD55D617A43A00010801  20170207   google / organic             Chrome   \n",
       "2  00CF09BD55D74C26B600010801  20170205     bing / organic  Internet Explorer   \n",
       "3  00CF09BD55D97C9ABE00010801  20170204   google / organic  Internet Explorer   \n",
       "4  00CF09BD55DBB7463400010901  20170204      unica / email            Firefox   \n",
       "5  00CF09BD55E1F0E29200010801  20170201  (direct) / (none)            Firefox   \n",
       "6  00CF09BD55E1F0E29200010801  20170202  (direct) / (none)            Firefox   \n",
       "7  00CF09BD55E1F0E29200010801  20170203  (direct) / (none)            Firefox   \n",
       "8  00CF09BD55E1F0E29200010801  20170204  (direct) / (none)            Firefox   \n",
       "9  00CF09BD55E1F0E29200010801  20170205  (direct) / (none)            Firefox   \n",
       "\n",
       "  ga:eventsPerSessionWithEvent    ga:avgTimeOnPage ga:uniqueEvents  \\\n",
       "0                          6.0               150.0               5   \n",
       "1                          4.0               275.8               4   \n",
       "2                         12.0   62.45454545454545              11   \n",
       "3                          6.0  47.083333333333336               6   \n",
       "4                          6.0   84.66666666666667               4   \n",
       "5                          4.0                31.0               4   \n",
       "6                          5.0  45.857142857142854               4   \n",
       "7                          0.0                 0.0               0   \n",
       "8                          1.0                35.0               1   \n",
       "9                         17.0   65.86666666666666              12   \n",
       "\n",
       "  ga:pageviewsPerSession ga:pageviews  \n",
       "0                    6.0            6  \n",
       "1                    6.0            6  \n",
       "2                   12.0           12  \n",
       "3                   13.0           13  \n",
       "4                    7.0            7  \n",
       "5                    3.0            6  \n",
       "6                    4.5            9  \n",
       "7                    1.0            2  \n",
       "8                    2.0            2  \n",
       "9                    8.5           17  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Retrieve\n",
    "dimensions = [\n",
    "    'ga:dimension13',\n",
    "    'ga:Date',\n",
    "    'ga:sourceMedium',\n",
    "    'ga:browser'\n",
    " ]\n",
    "metrics = [\n",
    "   'ga:eventsPerSessionWithEvent',\n",
    "   'ga:avgTimeOnPage',\n",
    "   'ga:uniqueEvents',\n",
    "   'ga:pageviewsPerSession',\n",
    "   'ga:pageviews'\n",
    "]\n",
    "date_from, date_to = '2017-02-01', '2017-02-07'\n",
    "data = get_analytics_results(service, profile_id, date_from, date_to, dimensions, metrics, cacheDir='./temp', batch=100)\n",
    "data[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
