-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b4f633
commit 4b80cbc
Showing
6 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import requests | ||
|
||
# save in a file called api-key.txt file | ||
# your api-key at your proyect folder | ||
try: | ||
with open("apikey.txt", "r") as file: | ||
apikey = file.readline() | ||
api_token = apikey.strip('\n') | ||
except: | ||
print("api-key.txt not found") | ||
|
||
|
||
def ct_get_posts(count=100, start_date="", end_date="", api_token=""): | ||
"""Retrieve a set of posts for the given parameters get post from crowdtangle | ||
Args: | ||
count (int, optional): The number of posts to return. Defaults to 100. options [1-100] | ||
start_date (str, optional): [description]. Defaults to "". | ||
end_date (str, optional): The latest date at which a post could be posted. | ||
Time zone is UTC. Format is “yyyy-mm-ddThh:mm:ss” | ||
or “yyyy-mm-dd” (defaults to time 00:00:00). | ||
Defaults to "now". | ||
api_token (str, optional): [description]. Defaults to "". | ||
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 post objects and | ||
a pagination object with URLs for both the next and previous page, if they exist | ||
""" | ||
|
||
# api-endpoint | ||
URL_BASE = "https://api.crowdtangle.com/posts" | ||
# defining a params dict for the parameters to be sent to the API | ||
PARAMS = {'count': count, 'token': api_token} | ||
|
||
# add params parameters | ||
if start_date: | ||
PARAMS['startDate'] = start_date | ||
if start_date: | ||
PARAMS['endDate'] = end_date | ||
|
||
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
"""Top-level package for PyCrowdTangle""" | ||
|
||
__author__ = """Jose R. Zapata""" | ||
__version__ = '0.0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests==2.24.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from setuptools import setup, find_packages | ||
|
||
with open("README.md", "r") as readme_file: | ||
readme = readme_file.read() | ||
|
||
requirements = ["requests>=2"] | ||
|
||
setup( | ||
name="PyCrowdTangle", | ||
version="0.0.1", | ||
author="Jose R. Zapata", | ||
author_email="[email protected]", | ||
description="A Python Wrapper To Retrieve Data From The CrowdTangle API", | ||
long_description=readme, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/UPB-SS1/PyCrowdTangle", | ||
packages=find_packages(), | ||
install_requires=requirements, | ||
classifiers=[ | ||
"Programming Language :: Python :: 3.7", | ||
"License :: OSI Approved :: MIT License", | ||
], | ||
keywords=['crowdtangle', 'wrapper-api'], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- |