- Joined
- Mar 24, 2025
- Messages
- 1,388
- Reaction Score
- 3,566
Another script that makes life easier if you are managing multiple accounts and want to know whether they're banned or how much karma they have.
Can be turned into a service!!
Steps to Create a Google Cloud Project & Run subreddit checker
- Go to the Google Cloud Console
- Visit: https://console.cloud.google.com/
- Log in with your Google account.
- Create a New Project
- Click on the project drop-down at the top of the page (next to "Google Cloud").
- Select New Project.
- Enter the Project Name (e.g., "Accountchecker").
- Choose your Organization and Location (optional).
- Click Create.
- Enable APIs and Services
- Go to the Navigation Menu (☰) > APIs & Services > Library.
- Search for the following APIs and enable them:
- Google Sheets API
- Google Drive API
- Click Enable for each.
- Create Service Account Credentials
- Go to APIs & Services > Credentials.
- Click + CREATE CREDENTIALS > Service Account.
- Provide a Name, ID, and Description.
- Click Create and Continue.
- Grant it Editor permissions (or specific permissions required for your project).
- Click Done.
- Generate and Download JSON Key
- After creating the service account, click on it in the Credentials page.
- Go to the Keys tab and click Add Key > Create New Key.
- Select JSON and download the key file.
- Save this file securely and update the path in your script (path/to/credentials.json).
- Share the Spreadsheet with the Service Account
- Open your Google Spreadsheet.
- Click Share and add the email address of the service account (visible in the JSON key file).
- Give it Editor access.
- Test the Script
- Ensure all dependencies (praw, gspread, oauth2client) are installed.
- Run the script and verify updates in the spreadsheet.
Code:
import praw
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import re
import time
import prawcore
# Reddit API credentials
reddit = praw.Reddit(
client_id='[Your client ID]',
client_secret='[Yourclientsecret]',
user_agent='[useragent by YOuruseragent]',
username='[yourusername]',
password='[yourpassword]'
)
# Google Sheets API credentials
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope)
client = gspread.authorize(creds)
# Open your spreadsheet
spreadsheet = client.open('Accountchecker') # Replace with your sheet name
sheet = spreadsheet.sheet1 # Use the first sheet or specify by name
# Get all usernames from the first column
usernames = sheet.col_values(1)[1:] # Skip header
# Prepare headers if missing
headers = sheet.row_values(1)
if 'Suspended' not in headers:
sheet.update_cell(1, 2, 'Suspended')
if 'Post Karma' not in headers:
sheet.update_cell(1, 3, 'Post Karma')
if 'Comment Karma' not in headers:
sheet.update_cell(1, 4, 'Comment Karma')
# Cache data to reduce API calls
data = sheet.get_all_values()
# Process each username
updates = [] # Cache updates to batch process later
batch_size = 10 # Number of rows to process before batching updates
for i, row in enumerate(data[1:], start=2):
# Skip rows that already have data in the 'Suspended' column
if len(row) > 1 and row[1]: # Check if 'Suspended' column is filled
continue
# Trim spaces and validate username
username = row[0].strip()
if not re.match(r'^[A-Za-z0-9_-]+$', username):
print(f"Invalid username at row {i}: {username}")
updates.append([i, 'Suspended', 'N/A', 'N/A'])
continue
try:
user = reddit.redditor(username)
user.id # Trigger error if suspended
# Attempt to fetch subreddit to detect shadowban
try:
user.subreddit.display_name # Access subreddit info
updates.append([i, 'No', user.link_karma, user.comment_karma])
except Exception:
# Shadowbanned if subreddit info cannot be accessed
updates.append([i, 'Shadowbanned', user.link_karma, user.comment_karma])
except prawcore.exceptions.NotFound:
# Suspended or deleted account
updates.append([i, 'Yes', 'N/A', 'N/A'])
except Exception as e:
print(f"Error processing {username} at row {i}: {e}")
updates.append([i, 'Yes', 'N/A', 'N/A'])
# Pause for 5 seconds to avoid API overuse
time.sleep(5)
# Perform batch update every 10 rows
if len(updates) >= batch_size:
for update in updates:
sheet.update_cell(update[0], 2, update[1]) # Suspended
sheet.update_cell(update[0], 3, update[2]) # Post Karma
sheet.update_cell(update[0], 4, update[3]) # Comment Karma
updates = [] # Clear updates after batch processing
# Final batch update for remaining rows
for update in updates:
sheet.update_cell(update[0], 2, update[1]) # Suspended
sheet.update_cell(update[0], 3, update[2]) # Post Karma
sheet.update_cell(update[0], 4, update[3]) # Comment Karma
print('Update complete!')
All you have to do is fill out the usernames in the correct Column.