예제 #1
0
def addStationsInLocationToDb(lat, lng, rad):
    logger = logging.getLogger('miner')
    logger.info("Requesting station list for lat: " + "{:.9f}".format(lat) + "long: " + "{:.9f}".format(lng) +  " and rad: " + "{:.9f}".format(rad))
    #Get Station data
    stationList = apiRequests.listRequest(lat, lng, rad)["stations"]
    dbHandle = connectDb.connect()
    if dbHandle is None:
        logger.critical("Cannot connect to db, exiting")
        sys.exit("Cannot connect to db.")
    for station in stationList:
        #Format for Database
        logger.info("Preparing data of " + station["name"] + " for insertion")
        station["_id"] = station["id"]
        del station["id"]
        del station["dist"]
        del station["price"]
        logger.info("Inserting station data of " + station["name"] + " to db")
        try:
            #If data for this station already exists replace, else insert
            dbHandle.stations.replace_one({"_id" : station["_id"]},  station, upsert=True)
            logger.info("Station " + station["name"] + " added")
        except Exception as exc:
            logger = logging.getLogger('database')
            logger.exception("Exception while inserting station data in db.")
            raise SystemExit
예제 #2
0
def addStationsInLocationToDb(lat, lng, rad):
    logger = logging.getLogger('miner')
    logger.info("Requesting station list for lat: " + "{:.9f}".format(lat) +
                "long: " + "{:.9f}".format(lng) + " and rad: " +
                "{:.9f}".format(rad))
    #Get Station data
    stationList = apiRequests.listRequest(lat, lng, rad)["stations"]
    dbHandle = connectDb.connect()
    if dbHandle is None:
        logger.critical("Cannot connect to db, exiting")
        sys.exit("Cannot connect to db.")
    for station in stationList:
        #Format for Database
        logger.info("Preparing data of " + station["name"] + " for insertion")
        station["_id"] = station["id"]
        del station["id"]
        del station["dist"]
        del station["price"]
        logger.info("Inserting station data of " + station["name"] + " to db")
        try:
            #If data for this station already exists replace, else insert
            dbHandle.stations.replace_one({"_id": station["_id"]},
                                          station,
                                          upsert=True)
            logger.info("Station " + station["name"] + " added")
        except Exception as exc:
            logger = logging.getLogger('database')
            logger.exception("Exception while inserting station data in db.")
            raise SystemExit
예제 #3
0
# Modul: testConnectDb
# Date: 13.07.2015
# Author: dtonal - Torben Mueller <*****@*****.**>
# Summary: Modul to do first request testing.
import connectDb
import utils

utils.loggingMode = 1

try:
    utils.logMessage("Testing DB Connection")
    dbHandle = connectDb.connect()
    if dbHandle is None:
        utils.logMessage("Connect DB - returned handle is null")
    else:
        utils.logMessage("Connect DB - getting handle successfully")
except Exception as exc:
    utils.logMessage("Exception while testing connectDb: %s " % exc)
    raise SystemExit
예제 #4
0
        del station["price"]
        logger.info("Inserting station data of " + station["name"] + " to db")
        try:
            #If data for this station already exists replace, else insert
            dbHandle.stations.replace_one({"_id" : station["_id"]},  station, upsert=True)
            logger.info("Station " + station["name"] + " added")
        except Exception as exc:
            logger = logging.getLogger('database')
            logger.exception("Exception while inserting station data in db.")
            raise SystemExit

if __name__ == "__main__":
    logger = logging.getLogger('miner')
    logger.info("Start mining")
    logger.info("Establishing DB connection")
    dbHandle = connectDb.connect()
    if dbHandle is None:
        logger.critical("Cannot connect to db, exiting")
        sys.exit("Cannot connect to db.")
    logger.info("Connect DB - getting handle successfully")
    try:
        #Getting a list of all stations in in the db
        stations= dbHandle.stations.find()
        for i in stations:
            #iterate trough all stations and do a detailRequest
            logger.info("Getting details for stationId = " + i["_id"])
            detailRequestResult = apiRequests.detailRequest(i["_id"])
            if detailRequestResult is not None:
                #build and add generally data to filtered result dict
                filteredResult = dict()
                filteredResult["dateTime"] = datetime.datetime.now()