def getHouseInfo(): locationMapping = LocationMapping() locationMappingToInt = LocationMappingToInt() crawler = Crawler(locationMapping, locationMappingToInt) houseInfoParser = HouseInfoParser() dao = DAO() # Crawl lianjia ershoufang lianjiaSiteName = 'http://sh.lianjia.com' lianjiaErShouFang = 'ershoufang' for k, v in locationMapping.getLocationMapping().iteritems(): for i in xrange(100): crawUrl = lianjiaSiteName + '/' + lianjiaErShouFang + '/' + k + '/d' + repr( i + 1) location, locationToInt, houseInfo = crawler.craw(crawUrl) if len(houseInfo): neighborhood, houseBedrooms, houseSize, houseFloor, houseBuiltDate, housePrice, houseAvgPrice = houseInfoParser.parseHttpResponse( houseInfo) if not len(neighborhood): break # Inser the data into database for i in xrange(len(neighborhood)): communityCode = queryCommunityCode(dao, neighborhood[i]) houseBedroomsInt = extractDigitFromString(houseBedrooms[i]) houseSizeInt = normalizeHouseSize(houseSize[i]) houseFloorInt = normalizeHouseFloor(houseFloor[i]) houseBuiltDateInt = normalizeHouseBuiltDate(houseBuiltDate[i]) housePriceInt = normalizeHousePrice(housePrice[i]) houseAvgPriceInt = normalizeHouseAvgPrice(houseAvgPrice[i]) insertSQL = "INSERT INTO house_price(location, location_int, community_name, community_code, house_bedrooms, house_bedrooms_int, house_size, house_size_int, house_floor, house_floor_int, house_built_date, house_built_date_int, house_price, house_price_int, house_avg_price, house_avg_price_int) VALUES ('%s', %d, '%s', %d, '%s', %d, '%s', %d, '%s', %d, '%s', %d, '%s', %d, '%s', %d)" % ( location, locationToInt, neighborhood[i], communityCode, houseBedrooms[i], houseBedroomsInt, houseSize[i], houseSizeInt, houseFloor[i], houseFloorInt, houseBuiltDate[i], houseBuiltDateInt, housePrice[i], housePriceInt, houseAvgPrice[i], houseAvgPriceInt) dao.insert(insertSQL) print 'Running...' dao.close()
def main(): st = SensorTag("B0:B4:48:C9:99:06") if not st.connected: print("Could not connect to sensortag") return #Wait for initial data gathering to be done time.sleep(1) db = DAO("sensor_data.sqlite") jb = JSONBuilder(db) data = None while (True): db.open(True) data = st.read(uuid_constants.IRTEMP_DATA_UUID) obj_temp = convert.irtemp(data[0:len(data) // 2]) amb_temp = convert.irtemp(data[len(data) // 2:]) db.store_irtemp(data, obj_temp, amb_temp) print("--------------------IR Temperature Sensor------------------") print("IR Object Temp = " + str(round(obj_temp, 2)) + " C, IR Ambient Temp = " + str(round(amb_temp, 2)) + " C") data = st.read(uuid_constants.HUMID_DATA_UUID) humid_temp = convert.humid_temp(data[0:len(data) // 2]) humidity = convert.humid(data[len(data) // 2:]) db.store_humid(data, humid_temp, humidity) print("-----------------------Humidity Sensor---------------------") print("Temperature = " + str(round(humid_temp, 2)) + " C, Humidity = " + str(round(humidity, 2)) + " %RH") data = st.read(uuid_constants.BARO_DATA_UUID) baro_temp = convert.baro(data[0:len(data) // 2]) baro_pres = convert.baro(data[len(data) // 2:]) db.store_baro(data, baro_temp, baro_pres) print("--------------------------Barometer------------------------") print("Temperature = " + str(round(baro_temp, 2)) + " C, Barometric Pressure = " + str(round(baro_pres, 2)) + " hPa/millibars") data = st.read(uuid_constants.OPTI_DATA_UUID) lux = convert.opti(data) db.store_opti(data, lux) print("-----------------------Optical Sensor----------------------") print("Light = " + str(round(lux, 2)) + " Lux") db.close() db.open(False) jb.buildFile("current") jb.buildFile("history") db.close() cron_jobs.reset_alarms() time.sleep(READING_DELAY) db.close()
def getCommunityInfo(): locationMapping = LocationMapping() locationMappingToInt = LocationMappingToInt() crawler = Crawler(locationMapping, locationMappingToInt) houseInfoParser = HouseInfoParser() dao = DAO() lianjiaSiteName = 'http://sh.lianjia.com' lianjiaXiaoqu = 'xiaoqu' count = 0 # 100 pages for i in xrange(100): crawUrl = lianjiaSiteName + '/' + lianjiaXiaoqu + '/d' + repr(i + 1) + 'rs' communityResp = crawler.crawCommunity(crawUrl) if len(communityResp): communityInfo = houseInfoParser.parseCommunityHttpResponse( communityResp) if not len(communityInfo): break for i in xrange(len(communityInfo)): # If it already exists querySQL = "SELECT * FROM community where community_name='%s'" % communityInfo[ i].strip() if dao.queryForExistence(querySQL): continue count = count + 1 insertSQL = "INSERT INTO community(community_name, community_code) VALUES ('%s', %d)" % ( communityInfo[i].strip(), count) dao.insert(insertSQL) dao.close()