Automated Google Trends downloader
Project description
=======
gtrends
=======
New!
====
Theoretically gtrends now supports python 3.4 and 3.5, as well as 2.7. You can also specify the geographical location, timezone, category, and type of search desired. If there are any issues let me know in the issue tracker! Now read on...
About
=====
gtrends is a Python library that eases the process of downloading Google Trend data. `Google Trends <http://www.google.com/trends>`_ is a service offered by Google which allows access to aggregate query volume data for specific search terms, over specific periods of time. This volume data is represented as a fraction of the total query volume on the given day or week.
Users with Google accounts can download these data into csv files, however there are several caveats which make the data difficult to process. The data only come in daily granularity up until 3 months worth of data, after which they become weekly. Even worse, Google normalizes the data, so that the largest percent query volume in the time series is set to an integer '100,' with all other values set to smaller integer values. This makes it difficult, for example, to collect several files and splice them together (such as to maintain a daily granularity via files of shorter time periods), since the data are on difference scales.
gtrends solves this by allowing developers to extract data with either weekly or daily granularity, with the same scaling throughout, without the need to worry over scaling and data manipulation themselves.
Usage
=====
gtrends only contains two functions, the primary one being ``collectTrends()``. It can be used by the following::
import datetime
import gtrends
username = "myGoogleUsername"
password = "myGooglePassword"
terms = ["foo", "bar", "baz"]
startDt = datetime.datetime(year=2015, month=1, day=1)
endDt = datetime.datetime(year=2015, month=2, day=1)
trends = gtrends.collectTrends(username, password, terms, startDt, endDt)
``collectTrends()`` returns a 2d list of the data, of format [datetime, val0, val1, val2, etc.], with an additional a header. For example, the above code snippet returns the list, ``trends``, as follows::
date,foo,bar,baz
1/1/2015,16.667,83.333,16.667
1/2/2015,16.667,83.333,16.667
1/3/2015,16.667,83.333,16.667
1/4/2015,16.667,83.333,16.667
1/5/2015,16.667,66.667,16.667
1/6/2015,16.667,66.667,16.667
1/7/2015,16.667,83.333,16.667
1/8/2015,16.667,83.333,16.667
1/9/2015,16.667,83.333,16.667
1/10/2015,16.667,83.333,16.667
...
1/30/2015,16.667,83.333,16.667
1/31/2015,16.667,100.00,16.667
The dates are of type datetime, and the numbers are floats rounded to 3 decimal places.
The data is normalized across the entire time period and between terms such that the largest value has a float of 100.0, and all other values are scaled accordingly.
Data is returned from [startDt, endDt), to the accuracy of the month (i.e. the specific day within the month does not matter).
Advanced Usage
==============
Granularity
-----------
With the optional argument ``granularity``, the granularity can be changed from the default of daily, to weekly. ``granularity`` takes a string of either ``'d'`` or ``'w'`` corresponding to daily or weekly, respectively.
Sum & SavePath
--------------
``sum``, is an optional argument of type boolean. With this, the data of multiple terms can be summed together into one column. Default is ``False``.``savePath`` takes a string for a path to save the resultant csv. If left as the default ``None``, no file is saved.
Advanced Usage Example
----------------------
::
import datetime
import gtrends
username = "myGoogleUsername"
password = "myGooglePassword"
terms = ["foo", "bar", "baz"]
startDt = datetime.datetime(year=2015, month=1, day=1)
endDt = datetime.datetime(year=2015, month=2, day=1)
trends = gtrends.collectTrends(username, password, terms, startDt, endDt,
granularity='w', sum=True, savePath="myDir/data.csv")
Other Specifications
-----------
Just like on the Trends site, you can specify the location, category, type of search, and time zone for which you'd like to collect data. These are all strings corresponding to the respective fields ``geo``, ``cat``, ``gprops``, and ``tz``. For example, to get the query data for the term "pizza" in Italy, in the "Food & Drink" category, in the "news" search for Tajikistan Time, I'd type:
::
trends = gtrends.collectTrends(username, password, terms, startDt, endDt, geo='IT', cat='0-71', gprops='news', tz='Asia/Dushanbe')
Note: when you select a type of search (gprops) other than the default, you can only search weekly data. That's just how Google is.
Raw Data
========
The secondary function ``collectRawTrends()`` allows you to collect the raw csv from Google Trends as a string::
import datetime
import gtrends
username = "myGoogleUsername"
password = "myGooglePassword"
terms = ["foo", "bar", "baz"]
startDt = datetime.datetime(year=2015, month=1, day=1)
endDt = datetime.datetime(year=2015, month=2, day=1)
trends = gtrends.collectRawTrends(username, password, terms, startDt, endDt,
savePath="myDir/data.csv")
In this case, the granularity cannot be set: it is daily or weekly based on what Google naturally returns. The number of terms is limited to 5 (which is the max Google itself allows per csv file) and sumation is not supported (as in the optional argument ``sum`` in ``collectTrends()``). In addition, the regional data and related term data is included, rather than being discarded in ``collectTrends()``.
Installing
==========
Install via pip with::
pip install gtrends
Requirements
============
This has so far only been tested on Python 2.7, 3.4, and 3.5.
Issues
======
Please create an issue in the issue tracker.
License
=======
MIT License
Copyright (c) 2015 Eric Salina
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Data Source: Google Trends (http://www.google.com/trends)
gtrends
=======
New!
====
Theoretically gtrends now supports python 3.4 and 3.5, as well as 2.7. You can also specify the geographical location, timezone, category, and type of search desired. If there are any issues let me know in the issue tracker! Now read on...
About
=====
gtrends is a Python library that eases the process of downloading Google Trend data. `Google Trends <http://www.google.com/trends>`_ is a service offered by Google which allows access to aggregate query volume data for specific search terms, over specific periods of time. This volume data is represented as a fraction of the total query volume on the given day or week.
Users with Google accounts can download these data into csv files, however there are several caveats which make the data difficult to process. The data only come in daily granularity up until 3 months worth of data, after which they become weekly. Even worse, Google normalizes the data, so that the largest percent query volume in the time series is set to an integer '100,' with all other values set to smaller integer values. This makes it difficult, for example, to collect several files and splice them together (such as to maintain a daily granularity via files of shorter time periods), since the data are on difference scales.
gtrends solves this by allowing developers to extract data with either weekly or daily granularity, with the same scaling throughout, without the need to worry over scaling and data manipulation themselves.
Usage
=====
gtrends only contains two functions, the primary one being ``collectTrends()``. It can be used by the following::
import datetime
import gtrends
username = "myGoogleUsername"
password = "myGooglePassword"
terms = ["foo", "bar", "baz"]
startDt = datetime.datetime(year=2015, month=1, day=1)
endDt = datetime.datetime(year=2015, month=2, day=1)
trends = gtrends.collectTrends(username, password, terms, startDt, endDt)
``collectTrends()`` returns a 2d list of the data, of format [datetime, val0, val1, val2, etc.], with an additional a header. For example, the above code snippet returns the list, ``trends``, as follows::
date,foo,bar,baz
1/1/2015,16.667,83.333,16.667
1/2/2015,16.667,83.333,16.667
1/3/2015,16.667,83.333,16.667
1/4/2015,16.667,83.333,16.667
1/5/2015,16.667,66.667,16.667
1/6/2015,16.667,66.667,16.667
1/7/2015,16.667,83.333,16.667
1/8/2015,16.667,83.333,16.667
1/9/2015,16.667,83.333,16.667
1/10/2015,16.667,83.333,16.667
...
1/30/2015,16.667,83.333,16.667
1/31/2015,16.667,100.00,16.667
The dates are of type datetime, and the numbers are floats rounded to 3 decimal places.
The data is normalized across the entire time period and between terms such that the largest value has a float of 100.0, and all other values are scaled accordingly.
Data is returned from [startDt, endDt), to the accuracy of the month (i.e. the specific day within the month does not matter).
Advanced Usage
==============
Granularity
-----------
With the optional argument ``granularity``, the granularity can be changed from the default of daily, to weekly. ``granularity`` takes a string of either ``'d'`` or ``'w'`` corresponding to daily or weekly, respectively.
Sum & SavePath
--------------
``sum``, is an optional argument of type boolean. With this, the data of multiple terms can be summed together into one column. Default is ``False``.``savePath`` takes a string for a path to save the resultant csv. If left as the default ``None``, no file is saved.
Advanced Usage Example
----------------------
::
import datetime
import gtrends
username = "myGoogleUsername"
password = "myGooglePassword"
terms = ["foo", "bar", "baz"]
startDt = datetime.datetime(year=2015, month=1, day=1)
endDt = datetime.datetime(year=2015, month=2, day=1)
trends = gtrends.collectTrends(username, password, terms, startDt, endDt,
granularity='w', sum=True, savePath="myDir/data.csv")
Other Specifications
-----------
Just like on the Trends site, you can specify the location, category, type of search, and time zone for which you'd like to collect data. These are all strings corresponding to the respective fields ``geo``, ``cat``, ``gprops``, and ``tz``. For example, to get the query data for the term "pizza" in Italy, in the "Food & Drink" category, in the "news" search for Tajikistan Time, I'd type:
::
trends = gtrends.collectTrends(username, password, terms, startDt, endDt, geo='IT', cat='0-71', gprops='news', tz='Asia/Dushanbe')
Note: when you select a type of search (gprops) other than the default, you can only search weekly data. That's just how Google is.
Raw Data
========
The secondary function ``collectRawTrends()`` allows you to collect the raw csv from Google Trends as a string::
import datetime
import gtrends
username = "myGoogleUsername"
password = "myGooglePassword"
terms = ["foo", "bar", "baz"]
startDt = datetime.datetime(year=2015, month=1, day=1)
endDt = datetime.datetime(year=2015, month=2, day=1)
trends = gtrends.collectRawTrends(username, password, terms, startDt, endDt,
savePath="myDir/data.csv")
In this case, the granularity cannot be set: it is daily or weekly based on what Google naturally returns. The number of terms is limited to 5 (which is the max Google itself allows per csv file) and sumation is not supported (as in the optional argument ``sum`` in ``collectTrends()``). In addition, the regional data and related term data is included, rather than being discarded in ``collectTrends()``.
Installing
==========
Install via pip with::
pip install gtrends
Requirements
============
This has so far only been tested on Python 2.7, 3.4, and 3.5.
Issues
======
Please create an issue in the issue tracker.
License
=======
MIT License
Copyright (c) 2015 Eric Salina
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Data Source: Google Trends (http://www.google.com/trends)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gtrends-0.2.2.tar.gz
(10.6 kB
view details)
Built Distributions
gtrends-0.2.2-py3-none-any.whl
(14.5 kB
view details)
gtrends-0.2.2-py2-none-any.whl
(14.5 kB
view details)
File details
Details for the file gtrends-0.2.2.tar.gz
.
File metadata
- Download URL: gtrends-0.2.2.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8635aaa115d4b1c27e5c766989dde3c84cab00593630eb7c17e8da0509b409fa |
|
MD5 | 14a31e0cd7e864a13333b9f1be598a62 |
|
BLAKE2b-256 | f963c3ed8065a23a5569b427de8bacd22d68f1b63a3a94df4d3f54d0c0f5f99b |
File details
Details for the file gtrends-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: gtrends-0.2.2-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4d9683a4af178e7431970c0ddd7d209d07bd2555dfcced1e6d09eb07dbc31d8 |
|
MD5 | edef7207e296d6bdb95023afd3bd0bd4 |
|
BLAKE2b-256 | 726245aa11147be66047464c49572732252694b0d575c12ec9c37f52c7833299 |
File details
Details for the file gtrends-0.2.2-py2-none-any.whl
.
File metadata
- Download URL: gtrends-0.2.2-py2-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c15e561d719e5323019165902302a2dbe23471ebb30b7d7f95d4da272c95ace4 |
|
MD5 | bb70eb3eee7f16daae300c1c307f2fe1 |
|
BLAKE2b-256 | b2576b2ae23da76023f2114cfedc3bcde6e5f728171052ef628aa67667c3418d |