Cov txheej txheem:

Reddit Teb Bot: 10 Kauj Ruam
Reddit Teb Bot: 10 Kauj Ruam

Video: Reddit Teb Bot: 10 Kauj Ruam

Video: Reddit Teb Bot: 10 Kauj Ruam
Video: 10 More Gamers Who Achieved The IMPOSSIBLE 2024, Hlis ntuj nqeg
Anonim
Reddit Teb Bot
Reddit Teb Bot
Reddit Teb Bot
Reddit Teb Bot

Lub hom phiaj ntawm phau ntawv qhia no yog tsim kom yooj yim Reddit bot. Reddit bot yog qhov program uas txheeb xyuas cov ntawv/lus pom ntawm Reddit, thiab tuaj yeem ua rau cov ntaub ntawv nws khaws. Qhov no tuaj yeem yog qhov tseem ceeb rau ntau qhov laj thawj, zoo li tau paub nrog Reddit API (Application Programming Interface) siv PRAW lossis kom teb tau yooj yim rau ntau cov ntawv ib zaug. Txhawm rau txhawm rau sib tw qhov no, koj yuav tsum muaj tus lej Reddit, yuav tsum muaj qee qhov kev paub nrog coding hauv Python thiab xav kom muaj koj li kab ke system PATH sib txawv rau Python teeb tsa kom koj tuaj yeem sau Python ntawm kab hais kom ua lossis davhlau ya nyob twg. Yog tias tsis muaj qhov ua rau koj nkag siab, tej zaum koj tsis tau npaj rau qhov kev qhia no. Yog tias cov kauj ruam no tau ua tiav, qhov no yuav tsum ua tiav tsis pub dhau 30 feeb. Hmoov zoo thiab kuv vam tias koj pom cov ntaub ntawv no, zoo siab botting!

Kauj ruam 1: Nkag mus thiab Tsim Tus Kheej Tus Kheej

Nkag mus thiab Tsim Tus Kheej Tus Kheej
Nkag mus thiab Tsim Tus Kheej Tus Kheej
Nkag mus thiab Tsim Tus Kheej Tus Kheej
Nkag mus thiab Tsim Tus Kheej Tus Kheej

Thawj zaug nkag mus rau Reddit lossis ua tus account thiab mus rau https://ssl.reddit.com/prefs/apps/ los tsim tus kheej app.

Kauj ruam 2: Tsim App

Tsim App
Tsim App

Lub npe app thiab ua kom ntseeg tau tias cov kab ntawv tau sau, tseem ntxiv lub npe thiab cov lus piav qhia rau app (tuaj yeem yog txhua yam), koj tuaj yeem siv qhov url tsis raug rau qhov hloov pauv url xws li https:// localhost:

Kauj ruam 3: App Screen

App Screen
App Screen

Thaum koj tau tsim lub app, koj tau muab 'tsab ntawv siv tus kheej' thiab 'zais cia', xyuas kom koj nco qab tias cov ntawd yog dab tsi, tseem ceeb heev.

Kauj Ruam 4: Ua RedditBot Folder thiab Qhib CMD

Ua RedditBot Folder thiab Qhib CMD
Ua RedditBot Folder thiab Qhib CMD

Tsim daim nplaub tshev tshiab ntawm koj lub desktop hu ua, "RedditBot" thiab qhib cmd lossis davhlau ya nyob twg. Tom qab ntawd, mus rau nws phau ntawv teev npe siv cd/Users/Admin/Desktop/RedditBot. Kuj tseem nco ntsoov hloov Admin nrog koj tus lej siv.

Kauj Ruam 5: Pip Install PRAW

Pip Install PRAW
Pip Install PRAW
Pip Install PRAW
Pip Install PRAW

Tom qab ntawd, ntaus cov lus txib sej -m pip install praw, hla yog tias koj twb tau teeb tsa.

Kauj Ruam 6: Luag Praw.ini Cov Ntaub Ntawv rau hauv Folder

Luag Praw.ini Cov Ntaub Ntawv Rau Hauv Cov Ntawv
Luag Praw.ini Cov Ntaub Ntawv Rau Hauv Cov Ntawv
Luag Praw.ini Cov Ntaub Ntawv Rau Hauv Cov Ntawv
Luag Praw.ini Cov Ntaub Ntawv Rau Hauv Cov Ntawv

Thaum koj ua tiav qhov ntawd, mus rau qhov chaw koj tau nruab Python thiab ntaus hauv finder praw.ini, coj cov ntawv ntawd thiab rub nws mus rau hauv koj li RedditBot nplaub tshev. Feem ntau yuav Python yuav raug teeb tsa hauv Cov Neeg Siv thiab AppData hauv C tsav.

Kauj Ruam 7: Ua Cov Ntaub Ntawv Python Tshiab

Ua Tus Python File Tshiab
Ua Tus Python File Tshiab
Ua Tus Python File Tshiab
Ua Tus Python File Tshiab

Qhib Python IDLE lossis cov ntawv nyeem sib npaug thiab tsim cov ntawv tshiab hu ua reddit_bot.py. Nco ntsoov khaws nws hauv koj phau ntawv RedditBot uas koj tau ua hauv qib 4.

Kauj Ruam 8: Muab tshuaj txhuam cov Code

Muab tshuaj txhuam txoj cai
Muab tshuaj txhuam txoj cai

Tom qab koj tsim cov ntawv ntawd, muab tshuaj txhuam cov cai no hloov me me. Hloov cov npe neeg siv thiab tus lej nkag mus rau koj tus kheej, tus neeg siv khoom siv tuaj yeem yog ib qho twg, tus neeg siv khoom siv yog koj tus kheej siv tsab ntawv los ntawm kauj ruam 3, thiab tus neeg siv khoom ntiag tug yog koj li kev zais ntawm kauj ruam 3. Tsis tas li ntawd, thaum muab cov lej no ua kom ntseeg tau tias qhov kev nkag mus zoo ib yam daim duab saum toj no. Kuj xyuas kom tseeb tias txhua qhov sib txawv koj nkag mus yog nyob hauv cov lus hais tawm.

#!/usr/bin/python import praw

#Nkag mus rau koj cov ntaub ntawv Reddit raug rau hauv qhov sib txawv hauv qab no

userAgent = 'Sau lub npe Bot'

cID = 'Sau koj tsab ntawv siv tus kheej'

cSC = 'Nkag mus rau koj cov neeg siv khoom zais'

userN = 'Sau koj lub npe siv Reddit'

userP = 'Sau koj tus password Reddit'

numFound = 0

reddit = praw. Reddit (user_agent = userAgent, client_id = cID, client_secret = cSC, username = userN, password = userP)

subreddit = reddit.subreddit ('huab cua') #txhua subreddit koj xav saib xyuas

bot_phrase = 'Aw shucks, zoo li kuv nyob hauv>:(' #phrase uas bot teb nrog

keywords = {'Mob khaub thuas', 'chicago', 'ncov qaumteb', 'vortex'} #muaj txheej cov ntsiab lus los nrhiav hauv subreddits

rau kev xa hauv subreddit.hot (txwv = 10): #this saib saum 10 cov lus tshaj tawm hauv qhov subbreddit

n_title = submission.title.lower () #Make cov npe kab ntawv me me yog li peb tuaj yeem sib piv peb cov ntsiab lus nrog nws.

rau kuv hauv cov ntsiab lus: #dhau los ntawm peb cov ntsiab lus

yog tias kuv nyob hauv n_title: #if ib ntawm peb cov ntsiab lus sib xws lub npe nyob rau sab saum toj 10 ntawm subreddit

numFound = numFound + 1

print ('Bot teb rau:') #teb thiab xa tawm mus rau kab hais kom ua

print ("Title:", xa tawm.title)

print ("Cov ntawv:", submission.selftext)

print ("Cov qhab nia:", xa tawm.score)

luam tawm ("---------------------------------")

print ('Bot hais tias:', bot_phrase)

luam tawm ()

xa tawm.reply (bot_phrase)

Yog hais tias numFound == 0:

luam tawm ()

print ("Thov txim, tsis pom muaj cov lus tshaj tawm nrog cov lus tseem ceeb, sim dua!")

Kauj ruam 9: Khiav Koj Cov Cai

Khiav Koj Cov Cai!
Khiav Koj Cov Cai!
Khiav Koj Cov Cai!
Khiav Koj Cov Cai!

Tom qab ntawd khaws cov ntawv hauv koj phau ntawv RedditBot thiab khiav nws ntawm cmd nrog pythonreddit_bot.py

Kauj ruam 10: Thiab Qhov ntawd yog nws

Tam sim no koj yuav tsum muaj Reddit bot ua haujlwm, muaj peev xwm txheeb xyuas los ntawm koj cov subreddit nyiam thiab teb tau nrog cov kab lus xav tau. Koj kuj tseem tuaj yeem siv tus lej no ua qhov pib zoo rau lwm qhov Reddit bot cov tswv yim, uas tuaj yeem yog ib yam dab tsi los ntawm kev hloov pauv kub, los teb rau cov tib neeg nrog cov duab miv. Ua tsaug rau kev nyeem dhau, vam tias qhov no muaj txiaj ntsig thiab hmoov zoo rau txhua txoj haujlwm yav tom ntej.

Pom zoo: