05.19.08
Posted in programming at 23:51 by dalore
A little code tidbit, how to loop through dates a day at a time, can easily be modifed for other time periods but this is all I needed:
#!/usr/bin/perl -w
use Date::Calc qw(Add_Delta_Days Delta_Days);
my @date = (2008, 1, 1);
my @enddate = (2009, 1, 1);
while (Delta_Days(@date, @enddate) >= 0)
{
print "$date[0]-$date[1]-$date[2]\n";
#... do stuff
# move to next day
@date = Add_Delta_Days(@date, 1);
}
Permalink
05.12.08
Posted in Shopping, programming at 23:01 by dalore
I just wrote my first python program. It checks a given ASIN to see if amazon has it in stock.
#!/usr/bin/python
import sys
import urllib
AWSAccessKeyId = "removed"
AmazonMerchantId = "A3P5ROKL5A1OLE"
def checkStock(asin):
try:
fh = urllib.urlopen("http://ecs.amazonaws.co.uk/onca/xml?Service=AWSECommerceService&AWSAccessKeyId="+AWSAccessKeyId+"&Operation=ItemLookup&ItemId="+asin+"&ResponseGroup=OfferFull&Version=2008-04-07")
except:
print "fail"
return -1
page = fh.read()
fh.close()
found = page.find(AmazonMerchantId)
return found != -1
try:
asin = sys.argv[1]
except:
print "Usage: " + sys.argv[0] + " asin"
else:
if checkStock(asin):
print "in stock"
else:
print "not in stock"
You of course need to sign up to amazon webservices and insert your own AWS access key.
Sample output:
# Mario Kart (Wii)
./stockcheck.py B000XJNTNS
not in stock
# Nintendo Wii Console
./stockcheck.py B0007UATDG
in stock
Permalink