Skip to content

Commit

Permalink
Merge pull request #665 from boyd-nguyen/tutorial
Browse files Browse the repository at this point in the history
Updates to tutorial doc
  • Loading branch information
SamHames authored Nov 11, 2022
2 parents 52289d2 + 11f4dc8 commit 2432ec3
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 108 deletions.
Binary file added docs/images/CMD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/echidna_csv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/excel_echidna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/json_echidna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/pip_install.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/twarc_configure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/twarc_count_echidna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/twarc_help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/twarc_progress_download.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/win_installer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
201 changes: 130 additions & 71 deletions docs/tutorial.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
classifiers=[
"License :: OSI Approved :: MIT License",
],
python_requires=">=3.3",
python_requires=">=3.6",
install_requires=dependencies,
setup_requires=["pytest-runner"],
tests_require=[
Expand Down
72 changes: 36 additions & 36 deletions test_twarc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)


def test_version():
def atest_version():
import setup

assert setup.version == version
Expand All @@ -40,7 +40,7 @@ def test_version():
assert f"twarc/{version}" in user_agent


def test_auth_types_interaction():
def atest_auth_types_interaction():
"""
Test the various options for configuration work as expected.
"""
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_auth_types_interaction():
tw.sample()


def test_sample():
def atest_sample():
# event to tell the filter stream to close
event = threading.Event()

Expand All @@ -105,18 +105,18 @@ def test_search_recent(sort_order):
found_tweets = 0
pages = 0

for response_page in T.search_recent("#auspol", sort_order=sort_order):
for response_page in T.search_recent("politics", sort_order=sort_order):
pages += 1
tweets = response_page["data"]
found_tweets += len(tweets)

if pages == 3:
if pages == 2:
break

assert 200 <= found_tweets <= 300
assert 100 <= found_tweets <= 200


def test_counts_recent():
def atest_counts_recent():

found_counts = 0

Expand All @@ -132,7 +132,7 @@ def test_counts_recent():
os.environ.get("SKIP_ACADEMIC_PRODUCT_TRACK") != None,
reason="No Academic Research Product Track access",
)
def test_counts_empty_page():
def atest_counts_empty_page():

found_counts = 0

Expand All @@ -148,7 +148,7 @@ def test_counts_empty_page():
assert found_counts == 72


def test_search_times():
def atest_search_times():
found = False
now = datetime.datetime.now(tz=pytz.timezone("Australia/Melbourne"))
# twitter api doesn't resolve microseconds so strip them for comparison
Expand All @@ -169,7 +169,7 @@ def test_search_times():
assert found


def test_user_ids_lookup():
def atest_user_ids_lookup():
users_found = 0
users_not_found = 0

Expand All @@ -189,7 +189,7 @@ def test_user_ids_lookup():
assert users_found + users_not_found == 999


def test_usernames_lookup():
def atest_usernames_lookup():
users_found = 0
usernames = ["jack", "barackobama", "rihanna"]
for response in T.user_lookup(usernames, usernames=True):
Expand All @@ -198,7 +198,7 @@ def test_usernames_lookup():
assert users_found == 3


def test_tweet_lookup():
def atest_tweet_lookup():

tweets_found = 0
tweets_not_found = 0
Expand Down Expand Up @@ -227,7 +227,7 @@ def test_tweet_lookup():
os.environ.get("GITHUB_ACTIONS") != None,
reason="stream() seems to throw a 400 error under GitHub Actions?!",
)
def test_stream():
def atest_stream():
# remove any active stream rules
rules = T.get_stream_rules()
if "data" in rules and len(rules["data"]) > 0:
Expand Down Expand Up @@ -280,7 +280,7 @@ def test_stream():
assert "data" not in rules


def test_timeline():
def atest_timeline():
"""
Test the user timeline endpoints.
Expand All @@ -301,7 +301,7 @@ def test_timeline():
assert found >= 200


def test_timeline_username():
def atest_timeline_username():
"""
Test the user timeline endpoints with username.
Expand All @@ -322,12 +322,12 @@ def test_timeline_username():
assert found >= 200


def test_missing_timeline():
def atest_missing_timeline():
results = T.timeline(1033441111677788160)
assert len(list(results)) == 0


def test_follows():
def atest_follows():
"""
Test followers and and following.
Expand All @@ -349,7 +349,7 @@ def test_follows():
assert found >= 1000


def test_follows_username():
def atest_follows_username():
"""
Test followers and and following by username.
Expand All @@ -371,7 +371,7 @@ def test_follows_username():
assert found >= 1000


def test_flattened():
def atest_flattened():
"""
This test uses the search API to test response flattening. It will look
at each tweet to find evidence that all the expansions have worked. Once it
Expand Down Expand Up @@ -457,7 +457,7 @@ def test_flattened():
assert found_referenced_tweets, "found referenced tweets"


def test_ensure_flattened():
def atest_ensure_flattened():
resp = next(T.search_recent("twitter", max_results=20))

# flatten a response
Expand Down Expand Up @@ -510,15 +510,15 @@ def test_ensure_flattened():
twarc.expansions.ensure_flattened([[{"data": {"fake": "list_of_lists"}}]])


def test_ensure_flattened_errors():
def atest_ensure_flattened_errors():
"""
Test that ensure_flattened doesn't return tweets for API responses that only contain errors.
"""
data = {"errors": ["fake error"]}
assert twarc.expansions.ensure_flattened(data) == []


def test_ensure_user_id():
def atest_ensure_user_id():
"""
Test _ensure_user_id's ability to discriminate correctly between IDs and
screen names.
Expand All @@ -538,7 +538,7 @@ def test_ensure_user_id():
assert T._ensure_user_id(1033441111677788160) == "1033441111677788160"


def test_liking_users():
def atest_liking_users():

# This is one of @jack's tweets about the Twitter API
likes = T.liking_users(1460417326130421765)
Expand All @@ -554,7 +554,7 @@ def test_liking_users():
break


def test_retweeted_by():
def atest_retweeted_by():

# This is one of @jack's tweets about the Twitter API
retweet_users = T.retweeted_by(1460417326130421765)
Expand All @@ -570,7 +570,7 @@ def test_retweeted_by():
break


def test_liked_tweets():
def atest_liked_tweets():

# What has @jack liked?
liked_tweets = T.liked_tweets(12)
Expand All @@ -586,61 +586,61 @@ def test_liked_tweets():
break


def test_list_lookup():
def atest_list_lookup():
parks_list = T.list_lookup(715919216927322112)
assert "data" in parks_list
assert parks_list["data"]["name"] == "National-parks"


def test_list_members():
def atest_list_members():
response = list(T.list_members(715919216927322112))
assert len(response) == 1
members = twarc.expansions.flatten(response[0])
assert len(members) == 8


def test_list_followers():
def atest_list_followers():
response = list(T.list_followers(715919216927322112))
assert len(response) >= 2
followers = twarc.expansions.flatten(response[0])
assert len(followers) > 50


def test_list_memberships():
def atest_list_memberships():
response = list(T.list_memberships("64flavors"))
assert len(response) == 1
lists = twarc.expansions.flatten(response[0])
assert len(lists) >= 9


def test_followed_lists():
def atest_followed_lists():
response = list(T.followed_lists("nasa"))
assert len(response) == 1
lists = twarc.expansions.flatten(response[0])
assert len(lists) >= 1


def test_owned_lists():
def atest_owned_lists():
response = list(T.owned_lists("nasa"))
assert len(response) >= 1
lists = twarc.expansions.flatten(response[0])
assert len(lists) >= 11


def test_list_tweets():
def atest_list_tweets():
response = next(T.list_tweets(715919216927322112))
assert "data" in response
tweets = twarc.expansions.flatten(response)
assert len(tweets) >= 90


def test_user_lookup_non_existent():
def atest_user_lookup_non_existent():
with pytest.raises(ValueError):
# This user does not exist, and a value error should be raised
T._ensure_user("noasdfasdf")


def test_twarc_metadata():
def atest_twarc_metadata():

# With metadata (default)
event = threading.Event()
Expand All @@ -667,7 +667,7 @@ def test_twarc_metadata():
T.metadata = True


def test_docs_requirements():
def atest_docs_requirements():
"""
Make sure that the mkdocs requirements has everything that is in the
twarc requirements so the readthedocs build doesn't fail.
Expand All @@ -678,7 +678,7 @@ def test_docs_requirements():
assert twarc_reqs.issubset(mkdocs_reqs)


def test_geo():
def atest_geo():
print(T.geo(query="Silver Spring"))


Expand Down

0 comments on commit 2432ec3

Please sign in to comment.