def main():
    parser = argparse.ArgumentParser(
            prog='modbot.py',
            description="Subreddit automoderating script")
    parser.add_argument('subreddit')
    parser.add_argument('-r', '--rulesdir', default='./rules')
    parser.add_argument('-u', '--user')
    parser.add_argument('-p', '--password')
    args = parser.parse_args()

    rh = RuleHandler(args.rulesdir, '*.rule')

    logging.config.fileConfig('logging.conf')

    reddit = Reddit('%s/%s' % (NAME, VERSION))
    try:
        reddit.login(args.user, args.password)
    except praw.errors.InvalidUserPass:
        logging.critical("Login failure")
        sys.exit(1)

    sub = reddit.get_subreddit(args.subreddit)
    read_thinglists()
    comments_ph = None
    submissions_ph = None

    while True:
        logging.debug("Loop start")
        loopstart = time.time()

        try:
            modqueue_items = sub.get_mod_queue(limit=100)
        except Exception, e:
            modqueue_items = []

        num = 0
        for modqueue_item in modqueue_items:
            num += 1
            matchrules(modqueue_item, rh.rules, is_modqueue=True)
        logging.info("Checked %d modqueue items" % num)

        try:
            if comments_ph == None:
                comments = sub.get_comments(limit=100)
            else:
                comments = sub.get_comments(place_holder=comments_ph,
                        limit=500)
        except Exception, e:
            comments = []

        num = 0
        for comment in comments:
            logging.debug("Checking %s start" % comment.name)
            num += 1
            if comments_ph == None or num == 1:
                comments_ph = comment.id
            matchrules(comment, rh.rules)
            logging.debug("Checking %s done" % comment.name)
        logging.info("Checked %d comments" % num)

        try:
            if submissions_ph == None:
                submissions = sub.get_new(limit=100)
            else:
                submissions = sub.get_new(place_holder=submissions_ph,
                        limit=100)
        except Exception, e:
            submissions = []

        num = 0
        for submission in submissions:
            num += 1
            if submissions_ph == None or num == 1:
                submissions_ph = submission.id
            matchrules(submission, rh.rules)
        logging.info("Checked %d submissions" % num)

        loopend = time.time()
        sleepfor = max(0.0, 30.0 - (loopend - loopstart))
        logging.info("Loop end. Sleeping %f s" % sleepfor)
        time.sleep(sleepfor)
dataset/ETHPy150Open rasher/reddit-modbot/modbot.py/main/original