Skip to content

Instantly share code, notes, and snippets.

@nloadholtes
Created November 26, 2012 19:43
Show Gist options
  • Save nloadholtes/4150184 to your computer and use it in GitHub Desktop.
Save nloadholtes/4150184 to your computer and use it in GitHub Desktop.
Playing around to figure out an API
#
# script for getting data from pic2shop.com
# Nick Loadholtes <nick@ironboundsoftware.com>
#
# Nov 26, 2012
#
import csv
import sys
import random
import time
import urllib2
def main(listing):
output = []
with open(listing, 'r') as csvfile:
rows = csv.DictReader(csvfile)
for row in rows:
output.append(row['ISBN13'])
return output
URL = """http://http://www.pic2shop.com/item/%s_0"""
PATH = """output/%s.html"""
def getListing(isbn):
url = URL % isbn
req = urllib2.Request(url)
try:
response = urllib2.urlopen(req)
data = response.read()
fullpath = PATH % isbn
f = open(fullpath, 'w')
f.write(data)
f.close()
except:
print("Failed to get %s" % url)
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Need a csv file to scan")
exit(-1)
print(len(sys.argv))
books = main(sys.argv[1])
for isbn in books:
getListing(isbn)
time.sleep(random.random() + 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment