Skip to content

Commit 95a3632

Browse files
author
stlc-bot
committed
feat(scrape): add reddit-post prebuilt parser with full comment trees (#2217)
Stainless-Generated-From: 65b502140edcfd051f63e617a8cc79b61615491e
1 parent ea66000 commit 95a3632

12 files changed

Lines changed: 1071 additions & 126 deletions

‎lib/context_dev/models/batch_get_results_response.rb‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,10 @@ module Type
10751075
TIKTOK_FOLLOWERS = :"tiktok-followers"
10761076
TIKTOK_FOLLOWING = :"tiktok-following"
10771077
TIKTOK_USER_SEARCH = :"tiktok-user-search"
1078+
REDDIT_POST = :"reddit-post"
1079+
REDDIT_SEARCH = :"reddit-search"
1080+
REDDIT_SUBREDDIT = :"reddit-subreddit"
1081+
REDDIT_USER = :"reddit-user"
10781082
YELP_SEARCH = :"yelp-search"
10791083
YELP_REVIEWS = :"yelp-reviews"
10801084
EMAILS = :emails
@@ -2487,6 +2491,10 @@ module Type
24872491
TIKTOK_FOLLOWERS = :"tiktok-followers"
24882492
TIKTOK_FOLLOWING = :"tiktok-following"
24892493
TIKTOK_USER_SEARCH = :"tiktok-user-search"
2494+
REDDIT_POST = :"reddit-post"
2495+
REDDIT_SEARCH = :"reddit-search"
2496+
REDDIT_SUBREDDIT = :"reddit-subreddit"
2497+
REDDIT_USER = :"reddit-user"
24902498
YELP_SEARCH = :"yelp-search"
24912499
YELP_REVIEWS = :"yelp-reviews"
24922500
EMAILS = :emails

‎lib/context_dev/models/batch_submit_params.rb‎

Lines changed: 242 additions & 34 deletions
Large diffs are not rendered by default.

‎lib/context_dev/models/web_scrape_params.rb‎

Lines changed: 121 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,62 @@ class PrebuiltParser < ContextDev::Internal::Type::BaseModel
576576
# (/search/user?q={query}) as data.users: id, username, nickname, biography,
577577
# avatar_url, sec_uid, follower_count, like_count, and is_verified. The TikTok
578578
# parsers accept tiktok.com, www.tiktok.com, and m.tiktok.com URLs but not short
579-
# links (vm.tiktok.com, vt.tiktok.com, tiktok.com/t/…). yelp-search accepts Yelp
580-
# search URLs with find_desc and find_loc, reads start as the result offset, and
581-
# returns up to 20 ranked organic businesses in data.businesses with total and
582-
# pagination. yelp-reviews accepts a Yelp business URL (yelp.com/biz/{alias}),
583-
# uses optional start for the offset, and always sorts newest first; unsupported
584-
# sort and review filters are rejected, while tracking params are ignored. It
585-
# returns up to 20 latest public reviews in data.reviews with business details and
579+
# links (vm.tiktok.com, vt.tiktok.com, tiktok.com/t/…). reddit-post parses a post
580+
# (reddit.com/r/{subreddit}/comments/{id}, reddit.com/comments/{id}, or
581+
# redd.it/{id}) into data.post: title, body as Markdown, type (text, link, image,
582+
# gallery, or video), link_url, subreddit, author, flairs, score, upvote_ratio,
583+
# comment and crosspost counts, NSFW, spoiler, locked, stickied, and archived
584+
# flags, images (every gallery image in order), and video (an MP4 url plus an
585+
# hls_url that carries the audio). data.comments holds the comment tree, each
586+
# comment with id, author, body as Markdown, score, posted_at, depth, parent_id,
587+
# url, is_submitter, is_deleted, and its replies; limit caps the total number of
588+
# comments (default 100), filled shallowest first so whole conversations are kept,
589+
# and data.has_more_comments says whether the thread has more. The sort query of
590+
# the URL (best, top, new, controversial, old, qa) orders the comments.
591+
# reddit-search returns search results for a search URL
592+
# (reddit.com/search?q={query}, or reddit.com/r/{subreddit}/search?q={query} to
593+
# search one subreddit). With type=link or no type it returns posts in the
594+
# reddit-post shape as data.posts, ordered by the sort (relevance, hot, top, new,
595+
# comments) and limited to the t time range (hour, day, week, month, year, all) of
596+
# the URL; type=sr returns communities as data.communities (name, title,
597+
# description, sidebar, subscriber_count, created_at, type, NSFW and quarantine
598+
# flags, language, category, icon and banner URLs, and allowed post types);
599+
# type=user returns accounts as data.users (username, display_name, bio,
600+
# created_at, post and comment karma, avatar and banner URLs, and verified,
601+
# employee, moderator, premium, and NSFW flags). limit caps the number of results
602+
# (default 100), in the order Reddit returns them, and data.has_more says whether
603+
# Reddit has more. reddit-subreddit reads a subreddit URL
604+
# (reddit.com/r/{subreddit}, optionally followed by /hot, /new, /top, /rising, or
605+
# /controversial, with t setting the time range of top and controversial, default
606+
# day) into data.subreddit in the community shape of reddit-search, data.rules
607+
# (name, description, applies_to, violation_reason, created_at), and data.posts in
608+
# the reddit-post shape, ordered like the tab (default hot) and with stickied
609+
# posts flagged; r/all and r/popular return posts with a null subreddit and rules.
610+
# limit caps the posts (default 100) and data.has_more says whether Reddit has
611+
# more. Private and quarantined subreddits return WEBSITE_ACCESS_ERROR.
612+
# reddit-user reads a profile URL (reddit.com/user/{username} or
613+
# reddit.com/u/{username}, optionally followed by /overview, /submitted, or
614+
# /comments, with sort set to new, hot, top, or controversial and t setting the
615+
# time range of top and controversial, default all) into data.user (id, username,
616+
# display_name, bio, created_at, total, post, comment, awardee, and awarder karma,
617+
# avatar and banner URLs, and verified, suspended, employee, moderator, premium,
618+
# and NSFW flags), data.trophies (name, description, icon_url, granted_at, url),
619+
# data.moderated_communities (name, title, url, subscriber_count, icon_url,
620+
# is_nsfw), data.posts in the reddit-post shape, and data.comments, each with id,
621+
# author, body as Markdown, score, posted_at, edited_at, url, subreddit, parent_id
622+
# (null for a top-level comment), is_submitter, is_stickied, distinguished,
623+
# award_count, and the post it was left on (id, title, url, author, is_nsfw). The
624+
# overview tab returns both posts and comments; submitted returns null comments
625+
# and comments returns null posts. limit caps the posts and comments together
626+
# (default 100) and data.has_more says whether Reddit has more. Users who hide
627+
# their activity return empty lists, and suspended accounts return their profile
628+
# with null posts and comments. yelp-search accepts Yelp search URLs with
629+
# find_desc and find_loc, reads start as the result offset, and returns up to 20
630+
# ranked organic businesses in data.businesses with total and pagination.
631+
# yelp-reviews accepts a Yelp business URL (yelp.com/biz/{alias}), uses optional
632+
# start for the offset, and always sorts newest first; unsupported sort and review
633+
# filters are rejected, while tracking params are ignored. It returns up to 20
634+
# latest public reviews in data.reviews with business details and
586635
# pagination.next_offset. Each review has rating, full text, updated_at, and
587636
# author; owner replies and photos are not included. emails accepts any page and
588637
# returns its email addresses as data.emails ([{ email }]), read from mailto
@@ -606,8 +655,10 @@ class PrebuiltParser < ContextDev::Internal::Type::BaseModel
606655
required :type, const: :prebuilt
607656

608657
# @!attribute limit
609-
# google-maps-reviews only. Maximum number of reviews to return. Defaults to 100;
610-
# maximum 1000.
658+
# google-maps-reviews and reddit parsers only. Maximum number of reviews
659+
# (google-maps-reviews, default 100), comments (reddit-post, default 100), or
660+
# results (reddit-search, reddit-subreddit, and reddit-user, default 100) to
661+
# return; maximum 1000.
611662
#
612663
# @return [Integer, nil]
613664
optional :limit, Integer
@@ -627,7 +678,7 @@ class PrebuiltParser < ContextDev::Internal::Type::BaseModel
627678
#
628679
# @param parser [Symbol, ContextDev::Models::WebScrapeParams::ParseParams::PrebuiltParser::Parser] google-maps parses Google Maps business data into data.results. Accepts Maps pla
629680
#
630-
# @param limit [Integer] google-maps-reviews only. Maximum number of reviews to return. Defaults to 100;
681+
# @param limit [Integer] google-maps-reviews and reddit parsers only. Maximum number of reviews (google-m
631682
#
632683
# @param sort [Symbol, ContextDev::Models::WebScrapeParams::ParseParams::PrebuiltParser::Sort] google-maps-reviews only. Order of data.reviews. newest, relevant, highest, and
633684
#
@@ -691,13 +742,62 @@ class PrebuiltParser < ContextDev::Internal::Type::BaseModel
691742
# (/search/user?q={query}) as data.users: id, username, nickname, biography,
692743
# avatar_url, sec_uid, follower_count, like_count, and is_verified. The TikTok
693744
# parsers accept tiktok.com, www.tiktok.com, and m.tiktok.com URLs but not short
694-
# links (vm.tiktok.com, vt.tiktok.com, tiktok.com/t/…). yelp-search accepts Yelp
695-
# search URLs with find_desc and find_loc, reads start as the result offset, and
696-
# returns up to 20 ranked organic businesses in data.businesses with total and
697-
# pagination. yelp-reviews accepts a Yelp business URL (yelp.com/biz/{alias}),
698-
# uses optional start for the offset, and always sorts newest first; unsupported
699-
# sort and review filters are rejected, while tracking params are ignored. It
700-
# returns up to 20 latest public reviews in data.reviews with business details and
745+
# links (vm.tiktok.com, vt.tiktok.com, tiktok.com/t/…). reddit-post parses a post
746+
# (reddit.com/r/{subreddit}/comments/{id}, reddit.com/comments/{id}, or
747+
# redd.it/{id}) into data.post: title, body as Markdown, type (text, link, image,
748+
# gallery, or video), link_url, subreddit, author, flairs, score, upvote_ratio,
749+
# comment and crosspost counts, NSFW, spoiler, locked, stickied, and archived
750+
# flags, images (every gallery image in order), and video (an MP4 url plus an
751+
# hls_url that carries the audio). data.comments holds the comment tree, each
752+
# comment with id, author, body as Markdown, score, posted_at, depth, parent_id,
753+
# url, is_submitter, is_deleted, and its replies; limit caps the total number of
754+
# comments (default 100), filled shallowest first so whole conversations are kept,
755+
# and data.has_more_comments says whether the thread has more. The sort query of
756+
# the URL (best, top, new, controversial, old, qa) orders the comments.
757+
# reddit-search returns search results for a search URL
758+
# (reddit.com/search?q={query}, or reddit.com/r/{subreddit}/search?q={query} to
759+
# search one subreddit). With type=link or no type it returns posts in the
760+
# reddit-post shape as data.posts, ordered by the sort (relevance, hot, top, new,
761+
# comments) and limited to the t time range (hour, day, week, month, year, all) of
762+
# the URL; type=sr returns communities as data.communities (name, title,
763+
# description, sidebar, subscriber_count, created_at, type, NSFW and quarantine
764+
# flags, language, category, icon and banner URLs, and allowed post types);
765+
# type=user returns accounts as data.users (username, display_name, bio,
766+
# created_at, post and comment karma, avatar and banner URLs, and verified,
767+
# employee, moderator, premium, and NSFW flags). limit caps the number of results
768+
# (default 100), in the order Reddit returns them, and data.has_more says whether
769+
# Reddit has more. reddit-subreddit reads a subreddit URL
770+
# (reddit.com/r/{subreddit}, optionally followed by /hot, /new, /top, /rising, or
771+
# /controversial, with t setting the time range of top and controversial, default
772+
# day) into data.subreddit in the community shape of reddit-search, data.rules
773+
# (name, description, applies_to, violation_reason, created_at), and data.posts in
774+
# the reddit-post shape, ordered like the tab (default hot) and with stickied
775+
# posts flagged; r/all and r/popular return posts with a null subreddit and rules.
776+
# limit caps the posts (default 100) and data.has_more says whether Reddit has
777+
# more. Private and quarantined subreddits return WEBSITE_ACCESS_ERROR.
778+
# reddit-user reads a profile URL (reddit.com/user/{username} or
779+
# reddit.com/u/{username}, optionally followed by /overview, /submitted, or
780+
# /comments, with sort set to new, hot, top, or controversial and t setting the
781+
# time range of top and controversial, default all) into data.user (id, username,
782+
# display_name, bio, created_at, total, post, comment, awardee, and awarder karma,
783+
# avatar and banner URLs, and verified, suspended, employee, moderator, premium,
784+
# and NSFW flags), data.trophies (name, description, icon_url, granted_at, url),
785+
# data.moderated_communities (name, title, url, subscriber_count, icon_url,
786+
# is_nsfw), data.posts in the reddit-post shape, and data.comments, each with id,
787+
# author, body as Markdown, score, posted_at, edited_at, url, subreddit, parent_id
788+
# (null for a top-level comment), is_submitter, is_stickied, distinguished,
789+
# award_count, and the post it was left on (id, title, url, author, is_nsfw). The
790+
# overview tab returns both posts and comments; submitted returns null comments
791+
# and comments returns null posts. limit caps the posts and comments together
792+
# (default 100) and data.has_more says whether Reddit has more. Users who hide
793+
# their activity return empty lists, and suspended accounts return their profile
794+
# with null posts and comments. yelp-search accepts Yelp search URLs with
795+
# find_desc and find_loc, reads start as the result offset, and returns up to 20
796+
# ranked organic businesses in data.businesses with total and pagination.
797+
# yelp-reviews accepts a Yelp business URL (yelp.com/biz/{alias}), uses optional
798+
# start for the offset, and always sorts newest first; unsupported sort and review
799+
# filters are rejected, while tracking params are ignored. It returns up to 20
800+
# latest public reviews in data.reviews with business details and
701801
# pagination.next_offset. Each review has rating, full text, updated_at, and
702802
# author; owner replies and photos are not included. emails accepts any page and
703803
# returns its email addresses as data.emails ([{ email }]), read from mailto
@@ -732,6 +832,10 @@ module Parser
732832
TIKTOK_FOLLOWERS = :"tiktok-followers"
733833
TIKTOK_FOLLOWING = :"tiktok-following"
734834
TIKTOK_USER_SEARCH = :"tiktok-user-search"
835+
REDDIT_POST = :"reddit-post"
836+
REDDIT_SEARCH = :"reddit-search"
837+
REDDIT_SUBREDDIT = :"reddit-subreddit"
838+
REDDIT_USER = :"reddit-user"
735839
YELP_SEARCH = :"yelp-search"
736840
YELP_REVIEWS = :"yelp-reviews"
737841
EMAILS = :emails

‎lib/context_dev/models/web_scrape_response.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,10 @@ module Type
928928
TIKTOK_FOLLOWERS = :"tiktok-followers"
929929
TIKTOK_FOLLOWING = :"tiktok-following"
930930
TIKTOK_USER_SEARCH = :"tiktok-user-search"
931+
REDDIT_POST = :"reddit-post"
932+
REDDIT_SEARCH = :"reddit-search"
933+
REDDIT_SUBREDDIT = :"reddit-subreddit"
934+
REDDIT_USER = :"reddit-user"
931935
YELP_SEARCH = :"yelp-search"
932936
YELP_REVIEWS = :"yelp-reviews"
933937
EMAILS = :emails

‎rbi/context_dev/models/batch_get_results_response.rbi‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,26 @@ module ContextDev
21632163
:"tiktok-user-search",
21642164
ContextDev::Models::BatchGetResultsResponse::Data::Ok::Result::Parsed::Type::TaggedSymbol
21652165
)
2166+
REDDIT_POST =
2167+
T.let(
2168+
:"reddit-post",
2169+
ContextDev::Models::BatchGetResultsResponse::Data::Ok::Result::Parsed::Type::TaggedSymbol
2170+
)
2171+
REDDIT_SEARCH =
2172+
T.let(
2173+
:"reddit-search",
2174+
ContextDev::Models::BatchGetResultsResponse::Data::Ok::Result::Parsed::Type::TaggedSymbol
2175+
)
2176+
REDDIT_SUBREDDIT =
2177+
T.let(
2178+
:"reddit-subreddit",
2179+
ContextDev::Models::BatchGetResultsResponse::Data::Ok::Result::Parsed::Type::TaggedSymbol
2180+
)
2181+
REDDIT_USER =
2182+
T.let(
2183+
:"reddit-user",
2184+
ContextDev::Models::BatchGetResultsResponse::Data::Ok::Result::Parsed::Type::TaggedSymbol
2185+
)
21662186
YELP_SEARCH =
21672187
T.let(
21682188
:"yelp-search",
@@ -4889,6 +4909,26 @@ module ContextDev
48894909
:"tiktok-user-search",
48904910
ContextDev::Models::BatchGetResultsResponse::Data::Error::Result::Parsed::Type::TaggedSymbol
48914911
)
4912+
REDDIT_POST =
4913+
T.let(
4914+
:"reddit-post",
4915+
ContextDev::Models::BatchGetResultsResponse::Data::Error::Result::Parsed::Type::TaggedSymbol
4916+
)
4917+
REDDIT_SEARCH =
4918+
T.let(
4919+
:"reddit-search",
4920+
ContextDev::Models::BatchGetResultsResponse::Data::Error::Result::Parsed::Type::TaggedSymbol
4921+
)
4922+
REDDIT_SUBREDDIT =
4923+
T.let(
4924+
:"reddit-subreddit",
4925+
ContextDev::Models::BatchGetResultsResponse::Data::Error::Result::Parsed::Type::TaggedSymbol
4926+
)
4927+
REDDIT_USER =
4928+
T.let(
4929+
:"reddit-user",
4930+
ContextDev::Models::BatchGetResultsResponse::Data::Error::Result::Parsed::Type::TaggedSymbol
4931+
)
48924932
YELP_SEARCH =
48934933
T.let(
48944934
:"yelp-search",

0 commit comments

Comments
 (0)