Created
January 24, 2021 16:09
-
-
Save plu5/90e9edae33ef7d982445fbaafeaf409a to your computer and use it in GitHub Desktop.
Reddit tally number of comments on a list of threads per user using PRAW [yet again]
This file contains hidden or 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
| import praw | |
| from collections import defaultdict | |
| discussion_threads = \ | |
| ["https://www.reddit.com/r/Yogscast/comments/ete47v/did_you_hear_about_the_guy_who_ate_kevin_bacons/", | |
| "https://www.reddit.com/r/Yogscast/comments/ews83c/did_you_hear_about_the_tortoise_that_had_800/", | |
| "https://www.reddit.com/r/Yogscast/comments/f0e71c/nasa_says_this_10_plant_will_save_your_life/", | |
| "https://www.reddit.com/r/Yogscast/comments/f3vz67/haunted_elsa_doll_returns_from_the_dead_twice/", | |
| "https://www.reddit.com/r/Yogscast/comments/f7eydi/grandma_falls_from_7th_storey_window_and_survives/", | |
| "https://www.reddit.com/r/Yogscast/comments/fayroa/uks_first_cheesethemed_hotel_opens_for_business/", | |
| "https://www.reddit.com/r/Yogscast/comments/fehcli/the_rats_that_learnt_to_drive_tiny_cars/", | |
| "https://www.reddit.com/r/Yogscast/comments/fi3uc5/penis_man_graffiti_artist_arrested_by_25_swat/", | |
| "https://www.reddit.com/r/Yogscast/comments/flzj1g/bride_gambles_on_fart_and_loses_in_a_big_way/", | |
| "https://www.reddit.com/r/Yogscast/comments/fq1y9n/why_this_prime_real_estate_is_selling_for_only/", | |
| "https://www.reddit.com/r/Yogscast/comments/fuc1ve/20000_artwork_accidentally_destroyed_by_critic/", | |
| "https://www.reddit.com/r/Yogscast/comments/fyjqf4/mum_trapped_under_bed_drinks_own_vomit_to_survive/", | |
| "https://www.reddit.com/r/Yogscast/comments/g35xn5/top_40_florida_man_stories/", | |
| "https://www.reddit.com/r/Yogscast/comments/g7c2mg/dog_named_mayor_of_us_town/", | |
| "https://www.reddit.com/r/Yogscast/comments/gblw6t/baboon_threesome_runs_loose_in_australian_hospital/", | |
| "https://www.reddit.com/r/Yogscast/comments/gfwxfk/horse_allowed_on_plane_flies_first_class/", | |
| "https://www.reddit.com/r/Yogscast/comments/gkcyj6/man_brings_llama_to_sisters_wedding/", | |
| "https://www.reddit.com/r/Yogscast/comments/gon4q5/parents_let_11yearold_drive_to_distract_him_from/", | |
| "https://www.reddit.com/r/Yogscast/comments/gswsmr/world_record_pizza_has_257_types_of_cheese/", | |
| "https://www.reddit.com/r/Yogscast/comments/gx8evl/pig_starts_farm_fire_with_its_own_poo/", | |
| "https://www.reddit.com/r/Yogscast/comments/h7ol40/womans_first_date_turns_into_bank_robbery/", | |
| "https://www.reddit.com/r/Yogscast/comments/hc4eoc/man_burns_down_house_trying_to_kill_snake/", | |
| "https://www.reddit.com/r/Yogscast/comments/hgbezm/dog_captured_by_hawk_found_28_hours_later/", | |
| "https://www.reddit.com/r/Yogscast/comments/hkmr6c/van_dwelling_hipster_tattoos_entire_body_blue/", | |
| "https://www.reddit.com/r/Yogscast/comments/hosnq9/reading_the_best_headlines_ever/", | |
| "https://www.reddit.com/r/Yogscast/comments/ht0ahc/the_weirdest_mcdonalds_food_from_around_the_world/", | |
| "https://www.reddit.com/r/Yogscast/comments/hx5jfe/rare_exotic_bird_is_actually_seagull_covered_in/", | |
| "https://www.reddit.com/r/Yogscast/comments/i1b5rc/this_doctor_can_make_you_taller/", | |
| "https://www.reddit.com/r/Yogscast/comments/i5hjwu/florida_man_strikes_again/", | |
| "https://www.reddit.com/r/Yogscast/comments/i9pr21/haunted_toaster_posessed_by_devil/", | |
| "https://www.reddit.com/r/Yogscast/comments/ie0n6w/alcoholic_monkey_attacks_250_people/", | |
| "https://www.reddit.com/r/Yogscast/comments/iiavvq/this_giant_teddy_bears_massive_legs_are_freaking/", | |
| "https://www.reddit.com/r/Yogscast/comments/imjs2f/ninja_studies_degree_now_available_simons/", | |
| "https://www.reddit.com/r/Yogscast/comments/iquip4/duck_walks_into_pub_downs_pint_fights_dog_loses/", | |
| "https://www.reddit.com/r/Yogscast/comments/iv9zzj/airplane_passenger_attempts_to_reheat_pizza_using/", | |
| "https://www.reddit.com/r/Yogscast/comments/iznaem/the_explosive_physics_of_pooping_penguins_simons/", | |
| "https://www.reddit.com/r/Yogscast/comments/j3ydlt/author_of_book_on_mushrooms_lets_mushrooms_eat/", | |
| "https://www.reddit.com/r/Yogscast/comments/j82ut6/the_only_surgeon_with_a_300_percent_mortality/", | |
| "https://www.reddit.com/r/Yogscast/comments/jcdnsn/the_man_who_made_a_fortune_from_terrible_business/", | |
| "https://www.reddit.com/r/Yogscast/comments/jgr4or/the_very_first_pepe_peculiar_portions_classique/", | |
| "https://www.reddit.com/r/Yogscast/comments/jl1sj8/simons_spookuliar_portions/", | |
| "https://www.reddit.com/r/Yogscast/comments/jp9y9b/the_fart_that_could_have_ended_the_world_simons/", | |
| "https://www.reddit.com/r/Yogscast/comments/jtkp7t/inflatable_childrens_toy_mistakenly_given_very/", | |
| "https://www.reddit.com/r/Yogscast/comments/jxu0jh/real_life_annabelle_escapes_simons_peculiar/", | |
| "https://www.reddit.com/r/Yogscast/comments/k264xm/lewis_and_simon_talk_about_crabs_for_19_minutes/", | |
| "https://www.reddit.com/r/Yogscast/comments/k6pzth/this_sheep_costs_490000_for_one_reason_simons/", | |
| "https://www.reddit.com/r/Yogscast/comments/kb7r0y/watching_the_professional_slapping_world/", | |
| "https://www.reddit.com/r/Yogscast/comments/kk34dl/looking_at_the_strangest_christmas_meals_simons/", | |
| "https://www.reddit.com/r/Yogscast/comments/kofowp/this_lizard_holds_the_world_record_for_largest/", | |
| "https://www.reddit.com/r/Yogscast/comments/kt7wio/nude_news_simons_peculiar_portions/", | |
| "https://www.reddit.com/r/Yogscast/comments/kxzyxr/the_queens_caravan_is_now_available_simons/", | |
| "https://www.reddit.com/r/Yogscast/comments/l2t6cn/youtuber_sets_fire_to_200000_car_for_content/"] | |
| reddit = praw.Reddit(client_id='PLACEHOLDER CLIENT ID', | |
| client_secret='PLACEHOLDER CLIENT SECRET', | |
| user_agent='PLACEHOLDER USER AGENT') | |
| tally = defaultdict(int) | |
| for url in discussion_threads: | |
| submission = reddit.submission(url=url) | |
| # do away with MoreComments objects | |
| submission.comments.replace_more(limit=None) | |
| comments = submission.comments.list() | |
| for comment in comments: | |
| author = comment.author.name if comment.author else "[deleted]" | |
| tally[author] += 1 | |
| # output | |
| print("Total participants: ", len(tally)) | |
| for index, k in enumerate(sorted(tally, key=tally.get, reverse=True)): | |
| print(index + 1, ':', k, tally[k]) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2nd year (same thing with the 19 new threads added):