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 months ago I made a python script which submits Post game Threads with more than just traditional boxscores. A few days back I made further improvement to include highlights as well. 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.
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 bs4 tabulate pafy
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. 'bs4' and pafy is used to get data from youtube. 'tabulate' is used make some tables.
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 bs4 tabulate pafy
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. 'bs4' and pafy is used to get data from youtube. 'tabulate' is used make some tables.
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
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-postgame-thread.py". Go to this link, Copy everything in the "code box", paste it to a file and name it "edit-postgame-thread.py". You'll have to create another file in the same folder where you saved above mentioned files and name it "config.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.py that we created and enter the following information:
username = "f1uk3r"
password = "demarismynewdaddy"
client_id = "NOJn2vocumxayQ"
client_secret = "Il53Gmxg9kUusQiwoRO4JYC_FDw"
FYI: Don't use my usernames and password, that'll not work.
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. I have one more thing to add that right now I have made my script post to r/test by default, changing it to r/nba is pretty easy you just have to read some more of this.
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-post-game-thread.py
For OS X/ Linux
python3 nba-post-game-thread.py
You'll see a list of games that are finished at this time, enter one number corresponding to the game you want to make post game thread of and hit enter. Now sit back and relax and the script will automatically submits the post game thread of the game that was choosen. The list will only show games which that are finished not all the games that'll be played on that day.
What about "edit" script?
I told you earlier that we will be adding highlights from reddit and youtube as well, this is where edit
script comes into play. First, 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-postgame-thread.py
For OS X/ Linux
python3 edit-postgame-thread.py
When you run the script, if you had made more than one postgame threads in last 24 hours you'll be prompted to choose which post you want to make edit to. Choose the concerned post game thread by selecting index number against the thread title. You can see an example in this image where I choose "0" for Raptors vs Clippers game. Then you'll probably see a long list of thread titles. They are all the streamable links that have been posted in the sub as a post in r/nba in last 24 hours. Choose the relevant titles by using numbers against them. You can choose multiple threads in one go by using index numbers seperated by "space" i.e. 0 3 5 10 15
means you have selected 0, 3, 5, 10 and 15th titles to be added in the post. Try to link only relevant streamables to the game. Here is an image for an example. You can see I chose some index from the same game. There will be times (especially Teams like Spurs, Grizzlies, Hornets, Nets) when there will be no streamable highlights will be posted, you can hit enter without chosing any number in that situation. After you hit enter you'll be given a list of some of trusted highlight youtube channels (don't choose 'House of Highlight', automod will delete your thread). Again choose one of the channel with index and hit enter which will give you list of last 15 videos by that channel. Here is the image for reference. Choose the relevant ones by separating them with space. Remember this The first youtube highlight should be full game highlight because it will be cationed as one. Repeat this untill you are satisfied. Incase you don't find any relevant highlights in a choosen channel just hit enter without entering any integer. When you are done press 0 and your post will be edited. Remember one more thing that this script is optimised in a way that only one edit will look good so try to run it after 30 min of actual posting of thread so that you can accumulate maximum highlights. You'll get used to this after 3-4 tries.
Tutorial Video
Here is a streamable to show a run to both of the scripts. subscribe to PewDiePie
Important points
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. When you are satisfied that it is working fine on r/test and want to post on r/nba then search
reddit.subreddit('test')
and change 'test' to 'nba'
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)
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...