Пример #1
0
 def job_forget(self, persist=False):
     # 清除记忆
     if persist is True:
         #save memory before forget them
         pass
     self.memory.clear()
     oplogs("memory erased")
Пример #2
0
    def __init_jobs(self):
        self.sched = BackgroundScheduler()

        # 添加任务作业

        # 每天清理一次缓存
        #self.sched.add_job(self.job_clean_cache, trigger='cron', day_of_week='*',hour=1, minute=0, second=0)

        # 提供给group的5分钟检测
        self.sched.add_job(self.job_stock_monitor,
                           trigger='cron',
                           id='job_stock_monitor',
                           minute="*/5",
                           next_run_time=None)

        # 交易日9:30:15生成开盘报告
        self.sched.add_job(self.job_open_scan,
                           trigger='cron',
                           day_of_week='0-4',
                           hour=9,
                           minute=30,
                           second=15)

        # 交易日15:05生成收盘报告
        self.sched.add_job(self.job_close_scan,
                           trigger='cron',
                           day_of_week='0-4',
                           hour=15,
                           minute=5,
                           second=0)

        # 启动调度器
        self.sched.start()

        oplogs("schedulers started")
Пример #3
0
 def __init__(self, debug=False, stopcb=None):
     oplogs("Harry Botter is rebooting")
     self.__init_robot(debug)
     self.stopcb = stopcb
     self.__load_mods()
     #self.__init_db()
     #self.__init_jobs()
     oplogs("Harry Botter is online")
Пример #4
0
    def __init_db(self):
        # 创建数据库数据库用于永久记忆
        self.conn = sqlite3.connect('messages.db')
        self.cursor = self.conn.cursor()
        self.cursor.execute(
            'create table if not exists msgqueue (id integer primary key autoincrement, date TEXT, group TEXT, user TEXT, msg TEXT)'
        )
        self.cursor.execute(
            'create table if not exists monitorstocks (id integer primary key autoincrement, group TEXT, code TEXT)'
        )
        self.cursor.commit()

        oplogs("[%s]messages.db connected")
Пример #5
0
 def job_stock_monitor(self, valve=2.0):
     oplogs("job_stock_monitor triggerred")
     group_alarms = self.stockmod.get_alarms(valve)
     for (group, alarms) in group_alarms.items():
         notice = ""
         for alarm in alarms:
             # alarm = [stockname,price,change,highlow,closeopen]
             alarm_content = "[%s %.2f%%]5分钟涨跌幅:%.2f%%, 波动:%.2f%%\n" % (
                 alarm[0], alarm[2], alarm[4], alarm[3])
             notice += alarm_content
         if len(notice) > 0:
             print(notice)
             self.mouth(group, notice)
             time.sleep(1)
Пример #6
0
    def save_to_db(self):
        oplogs("save_to_db called")
        # 保存消息
        for msg in self.memory:
            sql = "INSERT INTO msgqueue VALUES (%s,%s,%s,%s)" % (
                msg[0], msg[1], msg[2], msg[3])
            self.cursor.execute(sql)

        # 保存监控列表
        for (key, value) in self.stockmod.monitor_queue.items():
            for code in value:
                # date TEXT, group TEXT, code TEXT
                # date = time.strftime("%Y-%m-%d %H:%M:%S")
                sql = "INSERT INTO monitorstocks VALUES (%s,%s)" % (key, code)
                self.cursor.execute(sql)

        self.conn.commit()
Пример #7
0
    def action_user(self, cmd, group, user):
        cmds = cmd.lower().split()

        #"命令格式:
        # [添加监控]harry 股票名
        # [删除监控]harry del 股票名
        # [显示群推荐]harry 本群推荐
        # [显示群数据统计]harry stat
        # [显示报告]harry report"]
        # user 用户命令
        if len(cmds) == 1:
            return random.choice(auto_replys)

        if '本群推荐' in cmds[1]:
            oplogs("action_user:本群推荐 [%s]" % cmd)
            return self.stockmod.get_group_stock_price(group)
        elif 'stat' in cmds[1]:
            stat = "共有群消息 条\n"
            stat = stat + ""
            return "建设中"
        elif 'report' in cmds[1]:
            return "建设中"
        elif 'help' in cmds[1]:
            oplogs("action_user:help called")
            return 'harry [股票名|本群推荐|stat*|report*|help|ver]'
        elif 'ver' in cmds[1]:
            return HR__VERSION
        else:
            oplogs("action_user:harry [stock] called %s" % cmd)
            if self.stockmod.isvalid_stock(cmds[1]):
                self.add_stock(group, cmds[1])
                return self.show_stock(cmds[1])

        return ""
Пример #8
0
 def unsubscribe(self):
     self.mouth = None
     oplogs('Robot muted.')
Пример #9
0
 def subscribe(self, msgSend):
     self.mouth = msgSend
     oplogs('Robot unmuted.')
Пример #10
0
 def __del__(self):
     oplogs("Harry Botter is shutting down~~~")
     self.stop_jobs()
Пример #11
0
 def job_close_scan(self):
     oplogs("job_close_scan triggerred")
     self.sched.pause_job(job_id="job_stock_monitor")
Пример #12
0
 def job_open_scan(self):
     oplogs("job_open_scan triggerred")
     self.job_stock_monitor(valve=5.0)
     self.sched.resume_job(job_id="job_stock_monitor")
Пример #13
0
 def stop_jobs(self):
     if self.sched == None:
         self.sched.shutdown()
     oplogs("schedulers stopped")