<jupyter_start><jupyter_text>Data Scrapping from Reddit<jupyter_code>import praw
from praw.models import MoreComments
import pandas as pd
import datetime as dt
# This is reddit API PRAW, Enter your DETAILS
reddit = praw.Reddit(client_id='id',
                     client_secret="secret",
                     user_agent='app-name',
                     username='your-username',
                     password='<PASSWORD>')
# These are all the available flairs for subreddit india
flairs = ['Business/Finance','Food','Sports','Politics','Science/Technology',
          'Policy/Economy','Photography','Scheduled','Non-Political',
          'Coronavirus','AskIndia']

# selecting india for subreddit
subreddit = reddit.subreddit('india')
# We need these features of each posts
topics = { "title":[], "url":[], "comms_num": [], "flair": 
               [], "score": [], "id": [], "comments": [], "created": [], "author": [], "body":[]}
# Fetching data for each flairs and appending it to the dict topics
# Setting limit to 20000
# We are only fetching root comments as it would take lot of time due to SLOW API
# Reddit API is very slow therefore limiting the comments

for flair in flairs:
    india= subreddit.new(limit=20000)
    for submission in india:
        topics["flair"].append(submission.link_flair_text)
        topics["title"].append(submission.title)
        topics["url"].append(submission.url)
        topics["comms_num"].append(submission.num_comments)
        c = []
        submission.comments.replace_more(limit=0)
        for comment in submission.comments.list():
            c.append(comment.body)
        topics["comments"].append(c)
        topics["score"].append(submission.score)
        topics["created"].append(submission.created)
        topics["author"].append(submission.author)
        topics["id"].append(submission.id)
        topics["body"].append(submission.selftext)
# Printing no of counts of each flair

print("Food: ",str(topics["flair"].count("Food")))
print("Sports: ",str(topics["flair"].count("Sports")))
print("Politics: ",str(topics["flair"].count("Politics")))
print("Policy Economy: ",str(topics["flair"].count("Policy/Economy")))
print("Photography: ",str(topics["flair"].count("Photography")))
print("Coronavirus: ",str(topics["flair"].count("Coronavirus")))
print("AskIndia: ",str(topics["flair"].count("AskIndia")))
print("Non-Political: ",str(topics["flair"].count("Non-Political")))
print("Science/Technology: ",str(topics["flair"].count("Science/Technology")))
print("Business/Finance: ",str(topics["flair"].count("Business/Finance")))
print("Scheduled: ",str(topics["flair"].count("Scheduled")))
# Convert dict to dataframe
topics_df = pd.DataFrame(topics)
# Convert dataframe to csv file
topics_df.to_csv('india.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16554174067495558, 'fraction_numerical': 0.003907637655417406, 'mean_word_length': 4.532416502946955, 'pattern_counts': {'":': 10, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '361425', 'license': 'MIT', 'n_tokens_mistral': 899, 'n_tokens_neox': 863, 'n_words': 180, 'path': 'notebooks/Part 1-Reddit Data Scraping.ipynb', 'repo_name': 'imskr/reFlair', 'size': '2818'}