コード例 #1
0
    def __init__(self):
        self.conf_reader = ConfigReader('./conf/db.ini')

        self.data_file = self.conf_reader.get_attr('file_name_raw')
        self.schema_raw = self.conf_reader.get_attr('transaction_db_raw')
        self.raw_table_name = 'transaction_log'
        self.raw_full_table_name = '.'.join(
            [self.schema_raw, self.raw_table_name])

        self.database = PostgreSQLCommon()
コード例 #2
0
def onStartupComplete(bot):
    # 启动完成时被调用
    # bot : QQBot 对象,提供 List/SendTo/GroupXXX/Stop/Restart 等接口,详见文档第五节
    global weibo_monitor

    global_config.MEMBER_WEIBO_GROUPS = ConfigReader.get_property(
        'qq_conf', 'member_weibo_groups').split(';')
    weibo_monitor = WeiboMonitor()
    weibo_monitor.login('15018433261', 'boa-85880907-BOA')
    name = ConfigReader.get_property('root', 'member_name')
    uid = ConfigReader.get_property('weibo', name)
    # uid = 1134206783
    weibo_monitor.getWBQueue(uid)
コード例 #3
0
def update_weibo_conf(bot):
    global weibo_monitor

    DEBUG('读取微博配置')
    global_config.MEMBER_WEIBO_GROUPS = ConfigReader.get_property(
        'qq_conf', 'member_weibo_groups').split(';')

    member_name = ConfigReader.get_property('root', 'member_name')
    if global_config.MEMBER_NAME == '' or global_config.MEMBER_NAME != member_name:
        DEBUG('微博监控变更')
        global_config.MEMBER_NAME = member_name
        uid = ConfigReader.get_property('weibo', member_name)
        if uid != '':
            weibo_monitor.getWBQueue(uid)
        else:
            INFO('没有微博UID')
コード例 #4
0
    def __init__(self):
        # Unique table name for the parallel processing
        self.conf_reader = ConfigReader('./conf/db.ini')

        self.storage_table = 'storage_' + str(int(time.time()))
        self.psa = PostgreSQLAdapter(
            storage_table=self.storage_table,
            schema_raw=self.conf_reader.get_attr('transaction_db_raw'),
            schema_target=self.conf_reader.get_attr('reconciliation_db'),
            schema_db_clean=self.conf_reader.get_attr('transaction_db_clean'))

        self.csv = CsvAdapter(
            storage_table=self.storage_table,
            schema_target=self.conf_reader.get_attr('reconciliation_db'),
            file_name_raw=self.conf_reader.get_attr('file_name_raw'),
            file_name_hash=self.conf_reader.get_attr('file_name_hash'))
コード例 #5
0
    def __init__(self,
                 config_reader: ConfigReader = ConfigReader(),
                 has_sleep_mode=True):
        """
        :param config_reader: use to init the voice controller with the right values
        :param has_sleep_mode: can be used to disable sleep_mode, not recommended
        """
        url = config_reader.Rasa["url"]
        headers = config_reader.Rasa["headers"]
        if url is None:
            self._rasa_intent = RasaIntent(headers)
        else:
            self._rasa_intent = RasaIntent(url=url, headers=headers)
        self.active = False
        self._stop = False
        self.active_time_delay = config_reader.Speech_to_text.getint(
            "active_time_delay")
        self.last_active_time = None
        self.noise_level = config_reader.Speech_to_text.getint("noise_level")
        self.confidence_threshold = config_reader.Speech_to_text.getfloat(
            "confidence_threshold")
        self.input_device_index = config_reader.Speech_to_text.getint(
            "input_device_index")
        self.has_sleep_mode = has_sleep_mode

        self._thread = threading.Thread(target=self.run, args=())
        self._thread.daemon = True  # Daemonize thread
コード例 #6
0
def get_room_msgs(bot):
    start_t = time.time()
    global pocket48_handler
    if pocket48_handler.is_login is False:
        DEBUG('登录失败,无法监控房间消息')
        return
    full_room_id_length = len(ConfigReader.get_all_member_room_id_list())
    if  0 < len(global_config.ACTIVE_MEMBER_ROOM_ID_LIST) < full_room_id_length:
        # 获取监控房间的room列表,循环获取房间消息
        for roomId in global_config.ACTIVE_MEMBER_ROOM_ID_LIST:
            r1 = pocket48_handler.get_member_room_msg(roomId[1])
            pocket48_handler.parse_room_msg(r1)
            # 开启房间评论
            # r2 = pocket48_handler.get_member_room_comment(global_config.ROOM_ID)
            # pocket48_handler.parse_room_comment(r2)
            # DEBUG('last_msg_time: %s', pocket48_handler.last_msg_time)
        end_t = time.time()
        DEBUG('获取房间消息 执行时间: %s', end_t-start_t)
    else:
        if len(global_config.ACTIVE_MEMBER_ROOM_ID_LIST) == full_room_id_length and len(pocket48_handler.member_room_msg_ids) >= pocket48_handler.init_room_msg_ids_length:
            for roomId in global_config.ACTIVE_MEMBER_ROOM_ID_LIST:
                r1 = pocket48_handler.get_member_room_msg(roomId[1])
                pocket48_handler.parse_room_msg(r1)
                # 开启房间评论
                # r2 = pocket48_handler.get_member_room_comment(global_config.ROOM_ID)
                # pocket48_handler.parse_room_comment(r2)
                # DEBUG('last_msg_time: %s', pocket48_handler.last_msg_time)
            end_t = time.time()
            DEBUG('获取房间消息 执行时间: %s', end_t-start_t)
        else:
            return
コード例 #7
0
def update_modian_conf(bot):
    global modian_handler
    INFO('读取摩点配置')
    ConfigReader.read_conf()
    modian_json = json.load(open("data/modian.json"))

    global_config.MODIAN_POSTSCRIPTS = modian_json['modian_postscripts']

    # 摩点集资PK链接数组初始化
    global_config.MODIAN_NEED_DISPLAY_PK = modian_json[
        'modian_need_display_pk']

    for modian_pk_j in modian_json['modian_pk_activities']:
        global_config.MODIAN_PK_ARRAY.append(modian_pk_j)

    # 需要适应同时开多个链接的情况
    global_config.MODIAN_ARRAY = []

    for modian_j in modian_json['monitor_activities']:
        if modian_j['modian_need_display_rank'] is False:
            modian = ModianEntity(modian_j['modian_link'],
                                  modian_j['modian_title'],
                                  modian_j['modian_pro_id'], False)
        elif modian_j['wds_need_display_rank'] is True:
            modian = ModianEntity(modian_j['modian_link'],
                                  modian_j['modian_title'],
                                  modian_j['modian_pro_id'], True)
        global_config.MODIAN_ARRAY.append(modian)

    modian_handler.modian_project_array = global_config.MODIAN_ARRAY

    modian_handler.init_order_queues()

    global_config.JIZI_NOTIFY_GROUPS = ConfigReader.get_property(
        'qq_conf', 'jizi_notify_groups').split(';')
    modian_groups = global_config.JIZI_NOTIFY_GROUPS
    modian_handler.modian_notify_groups = modian_groups

    DEBUG('JIZI_NOTIFY_GROUPS: %s, length: %d',
          ','.join(global_config.JIZI_NOTIFY_GROUPS),
          len(modian_handler.modian_notify_groups))
コード例 #8
0
def update_conf():
    """
    每隔1分钟读取配置文件
    :return:
    """
    my_logger.debug('读取配置文件:conf.ini')
    ConfigReader.read_conf()

    auto_reply_groups = global_config.AUTO_REPLY_GROUPS
    test_groups = global_config.TEST_GROUPS

    pocket48_handler.auto_reply_groups = auto_reply_groups
    pocket48_handler.test_groups = test_groups

    my_logger.debug('auto_reply_groups: %s, length: %d',
                    ','.join(global_config.AUTO_REPLY_GROUPS),
                    len(pocket48_handler.auto_reply_groups))

    for task in global_config.POCKET48_LISTEN_TASKS:
        pocket48_handler.listen_tasks.append(task)
        pocket48_handler.init_msg_queues(task)
コード例 #9
0
 def __init__(self,
              flower: Flower,
              config_reader: ConfigReader = ConfigReader()):
     self.flower = flower
     self.captor_data = CaptorData(config_reader=config_reader)
     self.target_temperature = config_reader.Plant.getfloat(
         "target_temperature", 17)
     self.target_humidity = config_reader.Plant.getfloat(
         "target_humidity", 20)
     self.temperature = 0
     self.humidity = 0
     self.refresh_data()
コード例 #10
0
def update_wds_conf(bot):
    global wds_handler

    DEBUG('读取微打赏配置')
    ConfigReader.read_conf()
    wds_json = json.load(open("data/wds.json"))

    global_config.WDS_POSTSCRIPTS = wds_json['wds_postscripts']

    # 微打赏集资PK链接数组初始化
    global_config.WDS_NEED_DISPLAY_PK = wds_json['wds_need_display_pk']

    for wds_pk_j in wds_json['wds_pk_activities']:
        wds = WDS(wds_pk_j['wds_pk_link'], wds_pk_j['wds_pk_title'], '', '', False)
        global_config.WDS_PK_ARRAY.append(wds)

    # 需要适应同时开多个链接的情况
    global_config.WDS_ARRAY = []

    for wds_j in wds_json['monitor_activities']:
        if wds_j['wds_need_display_rank'] is False:
            wds = WDS(wds_j['wds_link'], wds_j['wds_title'], wds_j['wds_moxi_id'], wds_j['wds_pro_id'],
                      False)
        elif wds_j['wds_need_display_rank'] is True:
            wds = WDS(wds_j['wds_link'], wds_j['wds_title'], wds_j['wds_moxi_id'], wds_j['wds_pro_id'],
                      True)
        global_config.WDS_ARRAY.append(wds)

    wds_handler.wds_array = global_config.WDS_ARRAY

    wds_handler.init_comment_queues()

    global_config.JIZI_NOTIFY_GROUPS = ConfigReader.get_property('qq_conf', 'jizi_notify_groups').split(';')
    wds_groups = QQHandler.list_group(global_config.JIZI_NOTIFY_GROUPS)
    wds_handler.wds_notify_groups = wds_groups

    DEBUG('JIZI_NOTIFY_GROUPS: %s, length: %d', ','.join(global_config.JIZI_NOTIFY_GROUPS),
          len(wds_handler.wds_notify_groups))
コード例 #11
0
ファイル: weibo_plugin.py プロジェクト: billjyc/pocket48
def update_weibo_conf():
    global weibo_monitor

    my_logger.debug('读取微博配置')
    global_config.MEMBER_WEIBO_GROUPS = ConfigReader.get_property(
        'qq_conf', 'member_weibo_groups').split(';')

    for task in global_config.POCKET48_LISTEN_TASKS:
        uid = task.member.weibo_uid
        my_logger.debug('weibo uid: %s', uid)
        if uid != 0:
            weibo_monitor.getWBQueue(task)
        else:
            my_logger.error('微博UID填写错误,请检查')
コード例 #12
0
class Reconciliator:
    """ Reconciliation executor """
    def __init__(self):
        # Unique table name for the parallel processing
        self.conf_reader = ConfigReader('./conf/db.ini')

        self.storage_table = 'storage_' + str(int(time.time()))
        self.psa = PostgreSQLAdapter(
            storage_table=self.storage_table,
            schema_raw=self.conf_reader.get_attr('transaction_db_raw'),
            schema_target=self.conf_reader.get_attr('reconciliation_db'),
            schema_db_clean=self.conf_reader.get_attr('transaction_db_clean'))

        self.csv = CsvAdapter(
            storage_table=self.storage_table,
            schema_target=self.conf_reader.get_attr('reconciliation_db'),
            file_name_raw=self.conf_reader.get_attr('file_name_raw'),
            file_name_hash=self.conf_reader.get_attr('file_name_hash'))

    def storage_preparing(self):
        """ Database preparing """
        self.psa.storage_create()

    def postgresql_adapter_run(self):
        """ Postgre side preparing """
        self.psa.adapter_run_main()

    @m.timing
    def csv_adapter_run(self):
        """ CSV side preparing """
        self.csv.run_reading()
        self.csv.bulk_copy_to_db()

    @m.timing
    def get_report(self):
        """ Return the detailed report """
        self.psa.get_discrepancy_report()

    def reconcillation_run(self):
        """ Comparison the data from two sources """
        self.psa.save_clean_data()
        self.psa.drop_storage()

    def start_all(self):
        """ Run all steps """
        self.storage_preparing()
        self.csv_adapter_run()
        self.postgresql_adapter_run()
        self.get_report()
        self.reconcillation_run()
コード例 #13
0
 def __init__(self,
              time_delta=24,
              config_reader: ConfigReader = ConfigReader()):
     """
     Initializes data recovery from the sensor.
     :param time_delta: How many days have the data been recovered
     """
     self.since = (
         datetime.datetime.now() -
         datetime.timedelta(hours=time_delta)).strftime("%d-%b-%Y %H:%M:%S")
     self.today = datetime.datetime.now().strftime("%d-%b-%Y %H:%M:%S")
     self.user_id = config_reader.Parrot["userid"]
     self.user_code = config_reader.Parrot["usercode"]
     self.password = config_reader.Parrot["passwd"]
     self.have_sensor = self.user_id is not None and self.user_code is not None and self.password is not None
     if self.have_sensor:
         self.connection = api_cloud.ApiCloud(self.user_id, self.user_code)
     else:
         print("off line sensor")
         self.connection = None
コード例 #14
0
    def __init__(self,
                 rank: int = 1,
                 planted_at=datetime.today(),
                 config_reader=ConfigReader()):
        self.__mood = Mood.STANDING  # based on the last time the plant was looked after
        self.rank = rank
        self.planted_at = planted_at
        self.updated_at = datetime.today()

        self.saved_moods = [Mood.STANDING]  # to save previous moods

        try:
            mood_time_sad = config_reader.Plant.getfloat("mood_time_sad")
        except TypeError:
            mood_time_sad = np.inf

        self.TIME_HAPPY = config_reader.Plant.getfloat("mood_time_happy")
        self.TIME_STANDING = config_reader.Plant.getfloat(
            "mood_time_standing") + self.TIME_HAPPY
        self.TIME_ANGRY = config_reader.Plant.getfloat(
            "mood_time_angry") + self.TIME_STANDING
        self.TIME_SAD = mood_time_sad + self.TIME_ANGRY
コード例 #15
0
def onStartupComplete(bot):
    # 启动完成时被调用
    # bot : QQBot 对象,提供 List/SendTo/GroupXXX/Stop/Restart 等接口,详见文档第五节
    DEBUG('%s.onStartupComplete', __name__)
    global pocket48_handler
    # 实例化PocketHandler
    pocket48_handler = Pocket48Handler([], [], [], [], [])
    # 获取票务
    global_config.TICKET_INFO = pocket48_handler.get_ticket_info()
    # 登录口袋48
    username = ConfigReader.get_property('user', 'username')
    password = ConfigReader.get_property('user', 'password')
    pocket48_handler.login(username, password)

    DEBUG('读取配置文件')

    ConfigReader.read_conf()
    global_config.ACTIVE_MEMBER_ROOM_ID_LIST = ConfigReader.get_all_member_room_id_list()
    global_config.LIVING_MEMBER_ID_LIST = ConfigReader.get_living_member_id_list()


    global_config.AUTO_REPLY_GROUPS = ConfigReader.get_property('qq_conf', 'auto_reply_groups').split(';')
    global_config.MEMBER_ROOM_MSG_GROUPS = ConfigReader.get_property('qq_conf', 'member_room_msg_groups').split(';')
    global_config.MEMBER_ROOM_COMMENT_GROUPS = ConfigReader.get_property('qq_conf', 'member_room_comment_groups').split(';')
    global_config.MEMBER_LIVE_GROUPS = ConfigReader.get_property('qq_conf', 'member_live_groups').split(';')
    global_config.MEMBER_ROOM_MSG_LITE_GROUPS = ConfigReader.get_property('qq_conf', 'member_room_comment_lite_groups').split(';')

    auto_reply_groups = QQHandler.list_group(global_config.AUTO_REPLY_GROUPS)
    member_room_msg_groups = QQHandler.list_group(global_config.MEMBER_ROOM_MSG_GROUPS)
    member_room_comment_msg_groups = QQHandler.list_group(global_config.MEMBER_ROOM_COMMENT_GROUPS)
    member_live_groups = QQHandler.list_group(global_config.MEMBER_LIVE_GROUPS)
    member_room_msg_lite_groups = QQHandler.list_group(global_config.MEMBER_ROOM_MSG_LITE_GROUPS)

    pocket48_handler.member_room_msg_groups = member_room_msg_groups
    pocket48_handler.member_room_comment_msg_groups = member_room_comment_msg_groups
    pocket48_handler.auto_reply_groups = auto_reply_groups
    pocket48_handler.member_live_groups = member_live_groups
    pocket48_handler.member_room_msg_lite_groups = member_room_msg_lite_groups

    global_config.JIZI_KEYWORDS = ConfigReader.get_property('profile', 'jizi_keywords').split(';')
    global_config.JIZI_LINK = ConfigReader.get_property('profile', 'jizi_link').split(';')

    global_config.WEIBO_KEYWORDS = ConfigReader.get_property('profile', 'weibo_keywords').split(';')
    global_config.GONGYAN_KEYWORDS = ConfigReader.get_property('profile', 'gongyan_keywords').split(';')
    global_config.LIVE_LINK=ConfigReader.get_property('profile', 'live_link').split(';')
    global_config.LIVE_SCHEDULE = ConfigReader.get_property('profile', 'live_schedule').split(';')

    global_config.WEIBO_LINK = ConfigReader.get_property('profile', 'weibo_link')
    global_config.SUPER_TAG = ConfigReader.get_property('profile', 'super_tag')

    global_config.MEMBER_ATTR = ConfigReader.get_property('profile', 'member_attr')
    global_config.I_LOVE = ConfigReader.get_property('profile', 'i_love').split(';')

    global_config.AT_AUTO_REPLY = ConfigReader.get_property('profile', 'at_auto_reply').split(';')
    global_config.ROOM_MSG_LITE_NOTIFY = ConfigReader.get_property('profile', 'room_msg_lite_notify').split(';')

    global_config.PERFORMANCE_NOTIFY = ConfigReader.get_property('profile', 'performance_notify')

    # 哔哩哔哩消息初始化
    bilibili_video_list = pocket48_handler.get_bilibili_video_list()
    pocket48_handler.init_bilibili_video_queues(bilibili_video_list)

    # 成员房间消息初始队列化
    pocket48_handler.init_msg_queues(global_config.ACTIVE_MEMBER_ROOM_ID_LIST)

    # 先更新配置
    update_conf(bot)
コード例 #16
0
from utils import global_config
from utils import util
import json
from utils.config_reader import ConfigReader

from utils.scheduler import scheduler
from log.my_logger import logger
from pocket48.pocket48_handler import Pocket48ListenTask, Member

# 读取口袋48的配置
global_config.MEMBER_JSON = json.load(open('data/pocket48/member.json', encoding='utf8'))
global_config.POCKET48_JSON = json.load(open('data/pocket48/pocket48.json'), encoding='utf8')
global_config.POCKET48_VERSION = global_config.POCKET48_JSON['version']
global_config.IMEI = global_config.POCKET48_JSON['IMEI']

global_config.AUTO_REPLY_GROUPS = ConfigReader.get_property('qq_conf', 'auto_reply_groups').split(';')
global_config.TEST_GROUPS = ConfigReader.get_property('qq_conf', 'test_groups').split(';')
global_config.PERFORMANCE_NOTIFY = ConfigReader.get_property('profile', 'performance_notify')
global_config.LIVE_LINK = ConfigReader.get_property('auto_reply', '公演直播')

using_pro = ConfigReader.get_property('root', 'using_coolq_pro')
if using_pro == 'yes':
    global_config.USING_COOLQ_PRO = True

logger.debug('读取成员信息')
members_list = global_config.POCKET48_JSON['monitor_members']
for member in members_list:
    member_pinyin = member['name']
    if member_pinyin in global_config.MEMBER_JSON:
        # 如果成员名在数据文件中,创建监听任务
        member_json = global_config.MEMBER_JSON[member_pinyin]
コード例 #17
0
    def __init__(self, screen: Monitor, ui_screen: Monitor = None, config_reader: ConfigReader = ConfigReader()):
        """
        Class to display image or video onto faces.
        :param screen: (Monitor) Screen to display the mapping
        :param ui_screen: (Monitor) Screen information of the ui (use by the web interface)
        :param config_reader: (ConfigReader) Config file class
        """
        self.config_reader = config_reader
        self.screen = screen
        self.ui_screen = ui_screen
        self.screen_relation = None
        self.test_image = cv2.imread(TEST_IMAGE)
        # Start the projector show
        self.projector_show = ProjectorShow(self.screen, NB_FACES, config_reader.Py_video_mapping.getint("delay"))

        if self.ui_screen is not None:
            self.screen_relation = ScreenRelation(ui_screen, self.screen)
        self.projector_show.start()

        # creat faces
        for i in range(NB_FACES):
            self.projector_show.display_face(i, ImageGetter(self.test_image))
コード例 #18
0
                if not (time_start <= season < time_end):
                    continue

                filename = split_path + '{}.json'.format(season)
                if filename not in time_reviews_filenames:
                    time_reviews_filenames[filename] = codecs.open(
                        filename, encoding='utf-8', mode='w')
                time_reviews_filenames[filename].write(line)

        for filename in time_reviews_filenames:
            time_reviews_filenames[filename].close()


if __name__ == '__main__':
    import os
    config_reader = ConfigReader(config_filename='../config/yelp.ini')
    filtered_path = config_reader['path', 'filtered_path', 'string']
    if not os.path.exists(filtered_path):
        os.makedirs(filtered_path)

    if 0:
        print '-' * 50 + 'Filtering' + '-' * 50
        print '*' * 50
        print 'Count user-reviews number and business-reviews number.'
        reviews_filename = config_reader['path', 'reviews_filename', 'string']
        users_num_filename = filtered_path + config_reader[
            'path', 'users_num_filename', 'string']
        businesses_num_filename = filtered_path + config_reader[
            'path', 'businesses_num_filename', 'string']
        Dataset.read_reviews(reviews_filename, users_num_filename,
                             businesses_num_filename)
コード例 #19
0
def parse_args():
    """Parse command line arguments."""
    parser = argparse.ArgumentParser('train.py')
    add_arg = parser.add_argument
    add_arg('--device', default='cpu')
    add_arg('--config', default='configs/train_config_big.yaml')
    add_arg('--out_dir_colab', default='')
    return parser.parse_args()


if __name__ == '__main__':

    args_in = parse_args()

    reader = ConfigReader(args_in.config)
    cfg = reader.cfg
    config_train = cfg['train']

    if args_in.out_dir_colab != "":
        out_dir = args_in.out_dir_colab  #"/gdrive/My Drive/graph/result_colab"
    else:
        out_dir = config_train['result_dir']

    logfilename = '%(asctime)s %(levelname)s %(message)s'

    os.makedirs(out_dir, exist_ok=True)

    logging.basicConfig(filename=(out_dir + "/process_log.log"),
                        level=logging.INFO,
                        format=logfilename)
コード例 #20
0
import sys
from utils.config_reader import ConfigReader
from train_dnn_gru import TrainDNN
#from train_autoencoder import TrainAutoencoder

#Codes by: Yu Wang, July 2016 Copyright@MOBVOI
if __name__ == '__main__':
    if len(sys.argv) != 2:
        print 'Usage: python train_gru.py config_file'
        exit(1)
    config_file = sys.argv[1]
    conf = ConfigReader(config_file)
    conf.ReadConfig()
    #TrainAutoencoder(conf)
    TrainDNN(conf)
コード例 #21
0
    register_function_for_active, register_function_for_sleep
from utils.config_reader import ConfigReader
from ffpyplayer.player import MediaPlayer

FOLDER_ABSOLUTE_PATH = os.path.normpath(os.path.dirname(os.path.abspath(__file__)))
MOTION_DETECTION_SONG_PATH = os.path.join(FOLDER_ABSOLUTE_PATH, "ressources", "sounds", "son_de_la_foret.mp3")
CORRECT_SOUND = os.path.join(FOLDER_ABSOLUTE_PATH, "ressources", "sounds", "mario_yippee.wav")
INCOMPREHENSION_SOUND = os.path.join(FOLDER_ABSOLUTE_PATH, "ressources", "sounds", "mario_oof.wav")

KARAOKE_TIME = 1  # Time in seconds to lock the karaoke

NEXT_STEPS: List[Callable[[], None]] = []  # Global var to know what the next function should be

args = docopt(__doc__)
config_file_path = args["<config-file-path>"]
config_reader = ConfigReader(config_file_path)
py_video_mapping = PyVideoMapping(PyVideoMapping.get_all_screens()[-1], config_reader=config_reader)
scenario = Scenario(py_video_mapping)


@register_function_for_active
@register_function_for_intent(intent=Intent.SALUTATION)
def display_main_menu():
    scenario.display_main_menu()


@register_function_for_intent(intent=Intent.FIN)
def force_sleep_mode():
    vc.set_mode_sleep()

コード例 #22
0
class GenerateTestData:
    """ The main class for creating a dummy data """
    def __init__(self):
        self.conf_reader = ConfigReader('./conf/db.ini')

        self.data_file = self.conf_reader.get_attr('file_name_raw')
        self.schema_raw = self.conf_reader.get_attr('transaction_db_raw')
        self.raw_table_name = 'transaction_log'
        self.raw_full_table_name = '.'.join(
            [self.schema_raw, self.raw_table_name])

        self.database = PostgreSQLCommon()

    @m.wrapper(m.entering, m.exiting)
    def create_db_schema(self):
        """ Execute a script schema_transaction.sql """
        sql_script_path = 'sql/schema_transaction.sql'

        if os.path.exists(sql_script_path):
            with open('sql/schema_transaction.sql', 'r') as file:
                sql_command = file.read()

                try:
                    self.database.execute(sql_command)
                    m.info('SQL script %s has been successfully executed!' %
                           sql_script_path)
                except psycopg2.Error as err:
                    m.error('OOps! Script executing FAILED! Reason: %s' %
                            str(err.pgerror))
        else:
            m.error('Oops! No such file %s' % sql_script_path)
            raise FileNotFoundError

    @staticmethod
    def create_folder(dir_name):
        """ Create a folder for the csv-data keeping """
        try:
            if not os.path.exists(dir_name):
                os.makedirs(dir_name)
            m.info('Directory %s has been created!' % dir_name)
        except Exception as err:
            m.error('Oops! Folder creating FAILED! Reason: %s' % err)

    @m.timing
    @m.wrapper(m.entering, m.exiting)
    def create_csv_file(
        self,
        num_rows,
    ):
        """ Create csv file """
        csv_creator = TestDataCreator(num_rows, self.conf_reader,
                                      self.data_file)
        csv_creator.run_csv_writing()

    @m.timing
    @m.wrapper(m.entering, m.exiting)
    def bulk_copy_to_db(self):
        """ Insert data into DB """
        columns = ('transaction_uid', 'account_uid', 'transaction_date',
                   'type_deal', 'transaction_amount')

        try:
            with open(self.data_file, 'r') as csv_file:
                rows = self.database.bulk_copy(csv_file,
                                               self.raw_full_table_name,
                                               columns)
                m.info('Have been added %s rows into %s' %
                       (rows, self.raw_full_table_name))
        except psycopg2.Error as err:
            m.error('OOps! Bulk copy process FAILED! Reason: %s' % err.pgerror)

    @m.timing
    @m.wrapper(m.entering, m.exiting)
    def random_delete_rows(self):
        """ Random deleting some rows from the table """
        sql_command = sql.SQL("""
                        delete from {0}.{1}
                        where ctid = any(array(
                          select ctid
                          from {0}.{1}
                          tablesample bernoulli (1)
                          ))""").format(sql.Identifier(self.schema_raw),
                                        sql.Identifier(self.raw_table_name))
        try:
            rows = self.database.execute(sql_command)
            m.info('Has been deleted [%s rows] from table %s' %
                   (rows, self.raw_table_name))
        except psycopg2.Error as err:
            m.error('Oops! Delete random rows has been FAILED. Reason: %s' %
                    err.pgerror)

    @m.timing
    @m.wrapper(m.entering, m.exiting)
    def random_update_rows(self):
        """ Random update some rows from the table """
        sql_command = sql.SQL("""
                update {0}.{1}
                set transaction_amount = round(random()::numeric, 2)
                where ctid = any(array(
                  select ctid
                  from {0}.{1}
                  tablesample bernoulli (1) ))""").format(
            sql.Identifier(self.schema_raw),
            sql.Identifier(self.raw_table_name))
        try:
            rows = self.database.execute(sql_command)
            m.info('Has been updated [%s rows] from table %s' %
                   (rows, self.raw_table_name))
        except psycopg2.Error as err:
            m.error('Oops! Delete random rows has been FAILED. Reason: %s' %
                    err.pgerror)

    @m.timing
    def run(self, num_rows):
        """ Run the proceess """
        m.info('START!')
        self.create_db_schema()
        self.create_folder('data')
        self.create_csv_file(num_rows)
        self.bulk_copy_to_db()
        self.random_delete_rows()
        self.random_update_rows()
        m.info('END!')
コード例 #23
0
ファイル: weibo_plugin.py プロジェクト: billjyc/pocket48
                        pass
                        # QQHandler.send_to_groups(member_weibo_groups, '[CQ:image,file={}]'.format(newWB['video_url']))
                    if 'picUrls' in newWB.keys():
                        # for pic in newWB['picUrls']:
                        # 发一张图就可以了
                        pass
                        # QQHandler.send_to_groups(member_weibo_groups, '[CQ:image,file={}]'.format(newWB['picUrls'][0]))
                    if 'retweeted_status' in newWB.keys():
                        text = '转发微博:\n@{}: {}'.format(
                            newWB['retweeted_status']['user'],
                            newWB['retweeted_status']['text'])
                        pass
                        # QQHandler.send_to_groups(member_weibo_groups, text)


weibo_monitor = WeiboMonitor()
update_weibo_conf()

if __name__ == '__main__':
    global_config.MEMBER_WEIBO_GROUPS = ConfigReader.get_property(
        'qq_conf', 'member_weibo_groups').split(';')
    # weibo_monitor.login('*', '*')
    # uid = ConfigReader.get_property('weibo', name)
    from pocket48.pocket48_handler import Pocket48ListenTask, Member
    uid = 1134206783
    task = Pocket48ListenTask(Member('SNH48', 0, 0, 2689280541, 'SNH48'))
    weibo_monitor.getWBQueue(task)
    while True:
        monitor_member_weibo()
        time.sleep(5)
コード例 #24
0
ファイル: cool_http_server.py プロジェクト: billjyc/pocket48
from log.my_logger import logger
from utils.bot import bot
from utils.config_reader import ConfigReader
# from utils import global_config
# from modian_plugin import modian_handler
from qq.ai_reply import QQAIBot
from utils import util
import os
import sqlite3
import datetime
from datetime import date
import traceback

AUTO_REPLY = {}
items = ConfigReader.get_section('auto_reply')
logger.debug('items: %s', items)
for k, v in items:
    logger.debug('k: %s, v: %s', k, v)
    AUTO_REPLY[k] = v
    logger.debug('k in global_config.AUTO_REPLY: %s', k in AUTO_REPLY)
    logger.debug(AUTO_REPLY)

# groups = [483548995]
groups = ConfigReader.get_property('qq_conf', 'jizi_notify_groups').split(';')
test_groups = ConfigReader.get_property('qq_conf',
                                        'auto_reply_groups').split(';')
print(groups)
logger.debug('test groups: %s' % test_groups)
modian_json = json.load(open("data/modian.json", encoding='utf8'))
コード例 #25
0
ファイル: prepare.py プロジェクト: gooldan/GraphTracking_v0
    logging.info("Node reduce: %.2f times" % (np.mean(info_dict['reduce'])))
    logging.info("Edge reduce: %.2f times" % (np.mean(info_dict['reduce_edge'])))

    plt.figure(figsize=(12, 6))
    plt.subplot(121)
    binning = dict(bins=300)
    plt.hist(info_dict['node_count'], label='node_count', log=True, **binning)
    plt.xlabel('counts')
    plt.ylabel('count of events')
    plt.legend(loc=0)

    plt.subplot(122)
    binning = dict(bins=300)
    plt.hist(info_dict['edge_count'], label='edge_count', log=True, **binning)
    plt.xlabel('dx')
    plt.ylabel('count of nodes in supergraph')
    plt.legend(loc=0)
    plt.savefig(config_prepare['output_dir'] + '/result.png', bbox_inches='tight', dpi=500)
    stat_dict = pd.DataFrame.from_dict(info_dict)
    stat_dict.to_csv(config_prepare['output_dir'] + '/prepare_stats.csv')
    plt.show()



if __name__ == '__main__':
    reader = ConfigReader("configs/prepare_config.yaml")
    cfg = reader.cfg
    df = parse_df(cfg['df'])
    events_df = get_events_df(cfg['df'], df, preserve_fakes=True)
    prepare_events(cfg, cfg['prepare'], events_df)
    pass
コード例 #26
0
add('-c', '--config')
add('-n', '--experiment-name')

args = parser.parse_args()

# num_args = len(sys.argv) - 1

# if num_args != 1:
#     print('run.py accepts a single argument specifying the config file.')
#     exit(1)

# Read the config file
# config = ConfigReader(sys.argv[1])
config_id = args.config

config = ConfigReader(f"configs/config{config_id}")

RELATIONAL = config.val("RELATIONAL")
RELATION_TYPE = config.val("RELATION_TYPE")
RECURRENT_TRANSITION = config.val("RECURRENT_TRANSITION")
TRAINING = config.val("TRAINING")
G_FUNC = config.val("G_FUNC")
HINGE = torch.tensor(config.val("HINGE"))

NUM_SLOTS = config.val("NUM_SLOTS")
SLOT_DIM = config.val("SLOT_DIM")
HIDDEN_DIM = config.val("HIDDEN_DIM")
NUM_HEADS = config.val("NUM_HEADS")

EXPE = config.val("EXPE")
NUM_EPOCHS = config.val("NUM_EPOCHS")
コード例 #27
0
def onQQMessage(bot, contact, member, content):
    # 当收到 QQ 消息时被调用
    # bot     : QQBot 对象,提供 List/SendTo/GroupXXX/Stop/Restart 等接口,详见文档第五节
    # contact : QContact 对象,消息的发送者
    # member  : QContact 对象,仅当本消息为 群或讨论组 消息时有效,代表实际发消息的成员
    # content : str 对象,消息内容
    # DEBUG('member: %s', str(getattr(member, 'uin')))
    # DEBUG('content: %s', content)
    # DEBUG('contact: %s', contact.ctype)
    global pocket48_handler

    if contact.ctype == 'group':
        if '@ME' in content:  # 在群中@机器人
            strs = content.split('[@ME]')[1].strip()
            if strs :
                id = contact.uin
                bot.SendTo(contact, pocket48_handler.get_tuling_ai(id, strs))
            else:
                bot.SendTo(contact, util.random_str(global_config.AT_AUTO_REPLY))
        elif content.startswith('-'):  # 以'-'开头才能触发自动回复
            if content == '-version':
                bot.SendTo(contact, 'QQbot-' + bot.conf.version)
            elif content == '-票务' or content == '-公演':
                pocket48_handler.get_current_ticket_info_msg(global_config.TICKET_INFO)
            elif content == '-屏蔽全部消息' or content == '-屏蔽所有消息':
                if len(global_config.ACTIVE_MEMBER_ROOM_ID_LIST) > 0:
                    global_config.DEACTIVE_MEMBER_ROOM_ID_LIST = ConfigReader.get_all_member_room_id_list()
                    global_config.ACTIVE_MEMBER_ROOM_ID_LIST = []
                    QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '已屏蔽全部房间消息')

                else:
                    QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '当前已屏蔽全部房间消息,请不要重复输入命令')
            elif content == '-开启全部消息' or content == '-开启全部消息':
                if len(global_config.DEACTIVE_MEMBER_ROOM_ID_LIST) > 0:
                    global_config.ACTIVE_MEMBER_ROOM_ID_LIST = ConfigReader.get_all_member_room_id_list()
                    global_config.DEACTIVE_MEMBER_ROOM_ID_LIST = []
                    pocket48_handler.init_msg_queues(global_config.ACTIVE_MEMBER_ROOM_ID_LIST)
                    QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '已开启全部房间消息')
                else:
                    QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '当前已开启全部房间消息,请不要重复输入命令')
            elif content == '-关闭':
                bot.SendTo(contact, 'QQ机器人已关闭')
                bot.Stop()
            elif '-屏蔽' in content and '消息' in content:
                if len(global_config.ACTIVE_MEMBER_ROOM_ID_LIST) > 0:
                    name = util.get_order_name(content)
                    # 命令是否包含成员名字
                    if util.is_name_in_member_list(name):
                        # 屏蔽逻辑
                        pocket48_handler.deactive_member_by_name(name)
                    else:
                        QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '屏蔽失败, 无法识别该成员,请确保命令输入正确')
                else:
                     QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '当前已屏蔽全部房间消息,无法再进行屏蔽')
            elif '-开启' in content and '消息' in content:
                if len(global_config.DEACTIVE_MEMBER_ROOM_ID_LIST) > 0:
                    name = util.get_order_name(content)
                    # 命令是否包含成员名字
                    if util.is_name_in_member_list(name):
                        # 开启逻辑
                        pocket48_handler.active_member_by_name(name)
                    else:
                        QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '开启失败, 无法识别该成员,请确保命令输入正确')
                else:
                    QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, '当前已开启全部房间消息,无法再进行开启')
            elif content == '-直播':
                r = pocket48_handler.get_member_live_msg()
                pocket48_handler.parse_member_live_now(r, global_config.LIVING_MEMBER_ID_LIST)
            elif content == '-小黑屋':
                msg = util.get_black_room_list()
                QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, msg)
            elif content == '-小白屋':
                msg = util.get_white_room_list()
                QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, msg)
            elif content == '-使用说明':
                msg = '''
机器人使用说明:
一、命令类型(输入一次即可, 没回复可能是机器人没开启 或者 机器人卡住了):
    (1)'-票务':  查看尚未公演的票务信息.
    (2)'-直播':  查看所有正在直播的直播间.
    (3)'-使用说明':  机器人使用说明.
    (4)'-屏蔽全部(所有)消息':  屏蔽全部成员房间消息.
    (5)'-开启全部(所有)消息':  开启全部成员房间消息.
    (6)'-屏蔽' + 成员名字 + '消息':  屏蔽某个成员房间消息.
    (7)'-开启' + 成员名字 + '消息':  开启某个成员房间消息.
    (8)'-小黑屋':  查看被屏蔽房间消息的成员.
    (9)'-小白屋':  查看已开启房间消息的成员
    其余命令均无法识别
二、聊天
    '@机器人' + 聊天内容:  与图灵机器人聊天 (每天上限1000次, 河内梗完善中...)'''
                QQHandler.send_to_groups(pocket48_handler.member_room_msg_groups, msg)
            else:  # 无法识别命令
                no_such_command = ConfigReader.get_property('profile', 'no_such_command')
                bot.SendTo(contact, no_such_command)
コード例 #28
0
    def __init__(self, prefix=''):
        self.prefix = prefix

        self.save_dir = op.join(SAVE_DIR, prefix)
        self.config_dir = op.join(CONFIG_DIR, prefix)

        self.config_dict = {}

        # list all directories
        c_dirs = os.listdir(self.config_dir)
        regex = r'config([0-9]+)'
        config_list = [
            re.search(regex, p)[1] for p in c_dirs if re.search(regex, p)
        ]

        s_dirs = os.listdir(self.save_dir)
        for c_idx in config_list:
            c_idx = int(c_idx)

            self.config_dict[c_idx] = {}

            # read all config params and store them in a dict
            self.config_dict[c_idx]['path'] = op.join(self.save_dir,
                                                      f'config{c_idx}')
            config = ConfigReader(op.join(self.config_dir, f'config{c_idx}'))
            for name, setting in config.settings.items():
                value = setting.get_value()
                self.config_dict[c_idx][name] = value

            # add the special OCCLUDER param
            self.config_dict[c_idx]['OCCLUDER'] = \
                ('occluder' in self.config_dict[c_idx]['EXPE'])

            # did the run complete without error ?
            self.config_dict[c_idx]['completed'] = 'yes'
            if prefix:
                # this means the results come from clusters and were computed
                # with slurm, so we can read the error logs
                err_log_path = op.join(self.save_dir, f'config{c_idx}_log.err')
                with open(err_log_path, 'r') as errf:
                    error_message = errf.readlines()
                    if error_message:
                        self.config_dict[c_idx]['completed'] = 'no'

            # check if model file and train data are present
            files = os.listdir(self.config_dict[c_idx]['path'])
            if 'model.pt' not in files:
                self.config_dict[c_idx]['completed'] = 'no'
            if 'train_data.hdf5' not in files:
                self.config_dict[c_idx]['completed'] = 'no'

            train_data = utl.load_dict_h5py(
                op.join(self.config_dict[c_idx]['path'], 'train_data.hdf5'))

            if len(train_data['energy']) != config.val('NUM_EPOCHS'):

                print(f'config {c_idx}')
                print(
                    f'length of train data ({len(train_data["energy"])}) does'
                    f'not match number of epochs ({config.val("NUM_EPOCHS")})')

                self.config_dict[c_idx]['completed'] = 'partial'
コード例 #29
0
def update_modian_conf():
    global modian_handler
    time0 = time.time()
    my_logger.info('读取摩点配置')
    ConfigReader.read_conf()
    # modian_json = json.load(open("data/modian.json", encoding='utf8'))
    # modian_json = json.load(open("data/weixin_group_account.json", encoding='utf8'))
    modian_json = json.load(open("data/taoba_account.json", encoding='utf8'))

    modian_handler.login(modian_json['taoba_account'],
                         modian_json['taoba_passwd'])

    global_config.MODIAN_POSTSCRIPTS = modian_json['modian_postscripts']

    # 摩点集资PK链接数组初始化
    global_config.MODIAN_NEED_DISPLAY_PK = modian_json[
        'modian_need_display_pk']

    for modian_pk_j in modian_json['modian_pk_activities']:
        global_config.MODIAN_PK_ARRAY.append(modian_pk_j)

    # 是否需要开启抽卡功能
    global_config.MODIAN_CARD_DRAW = modian_json['modian_need_card_draw']

    # global_config.MODIAN_300_ACTIVITY = modian_json['modian_300_activity']

    # 需要适应同时开多个链接的情况
    global_config.MODIAN_ARRAY = []

    for modian_j in modian_json['monitor_activities']:
        # if modian_j['modian_need_display_rank'] is False:
        # modian = ModianEntity(modian_j['modian_link'], modian_j['modian_title'], modian_j['modian_pro_id'], False,
        #                       modian_j['broadcast_groups'])
        # modian = GroupAccountEntity(modian_j['modian_link'], modian_j['modian_title'], modian_j['modian_pro_id'],
        #                             modian_j['broadcast_groups'], modian_j['qrcode'])
        modian = TaoBaEntity(modian_j['modian_link'], modian_j['modian_title'],
                             modian_j['modian_pro_id'],
                             modian_j['broadcast_groups'], modian_j['qrcode'])
        # elif modian_j['wds_need_display_rank'] is True:
        #     modian = ModianEntity(modian_j['modian_link'], modian_j['modian_title'], modian_j['modian_pro_id'], True,
        #                           modian_j['broadcast_groups'])
        global_config.MODIAN_ARRAY.append(modian)

    modian_handler.taoba_project_array = global_config.MODIAN_ARRAY

    # modian_handler.init_order_queues()
    modian_handler.card_draw_handler.read_config()

    global_config.JIZI_NOTIFY_GROUPS = ConfigReader.get_property(
        'qq_conf', 'jizi_notify_groups').split(';')
    modian_groups = global_config.JIZI_NOTIFY_GROUPS
    modian_handler.group_account_notify_groups = modian_groups

    my_logger.debug('JIZI_NOTIFY_GROUPS: %s, length: %d',
                    ','.join(global_config.JIZI_NOTIFY_GROUPS),
                    len(modian_handler.group_account_notify_groups))

    my_logger.debug('读取正在进行中的flag活动')
    global_config.MODIAN_FLAG_ACTIVITIES = {}
    flag_json = json.load(open('data/modian_flag.json',
                               encoding='utf8'))['activities']
    for modian in global_config.MODIAN_ARRAY:
        pro_id = modian.taoba_id
        global_config.MODIAN_FLAG_ACTIVITIES[pro_id] = []
    for activity in flag_json:
        pro_id = activity['pro_id']
        end_time = activity['end_time']
        if util.convert_timestr_to_timestamp(end_time) > time.time():
            flag = ModianFlagEntity(activity['flag_name'], activity['pro_id'],
                                    activity['target_flag_amount'],
                                    activity['end_time'], activity['remark'])
            global_config.MODIAN_FLAG_ACTIVITIES[int(pro_id)].append(flag)
    my_logger.debug('MODIAN_FLAG_ACTIVITIES: %s',
                    global_config.MODIAN_FLAG_ACTIVITIES)

    my_logger.debug('读取正在进行的人头flag活动')
    global_config.MODIAN_COUNT_FLAG_ACTIVITIES = {}
    count_flag_json = json.load(
        open('data/modian_count_flag.json', encoding='utf8'))['activities']
    for modian in global_config.MODIAN_ARRAY:
        pro_id = modian.taoba_id
        global_config.MODIAN_COUNT_FLAG_ACTIVITIES[pro_id] = []
    for activity in count_flag_json:
        pro_id = activity['pro_id']
        start_time = activity['start_time']
        end_time = activity['end_time']
        if util.convert_timestr_to_timestamp(
                start_time) >= util.convert_timestr_to_timestamp(end_time):
            my_logger.error('人头类flag,起始时间大于结束时间!')
            raise RuntimeError('起始时间大于结束时间')
        time0 = time.time()
        if util.convert_timestr_to_timestamp(
                end_time) > time0 > util.convert_timestr_to_timestamp(
                    start_time):
            flag = ModianCountFlagEntity(activity['flag_name'],
                                         activity['pro_id'],
                                         activity['target_flag_amount'],
                                         activity['start_time'],
                                         activity['end_time'],
                                         activity['remark'])
            global_config.MODIAN_COUNT_FLAG_ACTIVITIES[int(pro_id)].append(
                flag)
    my_logger.debug('MODIAN_COUNT_FLAG_ACTIVITIES: %s',
                    global_config.MODIAN_COUNT_FLAG_ACTIVITIES)

    # 接棒活动更新,读取json文件中的内容,更新到数据库中
    my_logger.debug('接棒活动更新,读取json文件中的内容,更新到数据库中')
    jiebang_json = json.load(open('data/modian_jiebang.json',
                                  encoding='utf8'))['activities']
    # conn = sqlite3.connect('data/modian.db', check_same_thread=False)
    for activity in jiebang_json:
        end_time = activity['end_time']
        my_logger.debug('活动结束时间: {}; 当前时间:{}'.format(
            util.convert_timestr_to_timestamp(end_time), time.time()))
        if util.convert_timestr_to_timestamp(end_time) < time.time():
            my_logger.debug('活动结束时间早于当前时间,跳过')
            continue
        name = activity['jiebang_name']
        try:
            # cursor = conn.cursor()
            # c = cursor.execute("""
            #     select * from jiebang WHERE name=?
            # """, (name, ))
            # rst = c.fetchall()
            rst = mysql_util.select_one(
                """
                select * from jiebang WHERE name=%s
            """, (name, ))
            my_logger.debug(rst)
            if rst is not None:
                my_logger.debug('DB中有相应的接棒活动')
            else:
                my_logger.debug('DB中没有对应的接棒活动,需要创建')
                mysql_util.query(
                    """
                                    INSERT INTO jiebang (name, pro_id, current_stick_num, start_time, 
                                    end_time, target_stick_num, min_stick_amount, need_detail) VALUES
                                    (%s, %s, %s, %s, %s, %s, %s, %s)
                                """,
                    (name, activity['pro_id'], 0, activity['start_time'],
                     activity['end_time'], activity['target_stick_num'],
                     activity['min_stick_amount'], activity['need_detail']))
                # conn.commit()
            # else:
            #     raise RuntimeError('接棒活动名称错误!')
        except Exception as e:
            my_logger.error('读取mysql出现错误')
            my_logger.exception(e)
        # finally:
        #     cursor.close()

    # 读取正在进行中的接棒活动
    my_logger.debug('读取正在进行中的接棒活动')
    global_config.MODIAN_JIEBANG_ACTIVITIES = {}
    for modian in global_config.MODIAN_ARRAY:
        pro_id = modian.taoba_id
        global_config.MODIAN_JIEBANG_ACTIVITIES[pro_id] = []
        try:
            # cursor = conn.cursor()
            rst = mysql_util.select_all(
                """
                SELECT name, pro_id, current_stick_num, last_record_time, 
                    start_time, end_time, target_stick_num, min_stick_amount, need_detail
                FROM jiebang where pro_id=%s 
                    and end_time >= NOW() and current_stick_num < target_stick_num
            """, (pro_id, ))
            if rst:
                for jiebang in rst:
                    my_logger.debug('jiebang name: {}'.format(
                        str(jiebang[0], encoding='utf-8')))
                    # 修正当前棒数
                    my_logger.info('修正接棒棒数')
                    real_stick_num = 0
                    rst0 = mysql_util.select_all(
                        """
                                    SELECT backer_money FROM `order`
                                        WHERE pro_id = %s and backer_money >= %s and pay_time >= %s and pay_time <= %s
                                """,
                        (pro_id, jiebang[7], jiebang[4], jiebang[5]))
                    my_logger.debug(
                        """
                                    SELECT backer_money FROM `order`
                                        WHERE pro_id = %s and backer_money >= %s and pay_time >= %s and pay_time <= %s
                                """ %
                        (pro_id, jiebang[7], jiebang[4], jiebang[5]))
                    my_logger.debug(rst0)
                    if rst0:
                        for order in rst0:
                            my_logger.debug('order: {}'.format(order[0]))
                            real_stick_num += int(order[0] // jiebang[7])

                    my_logger.info('记录棒数: {}, 实际棒数: {}'.format(
                        jiebang[2], real_stick_num))
                    mysql_util.query(
                        """
                        UPDATE jiebang SET current_stick_num = %s WHERE name = %s
                    """, (real_stick_num, jiebang[0]))

                    my_logger.debug(
                        'jiebang: %s, %s, %s, %s, %s, %s, %s, %s, %s',
                        jiebang[0], jiebang[1], jiebang[2], jiebang[3],
                        jiebang[4], jiebang[5], jiebang[6], jiebang[7],
                        jiebang[8])
                    jiebang_entity = ModianJiebangEntity(
                        str(jiebang[0], encoding='utf-8'), jiebang[1],
                        jiebang[2], jiebang[3], jiebang[4], jiebang[5],
                        jiebang[6], jiebang[7], jiebang[8])
                    jiebang_entity.current_stick_num = real_stick_num
                    my_logger.info('修正完成')
                    global_config.MODIAN_JIEBANG_ACTIVITIES[pro_id].append(
                        jiebang_entity)

        except Exception as e:
            my_logger.error('读取正在进行中的接棒活动出现错误!')
            my_logger.exception(e)
        # finally:
        #     cursor.close()
    my_logger.debug(global_config.MODIAN_JIEBANG_ACTIVITIES)
    # conn.close()

    my_logger.debug('读取摩点配置耗时: %s秒', time.time() - time0)
    modian_handler.init_order_queues()
コード例 #30
0
ファイル: main.py プロジェクト: feizei2008/binance_demo
import pandas as pd
from utils.log import logger
from binance_f import RequestClient
from binance_f.model import *
from binance_f.base.printobject import *
import json
import jsonpickle
from utils.config_reader import ConfigReader

config_reader = ConfigReader('config/api.ini')
api_key = config_reader.read_config('binance', 'api_key')
api_secret = config_reader.read_config('binance', 'api_secret')


def converter(obj):
    """
    转换api返回的json类对象格式,方便存储在本地
    :param obj:
    :return:
    """
    res = jsonpickle.encode(obj)
    res = json.loads(obj)
    return res


if __name__ == '__main__':
    logger.info('连接币安网站')
    request_client = RequestClient(api_key=api_key, secret_key=api_secret)

    logger.info('打印币种数据')
    symbols = request_client.get_exchange_information().symbols