Пример #1
0
def pm25Monitor():
    try:
        msg = ''
        msg = msg + weather.fetchPm25Forcast()
        if msg:
            log.info('* pm25Monitor MESSAGE * ' + msg)
            sendMessage('PM2.5', msg, 2)
    except:
        log.exception('pm25Monitor Exception Occured!')
Пример #2
0
def pm25Monitor():
	try:
		msg = ''
		msg = msg + weather.fetchPm25Forcast()
		if msg:
			log.info('* pm25Monitor MESSAGE * ' + msg)
			sendMessage('PM2.5', msg, 2)
	except:
		log.exception('pm25Monitor Exception Occured!')
Пример #3
0
def sendMultiMessage(mtype, multimsg):
    try:
        for msgs in multimsg:
            mail.send(mtype, msgs[0])
    except:
        log.exception('Email Exception Occured!')

    try:
        fetion.sendMultiSms(multimsg)
    except:
        log.exception('Fetion Exception Occured!')
Пример #4
0
def marketMonitor():
    # Investments
    try:
        msg = ''
        msg = msg + prices.latestPrices()
        # sending message if available
        if msg:
            log.info('* marketMonitor MESSAGE * ' + msg)
            sendMessage('Market', msg, 1)
    except:
        log.exception('marketMonitor Exception Occured!')
Пример #5
0
def minuteMonitor():
    # Investments
    try:
        msg = ''
        msg = msg + prices.monitorPrice()
        # sending message if available
        if msg:
            log.info('* minuteMonitor MESSAGE * ' + msg)
            sendMessage('Prices', msg, 1)
    except:
        log.exception('minuteMonitor Exception Occured!')
Пример #6
0
def sendMultiMessage(mtype, multimsg):
	try:
		#for msgs in multimsg:
		#	mail.send(mtype, msgs[0])
		pass
	except:
		log.exception('Email Exception Occured!')
		
	try:
		fetion.sendMultiSms(multimsg)
		pass
	except:
		log.exception('Fetion Exception Occured!')
Пример #7
0
def weatherMonitor():
    try:
        #msg = ''
        #msg = msg + weather.fetchWeather()
        multimsg = [0, 0]
        multimsg[0] = [0, 0]
        multimsg[0][0] = weather.fetchWeather('101010200')
        multimsg[0][1] = const.WEATHER_BJ_MOBILES
        multimsg[1] = [0, 0]
        multimsg[1][0] = weather.fetchWeather('101180101')
        multimsg[1][1] = const.WEATHER_ZZ_MOBILES

        sendMultiMessage('Weather', multimsg)

    except:
        log.exception('weatherMonitor Exception Occured!')
Пример #8
0
def weatherMonitor():
	try:
		#msg = ''
		#msg = msg + weather.fetchWeather()
		multimsg = [0, 0]
		multimsg[0] = [0, 0]
		multimsg[0][0] = weather.fetchWeather('101010200')
		multimsg[0][1] = const.WEATHER_BJ_MOBILES
		multimsg[1] = [0, 0]
		multimsg[1][0] = weather.fetchWeather('101180101')
		multimsg[1][1] = const.WEATHER_ZZ_MOBILES
		
		sendMultiMessage('Weather', multimsg)
		
	except:
		log.exception('weatherMonitor Exception Occured!')
Пример #9
0
def fetchZZpm25():
    try:
        dt = datetime.datetime.now().strftime('%Y-%m-%d')
        dhour = datetime.datetime.now().hour
        dhour = dhour - 1

        url = 'http://www.zzemc.cn/em_aw/Services/DataCenter.aspx?type=getPointHourData&code=2&time='
        url = url + dt + '%20' + str(dhour) + ':00:00'
        #log.debug(url)
        resp = urllib2.urlopen(url, timeout=20)
        ac = json.loads(resp.read())
        ac = ac['Head'][0]
        pm25 = int(float(ac['PM25']) * 1000)

        return u'空气指数: ' + str(pm25) + '\n'
    except:
        log.exception('fetchZZpm25 Exception Occured!')
        return ''
Пример #10
0
def fetchZZpm25():
	try:
		dt = datetime.datetime.now().strftime('%Y-%m-%d')
		dhour = datetime.datetime.now().hour
		dhour = dhour - 1
		
		url = 'http://www.zzemc.cn/em_aw/Services/DataCenter.aspx?type=getPointHourData&code=2&time='
		url = url + dt + '%20' + str(dhour) + ':00:00'
		#log.debug(url)
		resp = urllib2.urlopen(url, timeout=20)
		ac = json.loads(resp.read())
		ac = ac['Head'][0]
		pm25 = int(float(ac['PM25']) * 1000)
		
		return u'空气指数: ' + str(pm25) + '\n'
	except:
		log.exception('fetchZZpm25 Exception Occured!')
		return ''
Пример #11
0
def sendMultiSms(multimsg):
	try:
		phone = PyFetion.PyFetion(const.FETION_USER, const.FETION_PASSWORD, 'TCP', debug=True)
		if phone.login(PyFetion.FetionOnline):
			log.info('Fetion login success!')
			for msgs in multimsg:
				msg = msgs[0]
				for receiver in msgs[1]:
					phone.send_sms(msg.encode('utf-8'), receiver, True)
					log.info('SMS sent! receiver ' + receiver + 'Sending ' + msg + '')
			phone.logout()
			return True
		else:
			log.info('Fetion login failed, message not send! receivers: ' + receivers + ', msg: ' + msg)
			return False
			
	except:
		log.exception('SMS sent failed!')
		return False
Пример #12
0
def fetchBJpm25():
	try:
		resp = urllib2.urlopen('http://zx.bjmemc.com.cn/ashx/Data.ashx?Action=GetAQIClose1h', timeout=20)
		if resp.info().get('Content-Encoding') == 'gzip':
			buf = StringIO.StringIO(resp.read())
			f = gzip.GzipFile(fileobj=buf)
			retjson = f.read()
		else:
			retjson = resp.read()
		pm25s = json.loads(retjson)
		
		wlpm25 = ''
		for pm25 in pm25s:
			if (pm25['StationName'] == u'万柳'): wlpm25 = pm25
		if not wlpm25:
			wlpm25 = pm25s[0]
		
		return u'空气指数:' + wlpm25['AQIValue'] + ',' + wlpm25['Quality'] + '\n'
	except:
		log.exception('fetchBJpm25 Exception Occured!')
		return ''
Пример #13
0
def monitorPrice():
    msg = ''
    #Agg
    try:
        #aggPrice = icbcAgg()
        aggPrice = sinaAgg()
        msg = msg + tally('AGG', aggPrice)
    except:
        log.exception('AGG Exception Occured!')

    #Agg
    try:
        agtdPrice = sinaAgTD()
        msg = msg + tally('AGTD', agtdPrice)
        #pass
    except:
        log.exception('AGTD Exception Occured!')

    #shdx
    try:
        shdx = sinaSHDX()
        msg = msg + tally('SHDX', shdx)
        #pass
    except:
        log.exception('SHDX Exception Occured!')

    return msg
Пример #14
0
def monitorPrice():
	msg = ''
	#Agg 
	try:
		#aggPrice = icbcAgg()
		aggPrice = sinaAgg()
		msg = msg + tally('AGG', aggPrice)
	except:
		log.exception('AGG Exception Occured!')
	
	#Agg 
	try:
		agtdPrice = sinaAgTD()
		msg = msg + tally('AGTD', agtdPrice)
		#pass
	except:
		log.exception('AGTD Exception Occured!')
	
	#shdx 
	try:
		shdx = sinaSHDX()
		msg = msg + tally('SHDX', shdx)
		#pass
	except:
		log.exception('SHDX Exception Occured!')
	
	return msg
Пример #15
0
def fetchBJpm25():
    try:
        resp = urllib2.urlopen(
            'http://zx.bjmemc.com.cn/ashx/Data.ashx?Action=GetAQIClose1h',
            timeout=20)
        if resp.info().get('Content-Encoding') == 'gzip':
            buf = StringIO.StringIO(resp.read())
            f = gzip.GzipFile(fileobj=buf)
            retjson = f.read()
        else:
            retjson = resp.read()
        pm25s = json.loads(retjson)

        wlpm25 = ''
        for pm25 in pm25s:
            if (pm25['StationName'] == u'万柳'): wlpm25 = pm25
        if not wlpm25:
            wlpm25 = pm25s[0]

        return u'空气指数:' + wlpm25['AQIValue'] + ',' + wlpm25['Quality'] + '\n'
    except:
        log.exception('fetchBJpm25 Exception Occured!')
        return ''
Пример #16
0
def batchMonitor():
    try:
        db = SqliteDB()
        db.cleanOldData()
    except:
        log.exception('dayMonitor Exception Occured!')