Esempio n. 1
0
def main(location):
	
    global pgConn
    log("Connecting to database")
    pgConn = dbObj.pgConnection()

    log("Getting new cities from database")
    select_query = pgConn.createSelectQuery(location)
    records = pgConn.performSelect(select_query)
    log("Fetched", len(records), location, "records")

    for record in records:
        try:
            log("Processing", record[GID], record[CITY_NAME])

            if record[GID] is None:	
                log("Null GID, skipping")
                continue
            
            process_city(record[GID], record[CITY_NAME], record[CV_HULL], record[XMIN:], location)

        except AssertionError as e:
            log(e)
        except Exception as e:
            log("Proccsing", record[CITY_NAME], "with error", str(e))

    del pgConn
    return len(records)
Esempio n. 2
0
def init():
    global pgConn
    servname = socket.gethostname()

    greencitieslog.start()
    
    log("Starting Green Cities on", servname)
    log("Connecting to database")
    pgConn = dbObj.pgConnection()
Esempio n. 3
0
 def run(self):
     while True:
         db = dbObj.pgConnection()
         for site in taskmanager._sites:
             site_name =  taskmanager._sites[site]
             db.get_and_update_CGIValues(site_name)
         db.get_and_update_CGIValues('total')
         del db
         time.sleep(300)
Esempio n. 4
0
def test_updateDaemon():
    update_daemon = UpdateDaemon('/tmp/daemon-update.pid', stdout='/tmp/update_daemon.log', stderr='/tmp/update_daemon.err')
    db = dbObj.pgConnection()
    firstValue = db.get_last_cgi_query()
    update_daemon.start()
    time.sleep(600)
    update_daemon.stop()
    secondValue = db.get_last_cgi_query()
    time.sleep(600)
    thirdValue = db.get_last_cgi_query()
    assert secondValue > firstValue, "second value %d should be > first value %d" % (secondValue, firstValue)
    assert secondValue == thirdValue, "second value %d should be = third value %d" % (secondValue, thirdValue)
Esempio n. 5
0
##             if site == "cs.UVic.CA": continue
##             site_data = sites[site]
##             values = site_data[key]
##             for i in range(0, len(values)):
##                 this_total[i] += values[i]
##         total[key] = this_total

sys.stderr = sys.stdout


form = cgi.FieldStorage()
requested_site = form.getfirst("site", "total")


## if requested_site in sites:
##     return_data = sites[requested_site]
##     return_data['site_name'] = requested_site
## else:
##     sum_dict()
##     return_data = total
##     return_data['site_name'] = 'total'

db = dbObj.pgConnection()
return_data = db.getCGIValues(requested_site)

json_return = json.JSONEncoder().encode(return_data)
print "Content-Type: text/html"
print
print json_return