Skip to content

Commit

Permalink
add ct_get_lists function
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRZapata committed Jun 29, 2020
1 parent 0cc06a6 commit 1acac6b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
26 changes: 25 additions & 1 deletion PyCrowdTangle/PyCrowdTangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,28 @@ def ct_get_posts(count=100, start_date="", end_date="", api_token=""):
# sending get request and saving the response as response object
r = requests.get(url=URL_BASE, params=PARAMS)
# status = r.status_code
return r.json()
return r.json()

def ct_get_lists(api_token=""):
"""Retrieve the lists, saved searches and saved post lists of the dashboard associated with the token sent in
Args:
api_token (str, optional): you can locate your API token via your crowdtangle dashboard
under Settings > API Access.
Returns:
[dict]: The Response contains both a status code and a result. The status will always
be 200 if there is no error. The result contains an array of a lists objects
Example:
ct_get_lists(api_token="AKJHXDFYTGEBKRJ6535")
"""

# api-endpoint
URL_BASE = "https://api.crowdtangle.com/lists"
# defining a params dict for the parameters to be sent to the API
PARAMS = {'token': api_token}

# sending get request and saving the response as response object
r = requests.get(url=URL_BASE, params=PARAMS)
# status = r.status_code
return r.json()
5 changes: 3 additions & 2 deletions PyCrowdTangle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Top-level package for PyCrowdTangle"""
__author__ = """Jose R. Zapata"""
__version__ = '0.0.4'
__version__ = '0.1.0'

from .PyCrowdTangle import ct_get_posts
from .PyCrowdTangle import ct_get_links
from .PyCrowdTangle import ct_get_links
from .PyCrowdTangle import ct_get_lists
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ df = pd.DataFrame(data['result']['posts'])
#show results
df.head()
```

### ct_get_lists
```python
import PyCrowdTangle as pct

#retrieve data from CrowdTangle
# get the api_token from https://apps.crowdtangle.com/
# you can locate your API token via your crowdtangle dashboard
# under Settings > API Access.

data = pct.ct_get_lists(api_token="AKJHXDFYTGEBKRJ6535")

#show results
print(data)
```
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
setup(
name="PyCrowdTangle",
packages = find_packages(include=['PyCrowdTangle']),
version="0.0.4",
version="0.1.0",
author="Jose R. Zapata",
author_email="[email protected]",
description="A Python Wrapper To Retrieve Data From The CrowdTangle API",
Expand Down

0 comments on commit 1acac6b

Please sign in to comment.