Last active
October 6, 2016 06:59
-
-
Save zatarra/11041635 to your computer and use it in GitHub Desktop.
Kickstarter new project notifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
date_default_timezone_set("Europe/Lisbon"); | |
############################################################## | |
# KICKSTARTER CRAWLER | |
# Author: David Gouveia | |
# Email: david.gouveia [_AT_] gmail.com | |
# | |
# This is a very simple script which allows you to crawl | |
# kickstarter projects and trigger some alerts. I find | |
# this useful to be alerted of new projects based on the | |
# keywords fed to the script. | |
############################################################## | |
$CACHE_FILE = "/tmp/kickstarter_db"; | |
$PAGES_TO_CRAWL = 5; | |
$EMAIL = "[email protected]"; | |
if ( sizeof( $argv ) < 2 ) die( "You need to specify at least one keyword\n" ); | |
array_shift( $argv ); | |
print "Looking for new projects using the following keywords: " . trim( implode( ", ", $argv) ) . "\n"; | |
$dataset = ( is_file( $CACHE_FILE ) ? unserialize( file_get_contents( $CACHE_FILE ) ) : Array() ); | |
$curPage = loadpage( 1 ); | |
preg_match_all( '/<li class="project grid_4">(.*?)<\/li>/ims', $curPage, $matches ); | |
foreach ( $matches[1] as $match ) | |
{ | |
$tmp = getDetails( $match ); | |
if ( $tmp && !checkArray( $dataset, $tmp[4] ) ) | |
{ | |
$dataset[] = $tmp; | |
foreach( $argv as $keyword ) | |
{ | |
if ( stripos( $tmp[0], trim($keyword) ) !== false || stripos( $tmp[2], trim($keyword) ) !== false) | |
{ | |
print "Matching project was found -> $tmp[2]: https://kickstarter.com$tmp[1]\n"; | |
mail( $EMAIL, "New project found: '$tmp[2]'", "Hello!\nIt seems that there is a new project matching your keywords. For more details go to https://kickstarter.com$tmp[1]", "From: $EMAIL"); | |
} | |
} | |
} | |
} | |
file_put_contents( $CACHE_FILE, serialize( $dataset ) ); | |
function getDetails( $match ) | |
{ | |
preg_match( '/bbcard_blurb">(.*?)<\/p>/ims', $match, $description); | |
preg_match( '/<strong>.*?<a href="(.*?)".*?>(.*?)<\/a>.*?<\/strong>/ims', $match, $linkdesc); | |
preg_match( '/<div class="project-thumbnail">.*?img.*?src="(.*?)"/ims', $match, $image ); | |
if ( $description[1] == null || $linkdesc[1] == null || $linkdesc[2] == null) return null; | |
return ( Array( trim( $description[1] ), | |
trim( $linkdesc[1] ), | |
trim( $linkdesc[2] ), | |
trim( $image[1] ), | |
md5( trim( $description[1] ) . trim( $linkdesc[1] ) . trim( $linkdesc[2] ) . trim( $image[1] ) ), | |
mktime() ) ); | |
} | |
function checkArray( $mArray, $hash ) | |
{ | |
if ( sizeof( $mArray ) == 0 ) return false; | |
foreach( $mArray as $project ) | |
{ | |
if ( $project[4] == $hash ) return true; | |
} | |
return false; | |
} | |
function loadpage ( $page=1 ) | |
{ | |
return ( file_get_contents( "https://www.kickstarter.com/discover/advanced?page=$page&category_id=16&sort=launch_date&seed=" ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment