Created
March 30, 2014 04:42
-
-
Save AgustinPelaez/9867656 to your computer and use it in GitHub Desktop.
Get product list for a specific search query in MercadoLibre.com, post the number of new items to the Ubidots Cloud
This file contains hidden or 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
#!/usr/bin/python | |
""" | |
Get product list for a specific search query in MercadoLibre.com, post the number of new items to the Ubidots Cloud | |
""" | |
__author__ = "Agustin Pelaez" | |
from sys import argv | |
import ubidots | |
import requests | |
import time | |
if __name__ == "__main__": | |
if len(argv) < 2: | |
print "Usage: %s API_KEY" % argv[0] | |
sys.exit(0) | |
api = ubidots.ApiClient(argv[1]) | |
new_cars_var = api.get_variable('53374b0b7625420ef842250b') | |
old_cars = 0 | |
while(1): | |
# Get product list webpage from MercadoLibre | |
query = requests.get('http://vehiculos.mercadolibre.com.co/gol-comfortline_PciaId_Antioquia_YearRange_2010-2012') | |
str_query = query.text | |
i = 0 | |
urls = [] | |
# Look for the URLs that link to each individual product | |
while True: | |
i = str_query.find('http://carro.mercadolibre.com.co',i) | |
if i == -1: | |
break | |
url = str_query[i:str_query.find('\"',i)] | |
try: | |
urls.index(url) | |
except: | |
urls.append(url) | |
i += 1 | |
cars = len(urls) | |
new_cars = cars - old_cars | |
print "New cars: "+ str(new_cars) | |
# Save the value to Ubidots | |
new_cars_var.save_value({'value':new_cars}) | |
old_cars = cars | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment