Пример #1
0
            bags.add( Bag(div_str) )
        except:
            print '[ERROR][create bag obj]', sys.exc_info()

    return bags


if __name__ == '__main__':
    last_bags = BagSet()
    new_bags = BagSet()
    fout = open("nm_sale_handbags.dat", "a")
    while True:
        cur_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
        cur_bags = parse_a_page(URL_NM_SALE_BAG)
        for b in cur_bags.bags:
            if not last_bags.exist(b):
                new_bags.add(b)

        if len(new_bags.bags) > 0:
            print cur_time, 'Send email!'
            # Set up the email here
            send_email( str(new_bags) )
            print >> fout, new_bags
        else:
            print cur_time, 'No new bag!'

        # Sleep for a while
        sleep_sec = random.randint(int(DURATION*4/5), DURATION)
        # sleep_sec = DURATION
        time.sleep(sleep_sec)