<jupyter_start><jupyter_text>Preferred form of data extraction, that extracts data based on post flairs and not the hottest posts<jupyter_code>import pandas as pd
import praw #PRAW is the API being used to scrap data from Reddit
### Creating a reddit instance by authenticating ourselves
reddit = praw.Reddit(client_id='', client_secret='', user_agent='', password='', username='')<jupyter_output><empty_output><jupyter_text>Note: The client_id, client_secret and password are anonymised to prevent privacy 1. get subreddit info of india subreddit<jupyter_code>india_subreddit = reddit.subreddit('India')<jupyter_output><empty_output><jupyter_text>2. Extracting the possible flairs<jupyter_code>def get_possible_flairs(subreddit):
    possibleflairs = []

    for template in subreddit.flair.link_templates:
        possibleflairs.append(template["text"])
    return possibleflairs

possibleflairs = get_possible_flairs(india_subreddit)
possibleflairs<jupyter_output><empty_output><jupyter_text>New way of data extraction<jupyter_code>newDataset = []
for flair in possibleflairs:
    for sub in india_subreddit.search(flair, limit=500):
        newDataset.append([sub.title, sub.id, sub.url, sub.selftext, flair])
newDataset = pd.DataFrame(newDataset, columns=['Title', 'id', 'url', 'content', 'flair'])
newDataset
# step 5: save the data in a csv
newDataset.to_csv('newdataset.csv', index=False) 

#index=False will prevent the row numbers from being saved as an independent column/attribute in the saved csv file<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09650259067357513, 'fraction_numerical': 0.0038860103626943004, 'mean_word_length': 6.842639593908629, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '406077', 'license': 'MIT', 'n_tokens_mistral': 491, 'n_tokens_neox': 489, 'n_words': 134, 'path': 'Jupyter Notebooks/.ipynb_checkpoints/Data Extraction - Preferred-checkpoint.ipynb', 'repo_name': 'ShreyaGupta08/Flare-Detector-for-Reddit-Data', 'size': '1544'}