
Welcome!There was a bit of hype for a tutorial so I had to deliver. If you know 0 python you're probably gonna have a bad time. I'd get versed on the basics first on a site like SoloLearn first. That being said let's get right into it.Why code this yourself / learn to code?If you really get into it and keep learning you can have the program monitor a page, then as soon as the item(s) you want drop, it'll check them out or add them to your cart for you, or open your browser to the page you've been watching, or tweet restocks like @supremealerts does or integrate it to make an app a la Restocks. The possibilities are fucking endless.Section 1 - Getting Started / What you'll needPycharm - where you will actually write all this codePython 2.7 and above JUST NOT 3.0Willingness to learnSection 2 - More PrepGo ahead and crank up pycharm AFTER you have installed any version from 2.7.0 to 2.9.0Next make a new project as shown belowhttp://imgur.com/a/io48DLastly make a new python file and call it whatever you want, IE "monitor.py" "watchpage.py" etc. (note you do not need to add .py at the end)http://ift.tt/2ganGPr 3 - Let's start codingFirst we need to import all the modules we'll need -time for setting delaysrequests to grab the websites contentsmtplib to send our email alerts when those new pieces dropand finally timeit for actually tracking timeYour code should look like the followinghttp://imgur.com/a/QhnT9Skip some lines and put the following code for the first part of our timerhttp://imgur.com/a/8M598Your code should now look like this so farhttp://imgur.com/a/1IXDiSection 4 - Email Alert FunctionNext we're gonna skip a line or two and make our function to email us when something changes called "send_email" by typing the following. We will pass your gmail username, app password, who your mailing it to, subject and body into the function as parameters.http://ift.tt/2gapVCo we have to actually fill in the guts of the function. We'll start off by assigning/reassigning some variables. Go ahead and add this. (it'll make sense later i promise bb gurl)http://ift.tt/2fx2t48 we'll continue to build onto our email sending function. I have written out the following code for you to just paste in because it's a lot and spacing/indentation is fucking crucial here.PASTE THIS INIt essentially creates a message variable from your supplied subject and body variables, and tries to send the email according to your specifications (which we will define later on). If it fails it will print out "failed to send mail," then the reason why.We are now done with our send_email function, your code should look like this.http://ift.tt/2galRCl 5 - main() and requestsJust like we did for our send_email function we're gonna make a function called main but it will have no parameters (things after the parentheses). Be sure to press enter a couple times.http://ift.tt/2fwYd4w enough right? Ok, now we are going to call the Session() function from the requests library in order to grab the content of the site later on. The "as c" part simply means we can type c.blahblah instead of typing out the whole word "requests" every time. Don't get lost its really not that hard or important. Just know "c" is substituted for typing out "requests" every time.http://ift.tt/2gaozHM main function should look like this so farhttp://imgur.com/a/vUox0Your ENTIRE program should be this so farhttp://imgur.com/a/sQAzBSection 5 - Picking a site, how often to check, who to email, and more!First we'll make a string variable called url containing the url we want to monitor - be sure to enclose it in quoteshttp://imgur.com/p9AMu9cNext we'll make an integer variable called wait_time which will be the time in seconds our program waits between checking the site for changes. I recommend a minute or two (60 or 120) to avoid getting blocked.http://ift.tt/2gap6tm make a string variable called user and insert the gmail address you will be emailing yourself from (IE "ucantdress@gmail.com")http://ift.tt/2fx7IRd, in order to allow our program to login to your gmail, you will need to go here and generate an app password. Find this, then hit generate, and this should come up. You will use the App password (IE "fjgi hgjs qiro lskd") you just generated in place of your gmail password when the time comes!Create a string variable called pwd to hold the app password you just madehttp://imgur.com/gIXCoDMMake another string variable this time called recipient to hold the email you want to send tohttp://imgur.com/b8LzZS3More string variables, this time called subject, fill it with the subject line of your choice (IE "SITE UPDATED")http://ift.tt/2gamjjF, we'll make one more string variable called body, and you can't leave this blank or else gmail will filter it as spam and your phone won't vibrate when you receive it etc. In my example I make the body say "CHANGE AT " , then i concatenate it with the url we've been watching in the url variable, as shown below.http://ift.tt/2fwYc0s email will look like this:http://ift.tt/2gakLWW up until this pointhttp://imgur.com/Er3BfTeSection 6 - Timing and checking for changesHere's where the requests module we imported and requests.session() as c we set up earlier come into play. We'll start off by downloading the original page - the page before anything has released or restocked - into a variable called page1 by requesting it.http://ift.tt/2gani3t will put in a super simple piece of code to delay our requests for the time you specified to avoid getting banned and/or crashing the program. Call the time.sleep() function and pass the wait_time variable as the time to sleep.http://ift.tt/2fx4ixX waiting a certain amount of time, we want the program to check the contents of the site again. We'll do this by downloading the contents of the site into a variable again, this time called page2.http://ift.tt/2gapjgj shit gets kinda hard to comprehend if you've never coded before. Plus this is probaly a sloppy af program tbh but we'll worry about that later. We start by making an "if statement" to check if the content of page1 is equal to the content of page2.http://ift.tt/2fx3lp7 next stuff is honestly way to hard to explain through text plus once again spacing/indentation will most likely fuck half of you so I recommend just pasting the following "if else" statement. This snippet prints output based on whether or not the site was changed, and converts seconds to minutes when displaying the elapsed time. If a change is detected it calls the send_email function we made earlier and, well, sends the email(s) according to your specifications.http://ift.tt/2fdGFvO http://ift.tt/2galSGp a few lines then hit backspace after the "if else" statement you just put in. Now we need to clear the page2 variable so it can grab the content of the site again when it's looping through. I did this simply by setting page2 to None.http://ift.tt/2fx4I7k done. Now we just need the program to keep doing this over. Instead of any type of legitimate loop, we just call the main() function within itself so it keeps on doing what we want it to.http://ift.tt/2galbNe step, we just need to call the actual main function by adding this last short section at the very end. I don't even know exactly why this is the way it is but is how things are.http://ift.tt/2fx1NLO that's it. I hope it didn't suck, a video tutorial would have been better but I don't have the means to make one rn. I'm sure half of you are lost as fuck so here's the source. If there are any other hacker skids into infosec and coding please hit me up i'd love to work with you. I just made a discord (i'm Chief Keef#1614). Also feel free to ask questions below and help others where you can. via /r/streetwear http://ift.tt/2gmTOT7
No comments:
Post a Comment