Jump to content

Hakshop Checker


newbi3
 Share

Recommended Posts

I wrote this program to notify me when the mk 5 was available. I released it to people in IRC when I wrote it because I didn't want everyone to get to the mk5 first :p

(there have been updates to it since the version I released in IRC)

#!/usr/bin/python

'''
Author Newbi3
Date October 10, 2013

This script will get a hash of the hakshop and compare it to a base hash.
if the hash changes then you know that there has been an update to it such
as the new pineapple :D
'''

import requests
import hashlib
import smtplib
from time import sleep

url = "http://hakshop.myshopify.com/"
baseHash = ""

account = "youremail@gmail.com"
password = "yourpassword"
number = "1234567890"
gateway = "texting.net"

def sendMessage(message):
	''' Login and send the message to the user '''
	server = smtplib.SMTP("smtp.gmail.com", 587)
	server.ehlo()
	server.starttls()
	server.login(account, password)
	headers = "\r\n".join(["from: " + account,
                       "subject: pineapple",
                       "to: " + number + "@" + gateway,
                       "mime-version: 1.0",
                       "content-type: text/html"])
	content = headers + "\r\n\r\n" + message
	server.sendmail(account, number + "@" + gateway, content)
	server.quit()

def compareHash(newHash):
	''' Compare baseHash with newHash '''
	global baseHash
	if (str(baseHash) == str(newHash)):
		print "No updates yet :/"
	else:
		baseHash = str(newHash)
		print "Something has been changed! " + newHash
		sendMessage("Something has been changed at the shop!")

def getHash(respondse):
	''' Get the sha224 hash of respondse '''
	return hashlib.sha224(respondse).hexdigest()

def removeShit(html):
	''' Remove shit from the html code that makes the page to dynamic '''
	lines = html.split("\n")
	for i in range(0, len(lines)-1):
		if ('<script type="text/javascript">var __st={"a":682142,"offset":-25200,' in lines[i]):
			lines[i] = ""
	return ''.join(lines)

def makeRequest(url):
	''' Make the request and return the code '''
	r = requests.get(url)
	return r.text

def main():
	''' Start the program '''
	global baseHash
	baseHash = ""
	baseHash = getHash(removeShit(makeRequest(url)))
	print "Got base hash " + str(baseHash)
	sleep(30)
	while True:
		r = makeRequest(url)
		compareHash(getHash(removeShit(r)))
		sleep(60)

main()

Even though the mk5 is out now this same code can be used to monitor other sites as well or aspects of it may be useful to your project. Just give me credit :D

Link to comment
Share on other sites

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...