This post has been de-listed (Author was flagged for spam)
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Few days ago I made a python script which edits the game thread as the game progresses to update the scores. Due to the rules of the subs I can not make more than one game threads or post game threads. So I am writing this tutorial and hope that some of you pick the script to run it on your systems. I tried to make this tutorial as comprehensive as possible so that those who don't have any experience with coding can follow it.
Major part of this tutorial is about how to set up Python3 and the script itself. This part in itself might seem hard to you but once the setup is done correctly, making game threads and post game threads becomes extreamly easy. This part of the tutorial consists most of what is written in this thread. I just copied the relevant part in this post.
Setting up Python 3
Windows
Go here to download the latest releases of Python
After you click the latest version you need, you'll want to download the Windows x86-64 MSI installer
and run it.
Next thing you will need is to install some packages for Python to make
the bot work. That's where pip
python's friendly package manager comes in. And luckily with the latest
versions of Python it comes installed with it. So now what you should do is open up
powershell, by going to run and typing in powershell, or searching for it on Win8.
Then you'll want to type in the command to install the package like so:
py -3 -m pip install requests praw
PRAW is an abbrevation for Python Reddit Api Wrapper, we will use it to post/edit our threads. We will use "requests" to hit the nba Api to receive the game data.
Python 3 pip install screenshot
If you get an error along the lines of
the term 'python'/'py' is not recognized as the name of a cmdlet, function, script file, or operable program`
Try typing this into power shell which will point powershell to python when they command is typed in:
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python34", "User") # python 3
If that still gives you errors try setting the path with this:
$env:path="$env:Path;C:\Python34 # python 3
If neither of those get it working, leave a comment, I'm trying to make sure I get all the bases covered with Windows to make this as easy as possible for people to setup!
And there you go, they are all installed! If you have any errors installing these with pip, see this StackOverflow post with fixes for common issues. And if that doesn't help, don't be afraid to ask somebody for help!
Now you are ready to run your bot. From here you have two options, running it from powershell/cmd, or from IDLE.
To run from powershell/cmd type in these commands:
cd C:/Path/To/.py/File # i.e if on Desktop this would be cd C:/Desktop
py -3 nba-game-thread.py
And it should be running!
To run from IDLE, either find IDLE from your program menu or search for it. IDLE is python's interpreter. Then go to file -> open and find your bot_file.py and open it. Then select Run -> Run Module (or press F5). And it'll start running. And there you go, you're running a Reddit bot!
Setup (OS X/Linux)
If you are using Linux, go to command line and run this command:
sudo apt-get python3
If you're on OS X you can either install by going to Python's website and getting the latest releases, or (my personal recommendation) download Homebrew package manager. If you choose the Homebrew route, after installation open terminal and type:
brew install python3
Next thing you will need is to install some packages for Python to make
the bot work. That's where pip
python's friendly package manager comes in. And luckily with the latest
versions of Python it comes installed with it. So now what you should do is open up
powershell, by going to run and typing in powershell, or searching for it on Win8.
Then you'll want to type in the command to install the package like so:
pip install praw requests
PRAW is an abbrevation for Python Reddit Api Wrapper, we will use it to post/edit our threads. We will use "requests" to hit the nba Api to receive the game data.
To run the script from command line do the following:
cd /Path/To/.py/File
python3 nba-game-thread.py
Setting up the script with your account
(This part is same for everyone(I guess))
First of all, you have to download the script. Go to this link, Copy everything in the "code box", paste it to a file and name it "nba-game-thread.py". Go to this link, Copy everything in the "code box", paste it to a file and name it "edit-game-thread.py". You'll have to create another file in the same folder where you saved "nba-game-thread.py" and name it "config_reddit.py", for now leave the file empty.
Now open your browser and go to https://www.reddit.com/prefs/apps/ . Scroll down and you'll see a button in the left "create another app...". When this button is clicked you'll see a form something like this. In the "name" field enter something like "nba-game-thread-generator", choose script option, in the description field you can write "Submits and updates game thread on r/nba", leave about url empty and in redirect uri you can enter "http://localhost:8080", then click on "create app" and you'll see your app under developed application. You should your app like this. The things we are interested in are the key under the "personal use script" line and the secret.
Now open the config_reddit.py that we created and enter the following information:
username = "f1uk3r"
password = "demarismynewdaddy"
client_id = "NOJn2vocumxayQ"
client_secret = "Il53Gmxg9kUusQiwoRO4JYC_FDw"
Now go to "nba-game-thread.py" file and search "response = ", you should get only one result and it will be
response = reddit.subreddit('nba').submit(title, selftext=beforeGameBody, send_replies=False)
Replace "nba" from above line to "test" until you are ready to post it on r/nba.
After saving this, we are done with our set up. Everything we have done till now was to done only once and if you are done with all of this successfully, running the script part is going to be pretty easy.
Running the script
Now go to terminal/command line and navigate through directories to where our script is saved:
For windows
cd C:/Path/To/.py/File # i.e if on Desktop this would be cd C:/Desktop
For OS X/ Linux
cd path/to/file
Now run the script by:
For windows
py -3 nba-game-thread.py
For OS X/ Linux
python3 nba-game-thread.py
You'll see a list of games that will be played today, enter one number corresponding to the game you want to make game thread of and hit enter. Now sit back and relax and let the script run throughout the game, it will stop by itself when the game is finished.
What about "edit" script?
You might have noticed I asked you to make an another file "edit-game-thread.py". But if everything is done by the main script what does this one accomplish? The answer is if everything works smoothly and without any interruptions to the main script, this script is of no use. But if your internet provider is as shitty as mine or you have to sleep/shutdown your system for some reason while the script was running then the main script might stop working. Then you can run this script and it will find the game-thread that have been posted by you and will make the edits same as our main script. All you have to do is, replace the username in the following line to that of yours.
if submission.author.name == "f1uk3r":
i.e. if your username is GOATsChokesSometimes then replace f1uk3r to GOATsChokesSometimes, and then run the script
For windows
py -3 edit-game-thread.py
For OS X/ Linux
python3 edit-game-thread.py
Important points
Please test the script in r/test by replacing "nba" to "test" in the following line of the code:
response = reddit.subreddit('nba').submit(title, selftext=beforeGameBody, send_replies=False)
Run this script on r/test until you are sure that it is working as intended, if you find/notice anything unusual please send me a PM I'll look into it ASAP.
If you live in EST or CST timezone please check this line of code, The number inside the parenthesis should be 0.
now = date.today() - timedelta(0)
Since this post will be seen by only a few people, I'll mention some users who showed interest in this tutorial earlier /u/fortyfive33 /u/dtttfu /u/tskitishvili7
This tutorial have been posted with mod's permission. Everybody is expected to follow the rules of the subs as are mentioned here.
I'll post a similar tutorial regarding posting post game threads in a week or two. You can go to this thread for some idea about PGTs.
If any of you see something wrong in this post, let me know and I'll fix it, good chance I've messed something up (and I don't use Windows that often (haven't used OS X ever) so there's probably some little errors in there).
If you have any questions ask me, I'm always more than willing to help.
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/nba/comment...