Python library for GNIP.
Project description
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Description: gnippy: Python library for GNIP
===============================
.. image:: https://badge.fury.io/py/gnippy.svg
:target: https://pypi-hypernode.com/pypi/gnippy
.. image:: https://img.shields.io/pypi/dm/gnippy.svg
:target: https://pypi-hypernode.com/pypi/gnippy
.. image:: https://travis-ci.org/abh1nav/gnippy.svg?branch=master
:target: https://travis-ci.org/abh1nav/gnippy
gnippy provides an easy way to access the `Power Track <http://gnip.com/twitter/power-track/>`_ stream provided by GNIP.
You can also use gnippy to programatically add rules to your Power Track stream.
Install
-------
.. code-block:: python
pip install gnippy
Quickstart
----------
Create a .gnippy file and place it in your home directory. It should contain the following:
.. code-block:: text
[Credentials]
username = user@company.com
password = mypassword
[PowerTrack]
url = https://my.gnip.powertrack/url.json
rules_url = https://api.gnip.powertrack/rules.json
Fire up the client:
.. code-block:: python
#!/usr/bin/env python
import time
from gnippy import PowerTrackClient
# Define a callback
def callback(activity):
print activity
# Create the client
client = PowerTrackClient(callback)
client.connect()
# Wait for 2 minutes and then disconnect
time.sleep(120)
client.disconnect()
Configuration
-------------
If you don't want to create a config file or you want it put it in another location:
.. code-block:: python
client = PowerTrackClient(callback, config_file_path="/etc/gnippy")
# OR ... provide the url and authentication credentials to override any config files
client = PowerTrackClient(callback, url="http://my.gnip.powertrack/url.json", auth=("uname", "pwd"))
You can also configure gnippy using environment variables:
.. code-block:: text
GNIPPY_URL
GNIPPY_RULES_URL
GNIPPY_AUTH_USERNAME
GNIPPY_AUTH_PASSWORD
Adding PowerTrack Rules
-----------------------
If you want to add `rules <http://support.gnip.com/apis/powertrack/rules.html>`_ to your PowerTrack:
.. code-block:: python
from gnippy import rules
from gnippy.errors import RuleAddFailedException
# Synchronously add rules
try:
rules.add_rule('(Hello OR World OR "this is a test") lang:en', tag="MyRule")
rules.add_rule('Rule without a tag')
except RuleAddFailedException:
pass
# OR ... synchronously add multiple rules at once
rule_list = []
rule_list.append(rules.build("Hello World", tag="asdf"))
rule_list.append(rules.build("Rule Without a Tag"))
try:
rules.add_rules(rule_list)
except RuleAddFailedException:
pass
# OR ... manually pass in params - overrides any config files
rules.add_rule("My Rule String", tag="mytag", rules_url="https://api.gnip.powertrack/rules.json", \
auth=("uname", "pwd"))
Listing Active PowerTrack Rules
-------------------------------
.. code-block:: python
from gnippy import rules
from gnippy.errors import RulesGetFailedException
try:
rules_list = rules.get_rules()
# rules_list is in the format:
# [
# { "value": "(Hello OR World) AND lang:en" },
# { "value": "Hello", "tag": "mytag" }
# ]
except RulesGetFailedException:
pass
Deleting PowerTrack Rules
-------------------------
.. code-block:: python
from gnippy import rules
from gnippy.errors import RuleDeleteFailedException, RulesGetFailedException
try:
rules_list = rules.get_rules()
# Suppose I want to delete the first rule in the list
rules.delete_rule(rules_list[0])
# OR ... I want to delete ALL rules
rules.delete_rules(rules_list)
except RuleDeleteFailedException, RulesGetFailedException:
pass
Source available on GitHub: http://github.com/abh1nav/gnippy/
Platform: UNKNOWN
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Description: gnippy: Python library for GNIP
===============================
.. image:: https://badge.fury.io/py/gnippy.svg
:target: https://pypi-hypernode.com/pypi/gnippy
.. image:: https://img.shields.io/pypi/dm/gnippy.svg
:target: https://pypi-hypernode.com/pypi/gnippy
.. image:: https://travis-ci.org/abh1nav/gnippy.svg?branch=master
:target: https://travis-ci.org/abh1nav/gnippy
gnippy provides an easy way to access the `Power Track <http://gnip.com/twitter/power-track/>`_ stream provided by GNIP.
You can also use gnippy to programatically add rules to your Power Track stream.
Install
-------
.. code-block:: python
pip install gnippy
Quickstart
----------
Create a .gnippy file and place it in your home directory. It should contain the following:
.. code-block:: text
[Credentials]
username = user@company.com
password = mypassword
[PowerTrack]
url = https://my.gnip.powertrack/url.json
rules_url = https://api.gnip.powertrack/rules.json
Fire up the client:
.. code-block:: python
#!/usr/bin/env python
import time
from gnippy import PowerTrackClient
# Define a callback
def callback(activity):
print activity
# Create the client
client = PowerTrackClient(callback)
client.connect()
# Wait for 2 minutes and then disconnect
time.sleep(120)
client.disconnect()
Configuration
-------------
If you don't want to create a config file or you want it put it in another location:
.. code-block:: python
client = PowerTrackClient(callback, config_file_path="/etc/gnippy")
# OR ... provide the url and authentication credentials to override any config files
client = PowerTrackClient(callback, url="http://my.gnip.powertrack/url.json", auth=("uname", "pwd"))
You can also configure gnippy using environment variables:
.. code-block:: text
GNIPPY_URL
GNIPPY_RULES_URL
GNIPPY_AUTH_USERNAME
GNIPPY_AUTH_PASSWORD
Adding PowerTrack Rules
-----------------------
If you want to add `rules <http://support.gnip.com/apis/powertrack/rules.html>`_ to your PowerTrack:
.. code-block:: python
from gnippy import rules
from gnippy.errors import RuleAddFailedException
# Synchronously add rules
try:
rules.add_rule('(Hello OR World OR "this is a test") lang:en', tag="MyRule")
rules.add_rule('Rule without a tag')
except RuleAddFailedException:
pass
# OR ... synchronously add multiple rules at once
rule_list = []
rule_list.append(rules.build("Hello World", tag="asdf"))
rule_list.append(rules.build("Rule Without a Tag"))
try:
rules.add_rules(rule_list)
except RuleAddFailedException:
pass
# OR ... manually pass in params - overrides any config files
rules.add_rule("My Rule String", tag="mytag", rules_url="https://api.gnip.powertrack/rules.json", \
auth=("uname", "pwd"))
Listing Active PowerTrack Rules
-------------------------------
.. code-block:: python
from gnippy import rules
from gnippy.errors import RulesGetFailedException
try:
rules_list = rules.get_rules()
# rules_list is in the format:
# [
# { "value": "(Hello OR World) AND lang:en" },
# { "value": "Hello", "tag": "mytag" }
# ]
except RulesGetFailedException:
pass
Deleting PowerTrack Rules
-------------------------
.. code-block:: python
from gnippy import rules
from gnippy.errors import RuleDeleteFailedException, RulesGetFailedException
try:
rules_list = rules.get_rules()
# Suppose I want to delete the first rule in the list
rules.delete_rule(rules_list[0])
# OR ... I want to delete ALL rules
rules.delete_rules(rules_list)
except RuleDeleteFailedException, RulesGetFailedException:
pass
Source available on GitHub: http://github.com/abh1nav/gnippy/
Platform: UNKNOWN
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
gnippy-0.7.0.tar.gz
(8.0 kB
view details)
Built Distribution
File details
Details for the file gnippy-0.7.0.tar.gz
.
File metadata
- Download URL: gnippy-0.7.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e12099e6d2ac4e6e07e688d849eeec86916f4038c07b150e70cf52a1cba90d72 |
|
MD5 | 7cde6be19c41b525eac03261bf4bd048 |
|
BLAKE2b-256 | a61f13e706602fd81f68f7e865a13b7cf9bde0c2d2f6ddaf19443d3b7fd35904 |
File details
Details for the file gnippy-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: gnippy-0.7.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cb42a72ed1dacaced87a987b2aba3a395ab692e9216d21f603b1782f92a2ad0 |
|
MD5 | 87d50a0f4d17df6dd79be9a3316e4cc0 |
|
BLAKE2b-256 | 9fc7322b45d61431541d9db3f6f262a3ccdbbde9550722ce4c0d6d77f18c6698 |