Ejemplo n.º 1
0
    # update doc in db
    db = mongodb_client.getDB()
    db[PROPERTY_TABLE_NAME].replace_one({'zpid': zpid},
                                        property_detail,
                                        upsert=True)
    print property_detail

    if FETCH_SIMILAR_PROPERTIES:
        # get its similar propertie's zpid
        similar_zpids = zillow_web_scraper_client.get_similar_homes_for_sale_by_id(
            zpid)

        # generate taslks for similar zpids
        for zpid in similar_zpids:
            old = db[PROPERTY_TABLE_NAME].find_one({'zpid': zpid})
            # Don't send task if the record is recent
            if (old is not None and 'last_update' in old and
                    time.time() - old['last_update'] < SECONDS_IN_ONE_WEEK):
                continue
            cloudAMQP_client.sendDataFetcherTask({'zpid': zpid})


# Main thread
while True:
    # fetch a message
    if cloudAMQP_client is not None:
        msg = cloudAMQP_client.getDataFetcherTask()
        if msg is not None:
            handle_message(msg)
        time.sleep(WAITING_TIME)
Ejemplo n.º 2
0
from cloudAMQP_client import CloudAMQPClient

CLOUDAMQP_URL = 'amqp://*****:*****@caterpillar.rmq.cloudamqp.com/dmsrypxa'
QUEUE_NAME = 'dataFetcherTaskQueue'

# Initialize a client
client = CloudAMQPClient(CLOUDAMQP_URL, QUEUE_NAME)

# Send a message
#client.sendDataFetcherTask({'name' : 'test message'})

# Receive a message
client.getDataFetcherTask()