A Simple Expiring Set in Python

17 Jan

Months ago, I coded a tiny crawler to monitor some electronics deals.

I extracted a list of my target products from the homepage, and on each product page tried to add it to my cart. Basically I need to:

  • Check each product page if it’s marked as available on home page;
  • The interval between two attempt for the same product page is at least 1 hour. That is, in the hour following the first check, we do nothing. After one hour, if it’s still marked as available, try it again. Otherwise, do nothing.
  • The number of unique product pages is small, like less than 100.

To achieve that, I made a simple expiring set in Python. It does not consider garbage collection, because

  • The same items are added from time to time;
  • The number of unique items is small.

One Reply to “A Simple Expiring Set in Python”

  1. It’s an interesting tips for the time constraint problem. Nice to make it a Class.

    Thanks for sharing.

    Daniel

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!