Package: gnippy
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 athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.Description: gnippy: Python library for GNIP===============================.. image:: https://badge.fury.io/py/gnippy.svg:target: https://pypi.python.org/pypi/gnippy.. image:: https://img.shields.io/pypi/dm/gnippy.svg:target: https://pypi.python.org/pypi/gnippy.. image:: https://travis-ci.org/abh1nav/gnippy.svg?branch=master:target: https://travis-ci.org/abh1nav/gnippygnippy 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:: pythonpip install gnippyQuickstart----------Create a .gnippy file and place it in your home directory. It should contain the following:.. code-block:: text[Credentials]username = user@company.compassword = mypassword[PowerTrack]url = https://my.gnip.powertrack/url.jsonrules_url = https://api.gnip.powertrack/rules.jsonFire up the client:.. code-block:: python#!/usr/bin/env pythonimport timefrom gnippy import PowerTrackClient# Define a callbackdef callback(activity):print activity# Create the clientclient = PowerTrackClient(callback)client.connect()# Wait for 2 minutes and then disconnecttime.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:: pythonclient = PowerTrackClient(callback, config_file_path="/etc/gnippy")# OR ... provide the url and authentication credentials to override any config filesclient = PowerTrackClient(callback, url="http://my.gnip.powertrack/url.json", auth=("uname", "pwd"))You can also configure gnippy using environment variables:.. code-block:: textGNIPPY_URLGNIPPY_RULES_URLGNIPPY_AUTH_USERNAMEGNIPPY_AUTH_PASSWORDAdding PowerTrack Rules-----------------------If you want to add `rules <http://support.gnip.com/apis/powertrack/rules.html>`_ to your PowerTrack:.. code-block:: pythonfrom gnippy import rulesfrom gnippy.errors import RuleAddFailedException# Synchronously add rulestry: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 oncerule_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 filesrules.add_rule("My Rule String", tag="mytag", rules_url="https://api.gnip.powertrack/rules.json", \auth=("uname", "pwd"))Listing Active PowerTrack Rules-------------------------------.. code-block:: pythonfrom gnippy import rulesfrom gnippy.errors import RulesGetFailedExceptiontry:rules_list = rules.get_rules()# rules_list is in the format:# [#    { "value": "(Hello OR World) AND lang:en" },#    { "value": "Hello", "tag": "mytag" }# ]except RulesGetFailedException:passDeleting PowerTrack Rules-------------------------.. code-block:: pythonfrom gnippy import rulesfrom gnippy.errors import RuleDeleteFailedException, RulesGetFailedExceptiontry:rules_list = rules.get_rules()# Suppose I want to delete the first rule in the listrules.delete_rule(rules_list[0])# OR ... I want to delete ALL rulesrules.delete_rules(rules_list)except RuleDeleteFailedException, RulesGetFailedException:passSource available on GitHub: http://github.com/abh1nav/gnippy/Platform: UNKNOWN