Пример #1
0
def main(opts):
    """
    Indefinitely cycles through the queries provided to the program,
    and extracts the new apartment information.

    """

    # The query URL now comes from the conf.py file. I rarely need to change it, and
    # didn't want to have to chase it down if it somehow left my bash history.
    query = conf.CRAIGS_URL

    queue = LookupQueue(opts.memory)

    while True:
        listings = craigslist.fetch_with_pages_back(query, pages=opts.pages)
        new_listings = [l for l in listings if queue.push(l)]

        # # If you just want to print out the relevant posts...
        # for listing in new_listings:
        #     print Template(opts.format).safe_substitute(listing)

        # Attempt to send an email containing the new posts
        if len(new_listings) > 0:
            msg = get_msg(new_listings, query)
            print msg
            try:
                send_email(conf.SENDER, conf.RECIPIENTS.split(';'), msg)
            except:
                print "Could not send email: ", sys.exc_info()[0]

        process_new(new_listings)
        time.sleep(opts.sleep)
Пример #2
0
def main(query, opts):
    """
    Indefinitely cycles through the queries provided to the program,
    and extracts the new apartment information.
    """
    queue = LookupQueue(opts.memory)
    while True:
        listings = craigslist.fetch_with_pages_back(query, pages=opts.pages)
        new_listings = [l for l in listings if queue.push(l['link'])]
        for listing in new_listings:
            print Template(opts.format).safe_substitute(listing)
        process_new(new_listings)
        time.sleep(opts.sleep)