google-csv-helper

A simple tool that takes CSV reports from Google Adsense, Google Admob, and Google Analytics and outputs them in JSON / Pandas.DataFrame format.


Keywords
python, google, csv, adsense, admob, report
License
MIT
Install
pip install google-csv-helper==1.2.5

Documentation

google-csv-helper

PyPI

A simple tool for parsing google csv files.

Installation

% pip install google-csv-helper

Usage

% tree csv 
csv
├── admob
│   └── hk
│       └── latest-day.csv
└── adsense
    ├── cn
    │   └── latest-day.csv
    └── hk
        └── latest-day.csv

6 directories, 3 files

% file csv/admob/hk/latest-day.csv 
csv/admob/hk/latest-day.csv: Unicode text, UTF-16, little-endian text

% iconv -f UTF-16 -t UTF-8 csv/admob/hk/latest-day.csv | head -n1
æ—Ĩ期	預äŧ°æ”ļį›Š (USD)	č§€å¯Ÿåˆ°įš„有效千æŦĄæ›å…‰å‡ē僚 (USD)	čĢ‹æą‚	åĒ’合įŽ‡ (%) (%)	比對成功įš„čĢ‹æą‚	éĄ¯į¤ēįŽ‡ (%) (%)	曝光	éģžé–ąįŽ‡ (%) (%)	éģžæ“ŠæŦĄæ•¸	å‡ē僚čĻæą‚	åƒčˆ‡įĢļ僚įš„å‡ē僚 (%)	åƒčˆ‡įĢļ僚įš„å‡ē僚	勝å‡ēå‡ē僚 (%)	勝å‡ēå‡ē僚æŦĄæ•¸

% file csv/adsense/hk/latest-day.csv 
csv/adsense/hk/latest-day.csv: CSV text

% head -n1 csv/adsense/hk/latest-day.csv 
æ—Ĩ期,預äŧ°æ”ļį›Š (USD),į€čĻŊ量,įļ˛é åƒæŦĄæ›å…‰æ”ļį›Š (USD),曝光æŦĄæ•¸,曝光千æŦĄæ›å…‰æ”ļį›Š (USD),Active View 可čĻ–įŽ‡,éģžæ“Š,éģžé–ąįŽ‡,å–ŽæŦĄéģžæ“Šå‡ē僚 (USD)

% head -n1 csv/adsense/cn/latest-day.csv
æ—Ĩ期,äŧ°įŽ—æ”ļå…Ĩ (USD),įŊ‘éĄĩæĩč§ˆé‡,įŊ‘éĄĩ RPM (USD),åą•į¤ēæŦĄæ•°,每千æŦĄåą•į¤ēæ”ļå…Ĩ (USD),Active View å¯č§įŽ‡,į‚šå‡ģæŦĄæ•°,į‚šå‡ģįŽ‡,CPC (USD)

Use Google AdSense/Admob api to get the report content and convert it into csv format

% google-csv-helper --google-token-file .google-account01 --google-show-report-list
% google-csv-helper --google-token-file .google-account02 --google-show-report-list
% google-csv-helper --google-token-file .google-account01 --google-adsense-latest-csv > csv/account1/adsense/latest-day.csv
% google-csv-helper --google-token-file .google-account02 --google-admob-latest-csv > csv/account2/admob/latest-day.csv
% google-csv-helper --google-token-file .google-account02 --google-adsense-latest-csv > csv/account2/adsense/latest-day.csv
% tree csv 
csv
├── account01
│   └── adsense
│       └── latest-day.csv
└── account02
    ├── adsense
    │   └── latest-day.csv
    └── admob
        └── latest-day.csv

6 directories, 3 files

Create Dashboard reports from csv files

% google-csv-helper --output markdown csv
## Current:
### Date Range: 2023-06-01 ~ 2023-06-04
#### compare: 2023-05-01 ~ 2023-05-31
| Item | Cumulative Revenue | Average Daily Revenue | Average CPC | Min Daily Revenue | Max Daily Revenue 
| -- | --: | --: | --: | --: | --: 
| Admob Global | 1,234.56 | 123.45 (-12.34%) | 0.001 (-1.23%) | 234.56 [06/02 Fri] | 456.78 [06/01 Thu] 
| Adsense Global | 1,234.56 | 123.45 (-12.34%) | 0.1234 (-2.34%) | 123.45 [06/02 Fri] | 345.67 [06/01 Thu] 
| Adsense China |  1,234.56 | 123.45 (-12.34%) | 0.2345 (2.34%) | 123.45 [06/02 Fri] | 345.67 `[06/01 Thu] 
| Total | 1,234.56 | 456.78 | | | 

% google-csv-helper --output markdown --output-chart-columns 'Estimated earnings (USD)' csv 

Current:

Date Range: 2023-06-01 ~ 2023-06-04

compare: 2023-05-01 ~ 2023-05-31

Item Cumulative Revenue Average Daily Revenue Average CPC Min Daily Revenue Max Daily Revenue
Admob Global 1,234.56 123.45 (-12.34%) 0.001 (-1.23%) 234.56 [06/02 Fri] 456.78 [06/01 Thu]
Adsense Global 1,234.56 123.45 (-12.34%) 0.1234 (-2.34%) 123.45 [06/02 Fri] 345.67 [06/01 Thu]
Adsense China 1,234.56 123.45 (-12.34%) 0.2345 (2.34%) 123.45 [06/02 Fri] 345.67 `[06/01 Thu]
Total 1,234.56 456.78

ref

Sum of (Admob Global, Adsense Global, Adsense China) - Cumulative Average of 'Estimated earnings (USD)' Chart:
 867.61  ┤
 846.52  ┤                          ╭──
 825.44  â”ŧ╮                        ╭╯
 804.36  ┤│                      ╭─╯
 783.27  ┤│                     ╭╯
 762.19  ┤│                   ╭─╯
 741.11  ┤│ ╭╮ ╭╮            ╭╯
 720.02  ┤│╭╯╰─╯╰╎           │
 698.94  ┤╰╯     ╰─╮         │
 677.86  ┤         ╰╮       ╭╯
 656.77  ┤          ╰───╮   │
 635.69  ┤              ╰───╯

% google-csv-helper --output-chart-columns 'Estimated earnings (USD)' --output-chart-detailed-columns csv

Current:

Date Range: 2023-06-01 ~ 2023-06-04

compare: 2023-05-01 ~ 2023-05-31

Item Cumulative Revenue Average Daily Revenue Average CPC Min Daily Revenue Max Daily Revenue
Admob Global 1,234.56 123.45 (-12.34%) 0.001 (-1.23%) 234.56 [06/02 Fri] 456.78 [06/01 Thu]
Adsense Global 1,234.56 123.45 (-12.34%) 0.1234 (-2.34%) 123.45 [06/02 Fri] 345.67 [06/01 Thu]
Adsense China 1,234.56 123.45 (-12.34%) 0.2345 (2.34%) 123.45 [06/02 Fri] 345.67 `[06/01 Thu]
Total 1,234.56 456.78

ref

Sum of (Admob Global, Adsense Global, Adsense China) - Cumulative Average of 'Estimated earnings (USD)' Chart:
 867.61  ┤
 846.52  ┤                          ╭──
 825.44  â”ŧ╮                        ╭╯
 804.36  ┤│                      ╭─╯
 783.27  ┤│                     ╭╯
 762.19  ┤│                   ╭─╯
 741.11  ┤│ ╭╮ ╭╮            ╭╯
 720.02  ┤│╭╯╰─╯╰╎           │
 698.94  ┤╰╯     ╰─╮         │
 677.86  ┤         ╰╮       ╭╯
 656.77  ┤          ╰───╮   │
 635.69  ┤              ╰───╯
Admob Global - Cumulative Average of 'Estimated earnings (USD)' Chart:
  297.11  â”ŧ╮
  294.28  ┤│     ╭╮
  291.46  ┤│    ╭╯╰─╎
  288.64  ┤│    │   ╰╮
  285.81  ┤│    │    ╰╮╭╮
  282.99  ┤│    │     ╰╯╰╎
  280.17  ┤│    │        ╰╮
  277.35  ┤│   ╭╯         ╰╮
  274.52  ┤│   │           ╰╮ ╭─╮
  271.70  ┤╰╮  │            ╰─╯ ╰─╮  ╭──
  268.88  ┤ ╰──╯                  ╰──╯
  266.06  ┤
Adsense Global - Cumulative Average of 'Estimated earnings (USD)' Chart:
  495.71  ┤
  473.65  ┤                          ╭──
  451.59  ┤                         ╭╯
  429.53  â”ŧ╮                       ╭╯
  407.46  ┤│                     ╭─╯
  385.40  ┤│                    ╭╯
  363.34  ┤│╭─╮                ╭╯
  341.28  ┤╰╯ ╰╮              ╭╯
  319.22  ┤    ╰──╮           │
  297.16  ┤       ╰╮         ╭╯
  275.10  ┤        ╰─╮      ╭╯
  253.04  ┤          ╰──────╯
Adsense China - Cumulative Average of 'Estimated earnings (USD)' Chart:
  211.76  ┤
  209.91  ┤     ╭──╮
  208.06  ┤     │  ╰╮
  206.20  ┤     │   ╰╮ ╭─╮
  204.35  ┤     │    ╰─╯ ╰╮  ╭──╮
  202.50  ┤    ╭╯         ╰──╯  ╰─╮
  200.65  â”ŧ╮  ╭╯                  ╰────╮
  198.80  ┤│  │                        ╰
  196.95  ┤│  │
  195.10  ┤│ ╭╯
  193.25  ┤│ │
  191.40  ┤╰─╯