Last active
July 26, 2022 13:02
-
-
Save digitalsleuth/6167bfaa653c8e15905cbb52923f02e3 to your computer and use it in GitHub Desktop.
Reddit Wallet Address Scraper for NFT Giveaways
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
#!/usr/bin/env python3 | |
""" | |
This script is for parsing ETH wallet addresses from | |
Reddit comments for delivery of NFT's | |
""" | |
import sys | |
import re | |
import argparse | |
import praw | |
__version__ = '0.0.2' | |
__author__ = 'Corey Forman - @digitalsleuth' | |
__date__ = '26 JUL 2022' | |
def parse_comments(url, subreddit, output): | |
"""Reads through all comments and grabs wallet addresses""" | |
raw_wallet_regex = re.compile("0x.{40}") | |
ens_wallet_regex = re.compile("\w+\.?\w+\.eth") | |
addresses = [] | |
post_comments = [] | |
u_agent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0" | |
post = f'https://www.reddit.com/r/{subreddit}/comments/{url}' | |
reddit_ro = praw.Reddit(client_id="", | |
client_secret="", | |
user_agent=u_agent) | |
submission = reddit_ro.submission(url=post) | |
submission.comments.replace_more(limit=None) | |
for comment in submission.comments.list(): | |
post_comments.append(comment.body) | |
for comment in post_comments: | |
raw = re.search(raw_wallet_regex, comment) | |
ens = re.search(ens_wallet_regex, comment) | |
if raw and not ens: | |
addresses.append((raw.group()).lower()) | |
elif ens and not raw: | |
addresses.append((ens.group()).lower()) | |
elif ens and raw: | |
addresses.append((ens.group()).lower()) | |
de_dup = sorted(set(addresses)) | |
with open(output, 'w') as output_file: | |
for each_address in de_dup: | |
output_file.write(f'{each_address}\n') | |
output_file.close() | |
def main(): | |
"""Parse all passed arguments""" | |
arg_parse = argparse.ArgumentParser(description=f"Python 3 Reddit Wallet Address parser" | |
f" v{__version__}") | |
arg_parse.add_argument('-u', '--url', help='short URL for the reddit thread', required=True) | |
arg_parse.add_argument('-s', '--subreddit', help='subreddit to parse', required=True) | |
arg_parse.add_argument('-o', '--output', help='choice in output file', required=True) | |
arg_parse.add_argument('-v', '--version', action='version', version=arg_parse.description) | |
if len(sys.argv[1:]) == 0: | |
arg_parse.print_help() | |
arg_parse.exit() | |
args = arg_parse.parse_args() | |
parse_comments(args.url, args.subreddit, args.output) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment