diff --git a/Parler/utils.py b/Parler/utils.py index 03db07c..f71bf56 100644 --- a/Parler/utils.py +++ b/Parler/utils.py @@ -6,7 +6,12 @@ def add_missing_values(row): row["Domain"] = "parler.com" return row - +def is_ok(data: dict) -> bool: + return ( + "status" in data and \ + data.get("status") == "success" and \ + "data" in data + ) def check_login(func): def wrapper(*args): if not args[0].is_logged_in: diff --git a/README.md b/README.md index 1395122..e89ec70 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This **UNOFFICIAL** library designed to programatically fetch data from parler.c ~~This library supports the new (as of 2022-02-06) Parler `open-api` / logged-in endpoints. Both logged in and guest modes are supported.~~ -**Show is back on!** Now this library supports the *even newer* (as of 2022-10-21) Parler `/v0/` and `/v0/public` endpoints. Same caveats, both logged in and guest modes are supported \#champagnepapi +**Show is back on!** Now this library supports the *even newer* (as of 2022-10-21) Parler `/v0/` and `/v0/public` endpoints. Same caveats, both logged in and guest modes are supported # To do list: diff --git a/tests/test_feed.py b/tests/test_feed.py index 4531efc..87c2e96 100644 --- a/tests/test_feed.py +++ b/tests/test_feed.py @@ -1,13 +1,15 @@ import Parler from Parler import with_auth as authed import os +from Parler import utils p = Parler.Parler(debug=True) au = authed.AuthSession(debug=False) -posts_per_feed_page = 20 -trending_length = 8 -trending_user_length = 6 +posts_per_feed_page = 10 +trending_length = 12 +trending_user_length = 20 + def test_get_feed(): assert os.getenv("PARLER_USERNAME") is not None @@ -16,6 +18,7 @@ def test_get_feed(): identifier=os.getenv("PARLER_USERNAME"), password=os.getenv("PARLER_PASSWORD") ) assert au.is_logged_in + assert utils.is_ok(au.feed()) r1 = au.feed()["data"] r2 = au.feed(False, 2, False)["data"] r3 = au.feed(False, 3, False)["data"] @@ -26,9 +29,9 @@ def test_get_feed(): # deep dive: get IDs of each post in user feed, sort alphabetically, compare against n+1 - fp1 = [x.get("primary").get("uuid") for x in r1] - fp2 = [x.get("primary").get("uuid") for x in r2] - fp3 = [x.get("primary").get("uuid") for x in r3] + fp1 = [x.get("postuuid") for x in r1] + fp2 = [x.get("postuuid") for x in r2] + fp3 = [x.get("postuuid") for x in r3] fp1.sort() fp2.sort() @@ -37,13 +40,10 @@ def test_get_feed(): assert fp1 != fp2 assert fp2 != fp3 + def test_trending(): assert len(p.trending("today")["data"]) == trending_length - assert len(p.trending("top")["data"]) == trending_length -def test_discover_feed(): - r = p.discover_feed() - assert len(r["data"]) >= posts_per_feed_page def test_trending_users(): assert os.getenv("PARLER_USERNAME") is not None @@ -52,4 +52,4 @@ def test_trending_users(): identifier=os.getenv("PARLER_USERNAME"), password=os.getenv("PARLER_PASSWORD") ) assert au.is_logged_in - assert len(au.trending_users()) == trending_user_length + assert len(au.trending_users().get("data")) == trending_user_length diff --git a/tests/test_post.py b/tests/test_post.py index 2f79098..a97a8ad 100644 --- a/tests/test_post.py +++ b/tests/test_post.py @@ -1,6 +1,7 @@ import Parler from Parler import with_auth as authed import os +from Parler import utils p = Parler.Parler(debug=True) au = authed.AuthSession(debug=False) @@ -8,16 +9,10 @@ def test_get_post(): r = p.post_info("ef4d02fe-7a5a-4ab4-8e82-7c0ee5e32960") - assert r.get("status") == "ok" - - assert "uuid" in r.get("data")[0].get("primary") + assert utils.is_ok(r) + assert "postuuid" in r.get("data") assert ( - r.get("data")[0].get("primary").get("uuid") + r.get("data").get("postuuid") == "ef4d02fe-7a5a-4ab4-8e82-7c0ee5e32960" ) - assert "id" in r.get("data")[0].get("primary") - assert "uuid" in r.get("data")[0].get("primary") - assert "body" in r.get("data")[0].get("primary") - assert "full_body" in r.get("data")[0].get("primary") - assert "image" in r.get("data")[0].get("primary") - assert "domain_name" in r.get("data")[0].get("primary") + assert "body" in r.get("data") diff --git a/tests/test_user.py b/tests/test_user.py index 75ca543..7cf9ffc 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -2,12 +2,13 @@ from Parler import with_auth as authed import os import random +from Parler import utils p = Parler.Parler(debug=True) au = authed.AuthSession(debug=False) -posts_per_user = 20 -search_hits_per_page = 50 +posts_per_user = 10 +search_hits_per_page = 10 badge_types = [ "gold", @@ -24,25 +25,40 @@ def test_get_profile(): r = p.profile("TheWesternJournal").get("data") assert r is not None assert "username" in r - assert "dateCreated" in r assert ( "uuid" in r and r.get("uuid") == "40f28d1a-ee94-4d6f-ad9a-ed4cd3a39228" ) # https://web.archive.org/web/20220213155807/https://parler.com/open-api/parley.php assert "bio" in r assert "website" in r assert "location" in r - assert "joinedAt" in r + assert "joined_date" in r + assert "birthday" in r + assert "gender" in r + assert "real_name" in r + assert "joined_date" in r + assert "following_count" in r + assert "follower_count" in r + assert "is_private" in r + assert "is_public" in r def test_get_profile_feed(): r = p.user_feed(username="TheWesternJournal") + assert utils.is_ok(r) + assert len(r.get("data")) == posts_per_user # posts per user - assert "id" in r.get("data")[0].get("primary") - assert "uuid" in r.get("data")[0].get("primary") - assert "body" in r.get("data")[0].get("primary") - assert "full_body" in r.get("data")[0].get("primary") - assert "image" in r.get("data")[0].get("primary") - assert "domain_name" in r.get("data")[0].get("primary") + assert "postuuid" in r.get("data")[0] + assert "body" in r.get("data")[0] + assert "title" in r.get("data")[0] + assert "total_comments" in r.get("data")[0] + assert "upvotes" in r.get("data")[0] + assert "echos" in r.get("data")[0] + assert "views" in r.get("data")[0] + assert "is_echo" in r.get("data")[0] + assert "is_comment" in r.get("data")[0] + assert "link" in r.get("data")[0] + assert "trolling" in r.get("data")[0] + assert "ad" in r.get("data")[0] def test_get_profile_feed_pagination(): @@ -59,9 +75,9 @@ def test_get_profile_feed_pagination(): # deep dive: get IDs of each post in user feed, sort alphabetically, compare against n+1 - fp1 = [x.get("primary").get("uuid") for x in r1.get("data")] - fp2 = [x.get("primary").get("uuid") for x in r2.get("data")] - fp3 = [x.get("primary").get("uuid") for x in r3.get("data")] + fp1 = [x.get("postuuid") for x in r1.get("data")] + fp2 = [x.get("postuuid") for x in r2.get("data")] + fp3 = [x.get("postuuid") for x in r3.get("data")] fp1.sort() fp2.sort() @@ -83,17 +99,16 @@ def test_login(): def test_search_users(): r = au.users("qanon") - assert len(r) == search_hits_per_page + assert utils.is_ok(r) + + assert len(r.get("data")) == search_hits_per_page # pick one at random - user = r[random.randint(0, search_hits_per_page - 1)] + user = r.get("data")[random.randint(0, search_hits_per_page - 1)] assert "name" in user assert "username" in user - assert "followed" in user - assert "profile_picture" in user - assert "badges" in user for x in badge_types: