コード例 #1
0
def send_email(from_='*****@*****.**', to='', subject='', message='', server='', port=25, username='', password='', use_ssl=False, starttls=False):
    logger.debug('Emailing %s' % to)
    if not server:
        return

    msg = MIMEText(message)

    msg['Subject'] = subject
    msg['From'] = from_
    msg['To'] = to


    if (use_ssl and not starttls):
        s = smtplib.SMTP_SSL(host=server, port=port)
    else:
        s = smtplib.SMTP(server, port)

    if (starttls):
        s.ehlo()
        s.starttls()
        s.ehlo()

    if (not username == '' and not password == ''):
        s.login(username, password)

    try:
        s.sendmail(from_, [to], msg.as_string())
        logger.info('Email sent to %s' % (to))
    except Exception as e:
        logger.error('Email sending produced exception %r' % e)
    s.quit()
コード例 #2
0
async def update_database(update_period: int,
                          insertion_period: int,
                          log: bool = False) -> None:
    """
    We update the database, as information about characters changes
    from time to time.

    :param update_period: Time in hours after which the database
    will be updated. Minimum 24 hours
    
    :param insertion_period: Time in seconds after which the
    request to the site will occur. Minimum 15 seconds

    :param log: Whether to write data about character
    insertion into the logs. False by default
    """
    update_period *= 3600
    if update_period < 24:
        update_period = 25

    while True:
        logger.info(f"{__name__}: Start updating database")
        champions = get_all_champions_links()

        if champions:
            await update_champions(insertion_period, champions, log)

        logger.info(f"{__name__} - Database updated completed")
        await asyncio.sleep(update_period)
コード例 #3
0
    def handle(self, handler_input):
        logger.info("HAN    ActDescriptHandler")
        speech_list = []

        activity = SlotUtils.get_resolved_value( handler_input, "activity")

        if not activity:
            logger.info("ActDescriptHandler: Non-resolved activity.")
            ms_overall_descript = DescriptUtils.get_ms_overall_act_descript()
            speech_list.append( ms_overall_descript)
        
        else:
            DescriptUtils.set_attr(handler_input, activity)
            ms_act_descript = DescriptUtils.get_ms_corresponding_descript(activity)
            speech_list.append( ms_act_descript)
        
        prompt, reprompt = (
            DescriptUtils.get_q_play_activity(activity) for _ in range(2))
        prompt = CardFuncs.format_prompt(prompt)
        speech_list.append( Pauser.get_p_level(4))
        speech_list.append(prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)

        return (
            handler_input.response_builder
                .speak( speech)
                .ask( reprompt)
                .set_card( SimpleCard( card_title, card_text))
                .response)
コード例 #4
0
ファイル: bt.py プロジェクト: zikasak/ReadOnlyBot
def proceed_new_members(update, callback):
    bot = callback.bot
    members = update.message.new_chat_members
    logger.info(members)
    if len(members) == 0:
        return
    chat_id = update.message.chat_id
    API.delete_message(bot, chat_id, update.message.message_id)
    with dataWorker.session_scope() as session:
        chat: GroupStatus = session.query(GroupStatus).get(chat_id)
        reply_template = chat.wel_message
        if chat is None or reply_template is None:
            return
        for member in members:
            reply = reply_template.replace("""{$name}""",
                                           f"""<a href="tg://user?id={member.id}">{member.first_name}</a>""")
            kwargs = {"chat_id": chat_id,
                      "text": reply,
                      "disable_web_page_preview": True}
            if not chat.new_users_blocked or not can_restrict_users(bot, update):
                message = send_wel_message(bot, kwargs)
                time.sleep(30)
                if can_delete_messages(bot, update):
                    API.delete_message(bot, chat_id=message.chat_id, message_id=message.message_id)
            else:

                unlock_button = telegram.InlineKeyboardButton("Я прочитал",
                                                              callback_data="applied " + str(member.id))
                reply_markup = InlineKeyboardMarkup(build_menu([unlock_button], n_cols=1))
                kwargs["reply_markup"] = reply_markup
                msg = send_wel_message(bot, kwargs)
                chat.add_muted(member.id, msg.message_id)
                bot.restrict_chat_member(chat_id, member.id, telegram.ChatPermissions())
コード例 #5
0
def execute(pkg_name, cert_md5, file_md5, min_sdk, download_url, short_desc,
            file_size, ver_code, ver_name, detail_url, channel, apk_info):

    doc = get_game_info(pkg_name, detail_url)
    label_info, pkg_info = perpare_data(doc, download_url, file_size, ver_code,
                                        ver_name, channel, apk_info)
    pkg_info["signature_md5"] = cert_md5
    pkg_info["file_md5"] = file_md5
    pkg_info["min_sdk_version"] = min_sdk
    pkg_info["game_desc"] = pkg_info["game_desc"]
    #xiangxiaowei
    pkg_info["pkg_name"] = pkg_name
    pkg_info["gpu_vender"] = apk_info["gpu_vender"]
    pkg_info["update_desc"] = apk_info["update_desc"]
    pkg_info["ver_code_by_gg"] = apk_info["ggvercode"]
    pkg_info["save_user"] = apk_info["save_user"]
    pkg_info["ver_name"] = apk_info["ver_name"]

    label_info["short_desc"] = short_desc
    label_info["detail_desc"] = label_info["detail_desc"]
    label_info["save_user"] = apk_info["save_user"]

    if label_info and pkg_info:
        pkg_name = pkg_info["pkg_name"]

        # 记录游戏信息
        write_file(pkg_name, doc)

        # 插入google play游戏信息
        db.insert_label_info(label_info)
        db.insert_pkg_info(pkg_info)
        logger.info("insert game_id: %s, name: %s", label_info["game_id"],
                    label_info["game_name"])
コード例 #6
0
    def handle(self, handler_input):
        logger.info("HAN    SM_CorrectQuestionHandler")
        speech_list = []

        player_obj = PlayerDict.load_player_obj(handler_input)
        UserStats.update_player_stats(handler_input, correct = True, player_obj= player_obj)
        SM_Attr.increment_sm_upper(handler_input)
        
        ms_congrats = CongratUtils.get_answer_congrats(
            handler_input, player_obj= player_obj, survival_mode=True)

        logger.debug(ms_congrats)

        ms_question = SMQuestions.get_question(
            handler_input, first_question= False, player_obj= player_obj)
        reprompt = GenQuestions.get_same_question(handler_input)
        
        if len(ms_congrats):
            sm_pause = Pauser.get_sm_pause_length(handler_input)
            speech_list += Pauser.make_ms_pause_level_list(ms_congrats, sm_pause)
        speech_list.append( ms_question)
        
        SessionStats.update_consecutive_correct(handler_input, True)
        ModeStats.update_mode_stats(handler_input, True)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (
            handler_input.response_builder
                .speak(speech)
                .ask(reprompt)
                .set_card( SimpleCard( card_title, card_text))
                .response)
コード例 #7
0
    def handle(self, handler_input):
        # type (HandlerInput) -> Response
        logger.info("HAN    ExitIntentHandler")
        speech_list = []

        player_obj = PlayerDict.load_player_obj(handler_input)

        ## TODO: Implement sesh performance func.
        ms_session_performance = ExitUtils.get_ms_session_performance(
            handler_input)
        ms_exit = ExitUtils.get_ms_exit_game()

        speech_list.append(ms_session_performance)
        speech_list.append(ms_exit)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)

        ## Attr management @ very end.
        ExitUtils.update_player_mode_statistics(handler_input, player_obj)
        PlayerDict.save_player_obj(handler_input, player_obj)

        ExitUtils.exit_skill_attr_management(handler_input)
        return (handler_input.response_builder.speak(speech).set_card(
            SimpleCard(card_title,
                       card_text)).set_should_end_session(True).response)
コード例 #8
0
ファイル: funcs.py プロジェクト: calllivecn/MCLauncher
    def func(self):

        # headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"}

        while True:

            url, savepath = self.taskqueue.get()

            block = 1 << 14  # 16k
            try:
                req = request.Request(url, headers=USER_AGENT)
                with request.urlopen(req, timeout=60) as response:
                    with open(savepath, "wb") as f:
                        for data in iter(partial(response.read, block), b""):
                            f.write(data)

            except socket.timeout:
                logger.warning("下载超时:{}".format(url))
                os.remove(savepath)
                self.count += 1
                self.taskqueue.put((url, savepath))
                continue
            except Exception as e:
                logger.error("出错:{}".format(e))
                logger.error("出错url:{}".format(url))
                self.count += 1
                self.taskqueue.put((url, savepath))

            finally:
                # response.close()
                self.taskqueue.task_done()
                self.count -= 1
                logger.info("下载完成:{}".format(savepath))
                logger.debug("当前队列任务数:{}".format(self.count))
コード例 #9
0
ファイル: funcs.py プロジェクト: calllivecn/MCLauncher
def get_jars(jar_obj, savepath):
    sha1_value = jar_obj.get("sha1")
    url = jar_obj.get("url")
    size = jar_obj.get("size")

    logger.info("开始下载:{} ...".format(savepath))
    dler.submit((url, savepath))
コード例 #10
0
    def handle(self, handler_input):
        logger.info("HAN    CP_CorrectAnswerHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        practice_type = attr['practice_type']
        if practice_type == custom_practice.data.PRACT_TYPES[0]:
            CP_Attr.remove_question_from_incorrect_questions(
                handler_input)  ## Before updating last question
        CP_Attr.update_last_question_attr(handler_input, correct=True)

        player_obj = PlayerDict.load_player_obj(handler_input)
        UserStats.update_player_stats(handler_input,
                                      correct=True,
                                      player_obj=player_obj)

        ms_congrats = CongratUtils.get_answer_congrats(handler_input,
                                                       player_obj=player_obj)
        ms_question = CP_Questions.get_question(handler_input,
                                                player_object=player_obj,
                                                practice_type=practice_type,
                                                first_question=False)
        reprompt = GenQuestions.get_same_question(handler_input)

        speech_list = (ms_congrats, 1, ms_question)

        SessionStats.update_consecutive_correct(handler_input, True)
        ModeStats.update_mode_stats(handler_input, True)
        PlayerDict.save_player_obj(handler_input, player_obj)

        speech = get_linear_nlg(speech_list)
        reprompt = GenQuestions.get_same_question(handler_input)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
コード例 #11
0
    def handle(self, handler_input):
        logger.info("HAN    CP_WrongAnswerHandler")
        speech_list = []

        player_obj = PlayerDict.load_player_obj(handler_input)

        CP_Attr.update_last_question_attr(handler_input, correct=False)
        UserStats.update_player_stats(handler_input,
                                      correct=False,
                                      player_obj=player_obj)

        ms_wrong = IncorrectAnsUtils.get_ms_incorrect()
        question = GenQuestions.get_same_question(handler_input)
        reprompt = question
        speech_list = (
            ms_wrong,
            1,
            question,
        )

        SessionStats.update_consecutive_correct(handler_input, correct=False)
        ModeStats.update_mode_stats(handler_input, correct=False)
        WrongAnswer.record_wrong_question(handler_input)
        PlayerDict.save_player_obj(handler_input, player_obj)

        speech = get_linear_nlg(speech_list)
        reprompt = GenQuestions.get_same_question(handler_input)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
コード例 #12
0
 def check_data(self):
     wait.until(EC.presence_of_element_located(cn.cus_name))
     con_name = self.driver.find_element(*cn.con_name).text
     con_tel = self.driver.find_element(*cn.con_tel).text
     cert_type = self.driver.find_element(*cn.cert_type).text
     cert_num = self.driver.find_element(*cn.cert_num).text
     con_addr = self.driver.find_element(*cn.con_addr).text
     taxpayer = self.driver.find_element(*cn.taxpayer).text
     cus_id = self.driver.find_element(*cn.cus_id).text
     data = con_name.strip() +\
            con_tel.strip() + \
            cert_type.strip() + \
            cert_num.strip() + \
            con_addr.strip() + \
            taxpayer.strip()
     data_dict_new = str(data_dict['联系人']) + \
                     str(data_dict['联系电话']) + \
                     str(data_dict['证件类型']) + \
                     str(data_dict['证件号码']) + \
                     str(data_dict['联系地址']) + \
                     str(data_dict['一般纳税人'])
     if data == data_dict_new:
         print('校验一致')
         logger.info('校验一致')
     else:
         logger.error('校验不一致')
     return cus_id
コード例 #13
0
ファイル: gui.py プロジェクト: WilfMan/git_updater
def GUIrunPeriod():
    try:
        q = [IGuiPeriodCaller.qsize(), IGuiCaller.qsize(), IGuiIdleCaller.qsize()]
        if q[0] > 100 or q[1] > 100 or q[2] > 100:
            logging.info("IGuiPeriodCaller=%d(d %d) IGuiCaller=%d(d %d) IGuiIdleCaller=%d(d %d)" % (
                q[0], q[0] - oq[0], q[1], q[1] - oq[1], q[2], q[2] - oq[2]))
        oq[:] = q[:]  # Replace content in-place
        n = 0
        t = time.time()
        try:
            while True:
                Run = IGuiPeriodCaller.get(0)
                try:
                    n += 1
                    t0 = time.time()
                    Run()
                    t0 = time.time() - t0
                    if t0 > 0.1:
                        logging.info("Run=%r took %r", Run, t0)
                except Exception, E:
                    logging.error("GUIrun/period: %s\nRun = %r\nTraceback: %s", E, Run, traceback.format_exc())
        except Queue.Empty:
            pass
        tt = time.time()
        if tt - t > 0.05:
            logging.error("GUIrunPrriod: proceed %d for %r", n, tt - t)
        GUIrun(False)
    except Queue.Empty:
        pass
    return True
コード例 #14
0
def main():

    logger.info('Initialize')

    data_sink = Observable()
    builder = Builder(config)
    builder.bind(data_sink)
    leds = Leds()

    while True:
        try:
            prices = [entry[1:] for entry in get_dummy_data()
                      ] if config.dummy_data else fetch_prices()
            data_sink.update_observers(prices)
            leds.off()
            time.sleep(config.refresh_interval)

        except Exception as e:
            logger.error(str(e))
            leds.on()
            time.sleep(10)

        except KeyboardInterrupt:
            logger.info('Exit')
            data_sink.close()
            exit()
コード例 #15
0
ファイル: rpc.py プロジェクト: yobonez/aos-rpc
def scan_for_process():
    logger.info('Waiting for aos client.')

    ps_pid = None
    ps_cmdline = None

    while True:
        # Iterate thru processes to find one that matches our wanted one
        # and assign important variables for further functions that will be executed
        for proc in psutil.process_iter(['name', 'pid', 'cmdline']):
            if proc.info['name'] == 'client.exe':
                ps_pid = proc.info['pid']

                try:
                    ps_cmdline = proc.info['cmdline'][1] # This is the server identifier "aos://XXXXXXXXXX:XXXXX"

                    handle = pymem.Pymem('client.exe')
                    if handle.process_id != ps_pid:
                        logger.info("Not a valid aos process.")
                        return
                        
                except IndexError:
                    break
                except pymem.exception.ProcessNotFound:
                    break

                update_presence(ps_pid, ps_cmdline, handle)
            else:
                time.sleep(0.05)
コード例 #16
0
ファイル: twitter_api.py プロジェクト: goldver/twitter_api
    def on_data(self, tweet):
        """
        :param tweet:
        :return:
        """
        global start_time
        tweet_dict = json.loads(tweet)
        if 'entities' in tweet_dict:
            if 'hashtags' in tweet_dict['entities']:
                hashtags = tweet_dict['entities']['hashtags']
                if hashtags:
                    for hashtag in hashtags:
                        hashtags_counter[hashtag['text']] += 1
        logger.info(hashtags_counter.most_common(10))
        if (datetime.datetime.now() - start_time > datetime.timedelta(0, 10, 0)):
            start_time = datetime.datetime.now()
            temp = hashtags_counter.most_common(100)
            hashtags_counter.clear()
            # reduce time
            for ht in temp:
                hashtags_counter[ht[0]] = ht[1] * 0.9

        logger.info(datetime.datetime.now() - start_time)

        return True
コード例 #17
0
def create_backup_of_shortcuts(config, user, dry_run=False):
  def _create_directory_if_needed(directory):
    if os.path.exists(directory):
      return

    logger.debug("Creating directory: %s" % directory)
    os.makedirs(directory)

  backup_dir = backup_directory(config)
  if backup_dir is None:
    logger.info("No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info")
    return

  _create_directory_if_needed(backup_dir)

  if not os.path.isdir(backup_dir):
    logger.warning("Backup directory path is something other than a directory. Skipping backups")
    return

  backup_path = shortcuts_backup_path(backup_dir, user)

  # Make sure the user-specific backups dir exists
  _create_directory_if_needed(os.path.dirname(backup_path))

  shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
コード例 #18
0
    def fit(self):
        logger.info("[lstm classifier start creating model]")
        num_words = min(self.dataset.MAX_NB_WORDS,
                        len(self.dataset.word_index))
        embedding_layer = Embedding(
            num_words,
            self.dataset.EMBEDDING_DIM,
            weights=[self.dataset.embedding_matrix],
            input_length=self.dataset.MAX_SEQUENCE_LENGTH,
            trainable=False)

        sequence_input = Input(shape=(self.dataset.MAX_SEQUENCE_LENGTH, ),
                               dtype='int32')
        embedded_sequences = embedding_layer(sequence_input)
        lstm = LSTM(64, dropout=0.2, recurrent_dropout=0.2)(embedded_sequences)

        preds = Dense(self.dataset.category_size, activation='softmax')(lstm)
        model = Model(sequence_input, preds)
        model.compile(loss='categorical_crossentropy',
                      optimizer='adam',
                      metrics=['accuracy'])
        model.summary()
        early_stopping = EarlyStopping(monitor='val_loss',
                                       min_delta=0,
                                       patience=0,
                                       verbose=0,
                                       mode='auto')
        model.fit(self.dataset.X_train,
                  self.dataset.y_train,
                  batch_size=512,
                  epochs=10,
                  validation_data=(self.dataset.X_test, self.dataset.y_test),
                  callbacks=[early_stopping])
        self.model = model
コード例 #19
0
def clean_common_image():
    """
    清理相同的图片,以计算图片的md5值为准
    """
    for lists in os.listdir(image_path):
        game_id = lists
        path = os.path.join(image_path, game_id)
        # print
        # print game_id
        md5_dict = dict()
        if os.path.isdir(path):
            screen_path = os.path.join(path, "screen")
            screens = os.listdir(screen_path)
            for screen in screens:
                md5 = file_md5(screen_path, screen)
                if md5 in md5_dict:
                    md5_dict[md5] = md5_dict[md5] + "$#$" + screen
                else:
                    md5_dict[md5] = screen
            for key, value in md5_dict.iteritems():
                # print key, value
                if "$#$" in value:
                    for index, image in enumerate(value.split("$#$")):
                        if index == 0:
                            continue
                        # 移除图片
                        remove_image_path = os.path.join(screen_path, image)
                        logger.info("remove image index:%d, path: %s", index, remove_image_path)
                        os.remove(remove_image_path)
コード例 #20
0
ファイル: watcher.py プロジェクト: WilfMan/git_updater
def main():
    # subprocess.Popen(['export', 'DISPLAY=:0'])
    logger.info('check status')
    status = check_status(info)
    logger.info('status= %s' % status)

    logger.info('check %s server' % speech_server)
    f_stat = proc_exist(speech_server)
    if not f_stat:
        subprocess.Popen(run_speech_server.split(' '))
    logger.info('run notifar')
    if status == run:
        pid = get_pid(pidFile)
        subprocess.Popen('kill %s' % pid, shell=True)
        wr(info, stop)
        sys.exit(0)
    else:
        wr(info, run)

    while check_status(info) != stop:
        if os.path.exists(pidFile):
            pid = get_pid(pidFile)

            if pid_exists(pid):
                time.sleep(1)
                # print 1
                continue

        logger.info('no tartget procces  try restart')
        subprocess.Popen(command.split(' '))
        print 'Fire!!!'
        time.sleep(1)
コード例 #21
0
    def handle(self, handler_input):
        logger.info("HAN  FP_AnsweredRequestedQuestionsHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        correct = QuestionChecker.check_answer(handler_input)
        UserStats.update_player_stats(handler_input, correct)

        ms_congrats = CongratUtils.get_player_congrats(handler_input, 2)

        num_questions = attr.get('num_questions', '')
        ms_answered_all_questions = FPSpeech.get_ms_answered_all_questions(
            num_questions)

        prompt, reprompt = (HelpUtils.get_q_what_todo() for _ in range(2))
        prompt = CardFuncs.format_prompt(prompt)

        speech_list += Pauser.make_ms_pause_level_list(
            ms_congrats, 1, ms_answered_all_questions, 3, prompt)

        SessionStats.update_consecutive_correct(handler_input, correct)
        ModeStats.update_mode_stats(handler_input, correct)
        ModeStats.translate_mode_stats_to_sesh(handler_input)
        FreePlayAttr.set_attr_end_fp(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)

        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
コード例 #22
0
 def post(self, request):
     role = request.user.role
     if role == 3:
         form = ModerationForm(request.POST)
         if form.is_valid():
             text = clear_text(form.cleaned_data['text'])
             title = clear_text(form.cleaned_data['title'])
             user = request.user.id
             moderation = ModerationPost(title=title,
                                         text=text,
                                         moderation_status=user)
             moderation.save()
             logger.info(
                 f'{request.user.username} created the post that was sent to moderation'
             )
             return HttpResponseRedirect('/news')
         logger.warning(f'form by user {request.user.username} [NOT VALID]')
         return HttpResponse('[POST CREATE FORM NOT VALID]')
     elif role == 1 or 2:
         form = PostCreateForm(request.POST)
         if form.is_valid():
             text = clear_text(form.cleaned_data['text'])
             title = clear_text(form.cleaned_data['title'])
             user = User.objects.get(id=request.user.id)
             post = Post(title=title, text=text, user=user)
             post.save()
             return HttpResponseRedirect('/news')
         return HttpResponse('[POST CREATE FORM NOT VALID]')
     return HttpResponse('[ERROR]')
コード例 #23
0
    def handle(self, handler_input):
        logger.info("HAN  FP_CorrectAnswerHandler")
        speech_list = []

        player_obj = PlayerDict.load_player_obj(handler_input)
        UserStats.update_player_stats(handler_input,
                                      correct=True,
                                      player_obj=player_obj)

        ms_congrats = CongratUtils.get_answer_congrats(handler_input,
                                                       player_obj=player_obj)
        ms_question = FPQuestions.get_question(handler_input)
        reprompt = FPQuestions.get_rephrased_question(handler_input)

        logger.debug(ms_congrats)

        if ms_congrats != "":
            speech_list += Pauser.make_ms_pause_level_list(
                ms_congrats, 1, ms_question)
        else:
            speech_list.append(ms_question)

        SessionStats.update_consecutive_correct(handler_input, correct=True)
        ModeStats.update_mode_stats(handler_input, correct=True)

        logger.debug(speech_list)
        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
コード例 #24
0
    def handle(self, handler_input):
        logger.info("HAN  FP_WrongAnswerHandler")
        speech_list = []

        player_obj = PlayerDict.load_player_obj(handler_input)
        UserStats.update_player_stats(handler_input,
                                      correct=False,
                                      player_obj=player_obj)

        WrongAnswer.record_wrong_question(handler_input)
        ms_incorrect = IncorrectAnsUtils.get_buzz_and_incorrect()
        ms_retry_question = AllQuestionIntros.get_retry_question(handler_input)
        reprompt = GenQuestions.get_same_question(handler_input)

        speech_list += Pauser.make_ms_pause_level_list(ms_incorrect, 1,
                                                       ms_retry_question)

        SessionStats.update_consecutive_correct(handler_input, correct=False)
        ModeStats.update_mode_stats(handler_input, correct=False)

        logger.debug(speech_list)
        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
コード例 #25
0
ファイル: SendEmail.py プロジェクト: XuylZhang/vip10test
def sendEmail():
    sender = '*****@*****.**'
    receiver = '*****@*****.**'
    smtpdsever = 'smtp.163.com'
    username = '******'
    password = '******'
    t = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    subject = '自动化测试结果。。。' + t
    content = 'Python 自动化测试发邮件////。。。'

    msg = MIMEText(content, 'plain', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
    msg['From'] = sender
    msg['To'] = receiver

    try:
        s = smtplib.SMTP()
        s.connect(smtpdsever)
        s.login(username, password)
        s.sendmail(sender, receiver, msg.as_string())
    except Exception as msg:
        logger.info(f'邮件发送失败:{msg}')
    else:
        logger.info('邮件发送成功')
    finally:
        s.quit()
コード例 #26
0
    def handle(self, handler_input):
        logger.info("HAN  FP_SetNumberQuestionsHandler")
        speech_list = []

        FreePlayAttr.set_attr_free_play(
            handler_input)  # reset questions asked.
        num_questions = SlotUtils.get_slot_val_by_name(handler_input,
                                                       'num_questions')

        if num_questions is None:
            ms_can_set_questions = FPNumQuestions.get_ms_can_set_num_questions(
            )
            prompt, reprompt = (FPNumQuestions.get_q_num_questions()
                                for _ in range(2))
            speech_list += Pauser.make_ms_pause_level_list(
                ms_can_set_questions, 2, prompt)

        else:
            FreePlayAttr.set_attr_num_questions(handler_input, num_questions)

            ms_confirm = ConfirmUtils.get_random_confirmation(handler_input)
            ms_ask_num_questions = FPNumQuestions.get_ms_ask_num_questions(
                handler_input)
            prompt = FPPrompts.get_q_fp_setup_prompt(handler_input)
            reprompt = FPPrompts.get_q_fp_setup_reprompt(handler_input)

            speech_list += Pauser.make_ms_pause_level_list(
                ms_confirm, ms_ask_num_questions, 2, prompt)

        ModeStats.translate_mode_stats_to_sesh(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
コード例 #27
0
    def handle(self, handler_input):
        logger.info("HAN    RepeatHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        if 'recent_response' in attr:
            return RepeatUtils.get_recent_response(handler_input)


        ms_help = HelpUtils.get_ms_corresponding_help(handler_input)
        ms_prompt, reprompt = (
            HelpUtils.get_ms_corresponding_help(handler_input) for _ in range(2))
                
        speech_list.append( fallback.data.MS_FALLBACK)
        speech_list.append( Pauser.get_p_level(1))

        ## NOTE: This will need refinement if there are callbacks. 
        ## Develop relevant methods from FallbackUtils.
        speech_list.append( ms_help)
        speech_list.append( ms_prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (
            handler_input.response_builder
                .speak( speech)
                .ask( reprompt)
                .set_card( SimpleCard(
                    card_title, card_text))
                .response)
コード例 #28
0
def plot_mse(trn_file_name, test_file_name, min_lbda):
    """

    @param trn_file_name:
    @type trn_file_name:
    @param test_file_name:
    @type test_file_name:
    @param min_lbda:
    @type min_lbda:
    @return:
    @rtype:
    """
    # construct x axis
    lbda_lst = [i for i in range(min_lbda, 151)]
    # get train MSE and test MSE with different theta
    train_mse_dict, test_mse_dict = calculate_trn_test_mse(
        trn_file_name, test_file_name, lbda_lst)
    # construct y axis
    y_train_mse = list(train_mse_dict.values())
    y_test_mse = list(test_mse_dict.values())
    # plot theta and MSE
    fig = plt.figure()
    plt.plot(lbda_lst, y_train_mse, label='Train MSE')
    plt.plot(lbda_lst, y_test_mse, label='Test MSE')
    plt.legend(loc='best')
    plt.show()
    # then save image
    pic_name = 'tmp_res/{}_mse_lambda_from_{}'.format(trn_file_name, min_lbda)
    fig.savefig(pic_name + '.png')
    logger.info('{} is saved!'.format(pic_name))
コード例 #29
0
ファイル: steam_grid_updater.py プロジェクト: lutris/Ice
    def update_rom_artwork(self, user, rom, dry_run=False):
        shortcut = roms.rom_to_shortcut(rom)
        logger.debug("Updating image for %s (%s)" % (rom, shortcut))
        app_id = shortcuts.shortcut_app_id(shortcut)

        if grid.has_custom_image(user, app_id):
            existing_image = grid.get_custom_image(user, app_id)
            logger.debug(
                "Not looking for new images for %s, it already has a grid image (%s)"
                % (shortcut.name, existing_image)
            )
            return

        path = self.provider.image_for_rom(rom)

        if path is None:
            logger.info("No image found for `%s`" % shortcut.name)
            return

        if dry_run:
            logger.debug("Found image, but not setting because its a dry run")
            return

        logger.info("Found grid image for `%s`" % shortcut.name)
        grid.set_custom_image(user, app_id, path)
コード例 #30
0
ファイル: mc-mouse.py プロジェクト: calllivecn/mc-hangup
def hangup(kbm, args):

    logger.info("吃食物.")
    eatfood(kbm, args.food)

    try:
        while True:
            print("按CTRL+C结束。")
            logger.info("等待...")

            # 反挂机检测机制。
            #if args.ahd != 0:
            #    for _ in range(args.ahd):
            #        time.sleep(1)

            # 间隔 waiteat分钟吃食物
            time.sleep(args.waiteat * 60)

            logger.info("吃食物.")
            eatfood(kbm, args.food)

            if args.message:
                logger.info(f"发送挂机消息: {args.message}")
                __chat(kbm, args.message)

            if args.move:
                logger.info("随机移动.")
                __move(kbm)

    except KeyboardInterrupt:
        print()
コード例 #31
0
ファイル: initconfig.py プロジェクト: calllivecn/MCLauncher
    def select_version_id(self, version_id=None):
        """
        param: version_id 默认为None, version_id 为非None 时为创建MC 目录构造。
        """

        if version_id is None:
            vers = os.listdir(self.versions)

            if len(vers) == 0:
                logger.error("{} 没有游戏。".format(self.gameDir))
                sys.exit(1)
            else:
                logger.info("当前版本:{}".format(vers))
                vers.sort()
                self.version_id = vers[-1]
                logger.info("默认选择版本:{}".format(self.version_id))

                self.client_jar = joinpath(self.versions, self.version_id, self.version_id + ".jar")

                self.client_json = joinpath(self.versions, self.version_id, self.version_id + ".json")

                self.server_jar = joinpath(self.serverDir, "server-" + self.version_id + ".jar")
            
        else:
            
            self.version_id = version_id

            self.client_jar = joinpath(self.versions, self.version_id, self.version_id + ".jar")

            self.client_json = joinpath(self.versions, self.version_id, self.version_id + ".json")

            self.server_jar = joinpath(self.serverDir, "server-" + self.version_id + ".jar")
コード例 #32
0
def execute(pkg_name, cert_md5, file_md5, min_sdk, download_url, short_desc, file_size, ver_code, ver_name, detail_url, channel, apk_info):

    doc = get_game_info(pkg_name, detail_url)
    label_info, pkg_info = perpare_data(doc, download_url, file_size, ver_code, ver_name, channel, apk_info)
    pkg_info["signature_md5"] = cert_md5
    pkg_info["file_md5"] = file_md5
    pkg_info["min_sdk_version"] = min_sdk
    pkg_info["game_desc"] = pkg_info["game_desc"]
    #xiangxiaowei
    pkg_info["pkg_name"] = pkg_name
    pkg_info["gpu_vender"] = apk_info["gpu_vender"]
    pkg_info["update_desc"] = apk_info["update_desc"]
    pkg_info["ver_code_by_gg"] = apk_info["ggvercode"]
    pkg_info["save_user"] = apk_info["save_user"]
    pkg_info["ver_name"] = apk_info["ver_name"]

    label_info["short_desc"] = short_desc
    label_info["detail_desc"] = label_info["detail_desc"]
    label_info["save_user"] = apk_info["save_user"]

    if label_info and pkg_info:
        pkg_name = pkg_info["pkg_name"]

        # 记录游戏信息
        write_file(pkg_name, doc)

        # 插入google play游戏信息
        db.insert_label_info(label_info)
        db.insert_pkg_info(pkg_info)
        logger.info("insert game_id: %s, name: %s", label_info["game_id"], label_info["game_name"])
コード例 #33
0
 def __iter__(self) -> bytes:
     response = handle_request(self.request)
     status = response.status
     response_headers = response.headers
     self.start_response(status, response_headers)
     logger.info(f"{self.request.get_full_path()} "
                 f"{self.request.method} {status}")
     yield response.body
コード例 #34
0
ファイル: pull_all.py プロジェクト: WilfMan/git_updater
 def __enter__(self):
     if self.do_stash:
         log_.info('stashing  %s' % self.cur_branch)
         name = 'save stash in branch %s' % self.cur_branch
         subprocess.check_output(
             'cd %(project_dir)s && git stash save "%(msg)s"' % {
                 'project_dir': self.project_path, 'msg': name},
             shell=True)
コード例 #35
0
ファイル: controller.py プロジェクト: anthonyt/3ad
    def generate_plugin_vectors(self, plugins, file_name, file_key):
        """ Generate the vectors for each provided plugin in a thread.

        Immediately returns a deferred which will return a dict of vectors
        """
        logger.info('Generating plugin vectors for %r and %r', file_name, plugins)
        df = threads.deferToThread(
                self.blocking_generate_vectors,
                plugins, file_name, file_key
             )
        return df
コード例 #36
0
ファイル: controller.py プロジェクト: anthonyt/3ad
        def got_file(file, file_name):
            inner_df = defer.Deferred()

            if file is not None:
                # file already exists
                result_tuples[file_name] = (file, False)
            else:
                # make a new file!
                file = AudioFile(file_name, user_name=user_name)
                result_tuples[file_name] = (file, True)

                logger.info("Adding new Audio File: %r", file)

                # Take care of saving the file object, as well as creating
                # the file.vector and PluginOutput objects, all at once!
                inner_df.addCallback(self.update_file_vectors)

                # After the file has been saved, apply the tags to it!
                # TODO: we shouldn't get_tags for each file individually. Do it once, before saving any files.
                if tags:
                    def got_tags(tags):
                        # Make sure that each apply_tag_to_file call does not overlap
                        # FIXME: Not sure if we need this now that the network
                        #        is tolerant of packet loss.
                        def apply(value, file, tag):
                            logger.debug("Attempting to apply: %r to %r ", tag, file)
                            tag_df = self.model.apply_tag_to_file(file, tag)
                            return tag_df

                        df = defer.Deferred()
                        for t in tags:
                            df.addCallback(apply, file, t)
                        df.callback(None)
                        return df

                    def get_tags(val):
                        ta = TagAggregator(self, self.model, tags, True)
                        ta_df = ta.go()
                        return ta_df

                    inner_df.addCallback(get_tags)
                    inner_df.addCallback(got_tags)

                # Pass "file" to our first callback
                inner_df.callback(file)

                # inner_df will 'callback', as far as the calling function is
                # concerned, either after the file is saved, or after all tags
                # have been applied, depending on the presence of a tags list
                return inner_df
コード例 #37
0
ファイル: my_notify.py プロジェクト: WilfMan/git_updater
    def __init__(self):
        logger.info("start init")

        self.icon = None
        self.log = logger
        self.rg = re.compile("\[(?:\w)+/([A-Za-z0-9\._]+): behind (\d+)\]")
        self.opt_repository = []
        self.opt_branch = []
        self.opt_timeout = 60
        self.log.info("\n\nDaemon start\n\n")
        self.img_path = None
        self._running = 1
        self.nn = []
        self.datata = []
        self.config_parse()
        self.fire_notify("start")
コード例 #38
0
ファイル: gui.py プロジェクト: WilfMan/git_updater
def GUIrun(clean=True):
    try:
        t = time.time()
        n = 0
        while True:
            Run = IGuiCaller.get(0)
            try:
                n += 1
                t0 = time.time()
                Run()
                t0 = time.time() - t0
                if t0 > 0.1:
                    logging.info("Run=%r took %r", Run, t0)
            except Exception, E:
                logging.error("GUIrun/caller: %s\nRun = %r\nTraceback: %s", E, Run, traceback.format_exc())
            tt = time.time()
            if tt - t > 0.05:
                logging.error("GUIrun/caller: proceed %d for %r; left=%d", n, tt - t, IGuiCaller.qsize())
                break
    except Queue.Empty:
        pass
    try:
        t = time.time()
        n = 0
        while True:
            Run = IGuiIdleCaller.get(0)
            try:
                n += 1
                t0 = time.time()
                Run()
                t0 = time.time() - t0
                if t0 > 0.1:
                    logging.info("Run=%r took %r", Run, t0)
            except Exception, E:
                logging.error("GUIrun/idle: %s\nRun = %r\nTraceback: %s", E, Run, traceback.format_exc())
            tt = time.time()
            if tt - t > 0.05:
                logging.error("GUIrun/idle: proceed %d for %r; left=%d", n, tt - t, IGuiIdleCaller.qsize())
                break
    except Queue.Empty:
        pass
    if clean:
        with IdleCallerLock:
            IdleCaller[0] = IGuiCaller.qsize() > 0 or IGuiIdleCaller.qsize() > 0
            return IdleCaller[0]
コード例 #39
0
    def sync_roms_for_user(self, user, users_roms, consoles, dry_run=False):
        """
        This function takes care of syncing ROMs. After this function exits,
        Steam will contain only non-Ice shortcuts and the ROMs represented
        by `roms`.
        """
        # 'Unmanaged' is just the term I am using for shortcuts that the user has
        # added that Ice shouldn't delete. For example, something like a shortcut
        # to Plex would be 'Unmanaged'
        previous_managed_ids = self.managed_rom_archive.previous_managed_ids(user)
        logger.debug("Previous managed ids: %s" % previous_managed_ids)
        current_shortcuts = shortcuts.get_shortcuts(user)
        unmanaged_shortcuts = self.unmanaged_shortcuts(previous_managed_ids,
                                                       current_shortcuts,
                                                       consoles)
        logger.debug("Unmanaged shortcuts: %s" % unmanaged_shortcuts)
        current_ice_shortcuts = filter(
            lambda shortcut: shortcut not in unmanaged_shortcuts, current_shortcuts
        )
        logger.debug("Current Ice shortcuts: %s" % current_ice_shortcuts)
        # Generate a list of shortcuts out of our list of ROMs
        rom_shortcuts = map(roms.rom_to_shortcut, users_roms)
        # Calculate which ROMs were added and which were removed so we can inform
        # the user
        removed = self.removed_shortcuts(current_ice_shortcuts, rom_shortcuts)
        map(lambda shortcut: logger.info("Removing ROM: `%s`" % shortcut.name), removed)
        added = self.added_shortcuts(current_ice_shortcuts, rom_shortcuts)
        map(lambda shortcut: logger.info("Adding ROM: `%s`" % shortcut.name), added)

        # Set the updated shortcuts
        updated_shortcuts = unmanaged_shortcuts + rom_shortcuts
        logger.debug("Sync Result: %s" % updated_shortcuts)

        if dry_run:
            logger.debug("Not saving or updating history due to dry run")
            return

        logger.debug("Saving shortcuts")
        shortcuts.set_shortcuts(user, updated_shortcuts)

        # Update the archive
        new_managed_ids = map(shortcuts.shortcut_app_id, rom_shortcuts)
        logger.debug("Updating archive to ids: %s" % new_managed_ids)
        self.managed_rom_archive.set_managed_ids(user, new_managed_ids)
コード例 #40
0
def do_default_stuff(channel, name, html=''):
    print "do_default_stuff"
    logger.info("no found game(%s) on channel(%s)" % (name, channel))
コード例 #41
0
ファイル: my_notify.py プロジェクト: WilfMan/git_updater
    def get_full_path(*args):
        return os.path.join(os.path.dirname(__file__), *args)


if __name__ == "__main__":

    def proc_exist(name):
        try:
            process = subprocess.Popen(stdout=-1, args="ps x|grep %s|grep -v grep|grep -v Z" % name, shell=True)
            output, _ = process.communicate()
            process.poll()
            if output:
                return set(i.split()[0] for i in output.rstrip("\n").split("\n"))
            return set()
        except:
            return set()

    ppe = proc_exist(__file__)
    pid = {str(os.getpid())}
    if ppe - pid:
        logger.info("found %s process" % (ppe - pid))
        sys.exit(1)

    pidfile = tempfile.gettempdir() + "/daemonGitPushNotify.pid"
    pid = str(os.getpid())
    with open(pidfile, "w") as pf:
        pf.write("%s" % pid)
    bapp = BaseApp()
    bapp.say(["say_en", '"start service"'])
    bapp.run()
コード例 #42
0
ファイル: gitPushNotify.py プロジェクト: WilfMan/git_updater
def empty_cb(n):
    log_.info('closed notify msg')
    n.close()
コード例 #43
0
ファイル: my_notify.py プロジェクト: WilfMan/git_updater
 def close(*a, **kwargs):
     logger.info("close in myapp")
     subprocess.call(["python", "%s/watcher.py" % os.path.split(os.path.abspath(__file__))[0]])
コード例 #44
0
ファイル: pull_all.py プロジェクト: WilfMan/git_updater
def pull_all_branches(project_dir):
    log_.info('get task path: %s' % project_dir)
    try:
        raw_branches = subprocess.check_output(
            'cd %(project_dir)s && git fetch && git branch -vv|grep behind' % {'project_dir': project_dir}, shell=True)
        log_.info('raw_branches: %s' % raw_branches)
    except subprocess.CalledProcessError:
        raw_branches = ''
    if not raw_branches:
        log_.info('nothing pull dir:%s' % project_dir)
        return

    rr = re.compile('\[(?:\w)+/([A-Za-z0-9\._]+): behind (\d+)\]')

    branches = [rr.search(i).group(1) for i in raw_branches.split('\n') if rr.search(i)]
    if branches:
        log_.info('branches: %s' % branches)
        status = subprocess.check_output('cd %(project_dir)s && git status' % {'project_dir': project_dir},
                                         shell=True)
        log_.info('status: %s' % status)
        for branch in branches:
            with Stash(status, project_dir, branch):
                s = subprocess.check_output(
                    'cd %(project_dir)s && git checkout %(branch)s && git pull' % {
                        'project_dir': project_dir, 'branch': branch},
                    shell=True)
                log_.info('pull: %s' % s)
    else:
        log_.info('branches from regexp is none')