当前位置: 首页>>代码示例>>Python>>正文


Python Action.send_message方法代码示例

本文整理汇总了Python中action.Action.send_message方法的典型用法代码示例。如果您正苦于以下问题:Python Action.send_message方法的具体用法?Python Action.send_message怎么用?Python Action.send_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在action.Action的用法示例。


在下文中一共展示了Action.send_message方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Cron

# 需要导入模块: from action import Action [as 别名]
# 或者: from action.Action import send_message [as 别名]
class Cron(object):

	def __init__(self, args):
		super(Cron, self).__init__()
		self.args = args
		self.query = Query(args);
		self.action = Action(args);

	def run(self):
		crons = self.query.list({}, 'AND', 'cron')
		output = []
		date = int(time.time())

		for action in crons:
			if( action['enable'] ):
				local = date - (action['tz_offset']*60*60)

				weekday = dt.utcfromtimestamp(local).weekday()
				hour = dt.utcfromtimestamp(local).hour
				minute = dt.utcfromtimestamp(local).minute

				dates = action['date'].split(',')

				for dte in dates:
					action_date = dt.utcfromtimestamp(int(dte) - (action['tz_offset']*60*60))
					cron_minute = action_date.minute
					cron_hour = action_date.hour

					if( action['repeat'] == 'hour' ):
						cron = {}

						# output.append({ str(action_date): (cron_minute < 30 and minute < 30) or (cron_minute > 29 and minute > 29) })

						if( (cron_minute < 30 and minute < 30) or (cron_minute > 29 and minute > 29) ):
							output.append(self.run_cron(action))
							cron['action'] = action

					if( action['repeat'] == 'day' ):
						cron = {}

						if( cron_hour == hour ):
							if( (cron_minute < 30 and minute < 30) or (cron_minute > 29 and minute > 29)  ):
								output.append(self.run_cron(action))
								cron['action'] = action

					if( action['repeat'] == 'week' ):
						cron = {}

						cron_weekday = action_date.weekday()

						if( weekday == cron_weekday and cron_hour == hour ):
							if( abs(cron_minute-minute) < 30 ):
								cron['message'] = self.action.send_message(action['bot_id'], action['chat_id'], action['text'], action['tz_offset'])
								cron['action'] = action

								output.append(cron)

		return output

	def run_cron(self, action):
		cron = {}
		if( len(action['cron']) > 0 and action['cron'] != 'null' ):
			# Cron contains photo or rss configuration
			cron_obj = json.loads(action['cron'])

			if 'photo' in cron_obj:
				cron['photo'] = self.action.send_photo(action['bot_id'], action['chat_id'], action['cron'], action['text'], action['tz_offset'])

				if( cron_obj['loop'] ):
					self.query.update({'cron': self.action.next_file(action['cron'], action['bot_id'])}, 'cron', action['id'])

			if 'rss' in cron_obj:
				rss_msg = self.complete_rss(cron_obj['resource'], cron_obj['rss'])
				if( len(rss_msg) > 0 ):
					cron['message'] = self.action.send_message(action['bot_id'], action['chat_id'], rss_msg, action['tz_offset'])
				else:
					cron['message'] = 'Failed to send rss'

			if 'weather' in cron_obj:
				weather = self.complete_weather(cron_obj['weather'])
				cron['weather'] = self.action.send_message(action['bot_id'], action['chat_id'], weather, action['tz_offset'])

		else:
			# Cron contains only text for message
			cron['message'] = self.action.send_message(action['bot_id'], action['chat_id'], action['text'], action['tz_offset'])

		return cron

	def complete_rss(self, resource, url):
		output = []

		if( resource == 'newsmaker.md' ):
			output.append('*{0}* - <DATE>'.format(resource))

			try:
				rss_url = urllib2.urlopen(url)
				data = rss_url.read()
				rss_url.close()

				rss = xmltodict.parse(data)
#.........这里部分代码省略.........
开发者ID:Ufrutov,项目名称:telebots,代码行数:103,代码来源:cron.py


注:本文中的action.Action.send_message方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。