コード例 #1
0
def do(session, df, caughtObj, caughtTxt, query_words=5, reply_char_min=12, scoremax=2, replymax=0):
    replied = pkl.load(fln.fReplied)
    checked = pkl.load(fln.fChecked)
    for post, text in zip(caughtObj, caughtTxt):
        text = text.replace(' bot', '')
        if (len(text) > 0) and (post.id not in checked):
            query = cleanQuery(text)
            if (post.id not in replied) and (post.author != session.user.me()):
                s = query.split(' ')
                if (len(s) >= query_words):
                    print(fnt.colorDarkGray + query + fnt.End)
                    query = ' '.join(s[-query_words:])
                    replycount = 0
                    if isinstance(post, praw.models.Submission):
                        replycount = len(post.comments)
                    elif isinstance(post, praw.models.Comment):
                        try:
                            post.refresh()
                            replycount = len(post.replies)
                        except:
                            replycount = 9999
                    if replycount <= replymax:
                        replies = parseReplies(df, query, reply_char_min, scoremax)
                        if (len(replies)>0):
                            reply = random.choice(replies)
                            subreddit = post.subreddit
                            replyText = assembleReply(subreddit, reply)
                            print('\t' + fnt.bS + reply[2] + fnt.End)
                            post.upvote()
                            post.reply(replyText)
                            replied.append(post.id)
                            pkl.save(fln.fReplied, replied)
            checked.append(post.id)
            pkl.save(fln.fChecked, checked)
コード例 #2
0
def getQualityScore(key):
    dictQS = pkl.load(fln.fQuality)
    score = 0
    if key in dictQS:
        score = int(dictQS[key])
    print('dictQS[\'%s\'] = ' % (key[0:32]+'...') + str(score))
    return score
コード例 #3
0
def replies(comment, goodsig):
    replied = pkl.load(fln.fReplied)
    comment.refresh()
    if len(comment.replies) > 0:
        for reply in comment.replies:
            r = str(reply.body)
            if not (comment.id in replied):
                if 'good bot' in r.lower():
                    reply.upvote()
                    line = random.choice(goodbot)
                    replytext = line + goodsig
                    reply.reply(replytext)
                    print('\t' + line)
                    replied.append(comment.id)
                elif 'bad bot' in r.lower():
                    reply.downvote()
                    line = random.choice(badbot)
                    replytext = line + badsig
                    reply.reply(replytext)
                    print('\t' + line)
                    replied.append(comment.id)
                elif 'coy bot' in r.lower() or 'coy-bot' in r.lower():
                    reply.upvote()
                    replytext = random.choice(coybot)
                    reply.reply(replytext)
                    print('\t' + replytext)
                    replied.append(comment.id)
    pkl.save(fln.fReplied, replied)
コード例 #4
0
def do():
    if drv.exists(fln.fPassword):
        password = pkl.load(fln.fPassword)
    else:
        password = input('Password:')
        pkl.save(fln.fPassword, password)
    session = praw.Reddit(username=username,
                          password=password,
                          client_id=client_id,
                          client_secret=client_secret,
                          user_agent=user_agent)
    return session
コード例 #5
0
def quality(comment, min=1):
    dict = pkl.load(fln.fQuality)
    karma = getKarma(comment)
    if (karma < min):
        body = str(comment.body)
        if '\n' in body:
            key = body.split('\n')[0]
        else:
            key = body
        print(fnt.colorRed + body + fnt.End)
        if str(comment.subreddit) == 'jakeandamir':
            if key in dict:
                dict[key] += 1
            else:
                dict[key] = 1
            print('\tRecorded quality score.')
        comment.delete()
        print("\tDeleted.")
    pkl.save(fln.fQuality, dict)
コード例 #6
0
def init():
    if drv.exist(fln.fDataframe) == False:
        link = "https://www.youtube.com/results?search_query=jake+and+amir+%s"
        titles = []
        links = []
        scripts = []
        soup = getSoup(surl)
        for script in soup.findAll("div", {"class": "episode-script-inner"}):
            scripts.append(
                str(script.text).replace('...', '⋯').replace('..', '⋯'))
        for title in soup.findAll("td", {"class": "header-inner-title"}):
            titles.append(titlecase(title.text))
            links.append(link % str(title.text).replace(' ', '+'))
        archive = pd.DataFrame({
            'Title': titles,
            'Link': links,
            'Script': scripts
        })
        archive = archive.replace('[\t]+', '', regex=True)
        archive = archive.replace('[\r]+', '', regex=True)
        pkl.save(fln.fDataframe, archive)
    df = pkl.load(fln.fDataframe)
    return df