From 248fafecbf12b6d7850284fac575f045d5127356 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Thu, 31 Aug 2017 16:12:53 +0000 Subject: [PATCH] Got everything working --- README.md | 8 ++++++-- main.py | 29 +++++++++++++++++++++++++++++ praw.ini | 10 ++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 main.py diff --git a/README.md b/README.md index f533741..27b941b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Is Anybody Here Bot -###### v0.0.0 +###### v0.1.0 [Keith Irwin](https://keithirwin.us/) -TODO: Write readme +To run the bot, simply run main.py with python3, setting environment variables for praw: + +```sh +praw_client_id=XXXXXXXXXXXXXX praw_client_secret=XXXXXXXXXXXXXXXXXXXXXXXXXXX praw_password=XXXXXXXX python main.py +``` diff --git a/main.py b/main.py new file mode 100644 index 0000000..b595c1e --- /dev/null +++ b/main.py @@ -0,0 +1,29 @@ +#!./env/bin/python +# main.py + + +import praw, pdb, re, os + +# Setup reddit and subs +reddit = praw.Reddit('DEFAULT') +rall = reddit.subreddit('all') +sub = reddit.subreddit('IsAnybodyHere') + +# Search latest comments in r/all +for comment in rall.stream.comments(): + + # Match with regex + match = re.search("(does|has|is)(n't)? (any one|anyone|someone|anybody) (here)? (.*)\?", comment.body, re.IGNORECASE) + if match: + + # Extract a description of the needed person + needed = match.group(3), 'who', match.group(1), match.group(5) + print(match.group(),'\n',needed,'\n') + + # Reply to the comment + #response = comment.reply( "I'll look for someone who", match.group(1), match.group(5) ) + #print("Replied to comment "+comment.id+":",response.permalink()) + + # Post to our sub + post = sub.submit(needed.title(), url='https://www.reddit.com'+comment.permalink(), resubmit=False) + print("Posted to sub:",post.shortlink) diff --git a/praw.ini b/praw.ini index 54d8393..87f7655 100644 --- a/praw.ini +++ b/praw.ini @@ -1,3 +1,10 @@ +[DEFAULT] +check_for_updates=True + +# Object to kind mappings +comment_kind=t1 +message_kind=t4 +redditor_kind=t2 submission_kind=t3 subreddit_kind=t5 @@ -5,6 +12,5 @@ oauth_url=https://oauth.reddit.com reddit_url=https://www.reddit.com short_url=https://redd.it -[isanybodyherebot] username=IsAnybodyHereBot -user_agent=u/IsAnybodyHereBot v0.0.0 +user_agent=u/IsAnybodyHereBot v0.1.0