Пример #1
0
    def gaia_post(self, queId, question, sess_id):
        string = utils.remove_html_tags(utils.BotMessages(id=7).get_message())
        message = f"<b>{string}</b>"
        voice = utils.zamol_download(url=question)
        payload = self.bot.send_audio(chat_id=configs.GROUPID,
                                      audio=open(voice, 'rb'),
                                      caption=emoji.emojize(message,
                                                            use_aliases=True),
                                      parse_mode='html')
        remove(voice)
        messageId = payload.message_id
        print("MESSAGE ID##########", messageId)
        sql.set_gaia_messageId(messageId=messageId, queId=queId)
        sql.create_correct(messageId=messageId)

        # sleep for 49 seconds then post answer
        local_datetime = datetime.datetime.now()
        strppp = local_datetime.astimezone(pytz.UTC)
        new_time = strppp + datetime.timedelta(seconds=int(43))
        answer_time = new_time.strftime("%Y-%m-%d %H:%M:%S")
        sched.add_job(utils.Notify().post_gaia_answer,
                      'date',
                      run_date=answer_time,
                      args=[messageId, sess_id],
                      id=str(messageId))
        print("post answer", answer_time)
        utils.mr_logger(f"Posting the answer at :{answer_time}")
Пример #2
0
    def nuwa_post(self, question, sess_id, queId):
        string = utils.remove_html_tags(utils.BotMessages(id=10).get_message())
        message = f"<b>{string}</b>\n\n<i>{question}</i>"

        payload = self.bot.send_message(chat_id=configs.GROUPID,
                                        text=emoji.emojize(message,
                                                           use_aliases=True),
                                        parse_mode='html')
        messageId = payload.message_id
        print("posted mess", messageId)
        sql.set_nuwa_messageId(messageId=messageId, queId=queId)
        sql.create_correct(messageId=messageId)

        # sleep for 49 seconds then post answer
        local_datetime = datetime.datetime.now()
        strppp = local_datetime.astimezone(pytz.UTC)
        new_time = strppp + datetime.timedelta(seconds=int(35))
        answer_time = new_time.strftime("%Y-%m-%d %H:%M:%S")
        sched.add_job(utils.Notify().post_nuwa_answer,
                      'date',
                      run_date=answer_time,
                      args=[messageId, sess_id],
                      id=str(messageId))
        print("post answer", answer_time)
        utils.mr_logger(f"Posting the answer at :{answer_time}")
Пример #3
0
    def odin_post(self, queId, sess_id):
        key_main = [[
            InlineKeyboardButton(emoji.emojize(":see_no_evil:",
                                               use_aliases=True),
                                 callback_data=f"odin+{queId}")
        ]]
        main_markup = InlineKeyboardMarkup(key_main)
        string = utils.remove_html_tags(utils.BotMessages(id=9).get_message())
        message = f"<b>{string}</b>"

        payload = self.bot.send_message(chat_id=configs.GROUPID,
                                        text=emoji.emojize(message,
                                                           use_aliases=True),
                                        reply_markup=main_markup,
                                        parse_mode='html')
        messageId = payload.message_id
        print("posted mess", messageId)
        sql.set_odin_messageId(messageId=messageId, queId=queId)
        sql.create_correct(messageId=messageId)

        # sleep for 49 seconds then post answer
        local_datetime = datetime.datetime.now()
        strppp = local_datetime.astimezone(pytz.UTC)
        new_time = strppp + datetime.timedelta(seconds=int(30))
        answer_time = new_time.strftime("%Y-%m-%d %H:%M:%S")
        sched.add_job(utils.Notify().post_odin_answer,
                      'date',
                      run_date=answer_time,
                      args=[messageId, sess_id],
                      id=str(messageId))
        print("post answer", answer_time)
        utils.mr_logger(f"Posting the answer at :{answer_time}")
Пример #4
0
 def wala_post_main(self, question):
     string = utils.remove_html_tags(
         utils.BotMessages(id=14).get_message()).split('.')
     fmt = ".\n".join(string)
     message = f"<b>{fmt}</b>\n\n{question}"
     payload = self.bot.send_message(chat_id=configs.GROUPID,
                                     text=emoji.emojize(message,
                                                        use_aliases=True),
                                     parse_mode='html')
     messageId = payload.message_id
     local_datetime = datetime.datetime.now()
     strppp = local_datetime.astimezone(pytz.UTC)
     new_time = strppp + datetime.timedelta(minutes=int(3))
     delete_time = new_time.strftime("%Y-%m-%d %H:%M:%S")
     sched.add_job(utils.Notify().wala_delete_main,
                   'date',
                   run_date=delete_time,
                   args=[messageId],
                   id=str(messageId))
     print("delete answer", delete_time)
     utils.mr_logger(f"deleting the main question at :{delete_time}")
Пример #5
0
    def kadlu_post(self, queId, question, pick, sess_id):
        # string = utils.remove_html_tags(utils.BotMessages(id=2).get_message())
        # message = f"<b>{string}</b>\n\n<i>{question}</i>"
        answer = pick[0]

        random.shuffle(pick)
        correct = pick.index(answer)
        payload = self.bot.send_poll(chat_id=configs.GROUPID,
                                     question=question,
                                     options=pick,
                                     is_anonymous=False,
                                     type=Poll.QUIZ,
                                     correct_option_id=correct)

        message_id = payload.message_id
        poll_id = payload.poll.id
        correct_id = payload.poll.correct_option_id
        print("posted mess", message_id)
        sql.set_kadlu_messageId_pollId_correctId(messageId=message_id,
                                                 pollId=poll_id,
                                                 correctId=correct_id,
                                                 queId=queId)
        # sql.create_correct(messageId=poll_id)

        # sleep for 49 seconds then post answer
        local_datetime = datetime.datetime.now()
        strppp = local_datetime.astimezone(pytz.UTC)
        new_time = strppp + datetime.timedelta(seconds=int(18))
        answer_time = new_time.strftime("%Y-%m-%d %H:%M:%S")
        sched.add_job(utils.Notify().post_kadlu_answer,
                      'date',
                      run_date=answer_time,
                      args=[message_id, sess_id],
                      id=str(poll_id))
        print("post answer", answer_time)
        utils.mr_logger(f"Stopping the quiz at :{answer_time}")
Пример #6
0
    def seshat_post(self, queId, question, instruction, gif, sess_id):
        string = utils.remove_html_tags(utils.BotMessages(id=15).get_message())
        message = f"<b>{instruction}\n<i>{question}</i>\n\n{string}</b>"

        if "gif" in gif:
            utils.mr_logger(f"posting gif: {gif}")
            payload = self.bot.send_document(chat_id=configs.GROUPID,
                                             document=gif,
                                             caption=emoji.emojize(
                                                 message, use_aliases=True),
                                             parse_mode=ParseMode.HTML)
        else:
            utils.mr_logger(f"posting photo: {gif}")
            payload = self.bot.send_photo(chat_id=configs.GROUPID,
                                          photo=gif,
                                          caption=emoji.emojize(
                                              message, use_aliases=True),
                                          parse_mode=ParseMode.HTML)

        messageId = payload.message_id
        print("posted mess", messageId)
        sql.set_seshat_messageId(messageId=messageId, queId=queId)
        sql.create_correct(messageId=messageId)

        # sleep for 49 seconds then post answer
        local_datetime = datetime.datetime.now()
        strppp = local_datetime.astimezone(pytz.UTC)
        new_time = strppp + datetime.timedelta(seconds=int(20))
        answer_time = new_time.strftime("%Y-%m-%d %H:%M:%S")
        sched.add_job(utils.Notify().post_seshat_answer,
                      'date',
                      run_date=answer_time,
                      args=[messageId, sess_id],
                      id=str(messageId))
        print("post answer", answer_time)
        utils.mr_logger(f"Posting the answer at :{answer_time}")
N = len(labels)
ind = np.arange(N)
width = 0.35

ax1 = fig.add_axes(rect_kilzone, facecolor='#f6f6f6')
ax1.bar(ind, values, width, color='b', bottom=0)
ax1.set_ylabel('ATR Value')
ax1.set_title('Killzones', fontsize=14)
ax1.set_xticks(ind)
ax1.set_xticklabels(labels,
                    rotation=90,
                    fontsize=11,
                    stretch='ultra-condensed')

###############################

im = Image.open(LOGO_PATH)
fig.figimage(im, 50, (fig.bbox.ymax - im.size[1]) - 10)

plt.savefig(FILENAME)

n = utils.Notify()
n.telegram({
    'chat_id': '@whalepoolbtcfeed',
    'message': 'Recent bitcoin volatility periods',
    'picture': FILENAME
})
print('Saved: ' + FILENAME)
os.remove(FILENAME)
sys.exit()
Пример #8
0
def fetchSessions():
    sessions = utils.Sessions(language=configs.LANGUAGE).get_sessions()
    for session in sessions:
        # check if session is already save in the db
        sess_check = sql.check_session(session['id'])
        if sess_check==False:
            sess_id = session['id']
            group_language = session['language']
            bot = session['type']
            lesson = session['session']
            each_time = session['each_time']
            total_time = session['total_time']
            start_time = session['start_time'].replace('/', '-')
            qlevel = session['level']
            questions = session['questions']
            session_name = session['session_name']
            status = session['status']
            """Save session"""
            print(f"{session_name} saved")
            print('start time', start_time)
            sql.save_sessions(sess_id, group_language, bot, lesson, each_time, total_time, start_time, qlevel,
                              questions, session_name, status)
            # queue the notification a minute earlier
            amin_time = utils.liner.session_time(start_time=start_time, period=60)
            after_time = utils.liner.post_time(start_time=start_time, period=60)

            sched.add_job(utils.Notify().session_start, 'date', run_date=amin_time,
                          args=[bot, questions, qlevel, session_name, total_time])
            sched.add_job(utils.Notify().session_ongoing, 'date', run_date=after_time,
                          args=[bot, questions, qlevel, session_name, total_time])
            print("starting session", amin_time)
            utils.mr_logger(f"starting session{amin_time}")
            # sched.add_job(utils.Notify().session_start, 'date', run_date='2020-04-01 23:21:10',
            #                              args=[session_name, questions, total_time])
            # get apollo questions
            if bot == 'Apollo':
                apollos = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 10
                for apollo in apollos:
                    apollo_id = apollo['id']
                    apollo_language = apollo['language']
                    apollo_question = apollo['question']
                    apollo_answer = apollo['answer']
                    apollo_level = apollo['level']
                    sql.save_apollo(sess_id=sess_id, quesId=apollo_id, question=apollo_question, answer=apollo_answer,
                                    qlevel=apollo_level, qlanguage=apollo_language)
                    print(f"saving apollo {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    sched.add_job(utils.Notify().apollo_post, 'date', run_date=net_time,
                                  args=[apollo_id, apollo_question, sess_id], id=str(apollo_id))

                print(f'Finished saving apollo {session_name} session')
            elif bot == 'Seshat':
                seshats = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 5
                for seshat in seshats:
                    seshat_id = seshat['id']
                    seshat_language = seshat['language']
                    seshat_question = seshat['question']
                    seshat_answer = seshat['answer']
                    seshat_instruction = seshat['instruction']
                    seshat_level = seshat['level']
                    seshat_gif = seshat['img']
                    sql.save_seshat(sess_id=sess_id, quesId=seshat_id, question=seshat_question, answer=seshat_answer,
                                    instruction=seshat_instruction, gif=seshat_gif, qlevel=seshat_level,
                                    qlanguage=seshat_language)
                    print(f"saving seshat {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    sched.add_job(utils.Notify().seshat_post, 'date', run_date=net_time,
                                  args=[seshat_id, seshat_question, seshat_instruction, seshat_gif, sess_id],
                                  id=str(seshat_id))
            elif bot == 'Tyche':
                tyches = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 5
                for tyche in tyches:
                    tyche_id = tyche['id']
                    tyche_language = tyche['language']
                    tyche_question = tyche['hint']
                    tyche_answer = tyche['question']
                    tyche_level = tyche['level']
                    sql.save_tyche(sess_id=sess_id, quesId=tyche_id, question=tyche_question, answer=tyche_answer,
                                   qlevel=tyche_level, qlanguage=tyche_language)
                    print(f"saving tyche {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    sched.add_job(utils.Notify().tyche_post, 'date', run_date=net_time,
                                  args=[tyche_id, tyche_question, sess_id], id=str(tyche_id))

                print(f'Finished saving Tyche {session_name} session')
            elif bot == 'Leizi':
                leizis = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 5
                for leizi in leizis:
                    leizi_id = leizi['id']
                    leizi_language = leizi['language']
                    leizi_question = leizi['question']
                    leizi_answer1 = leizi['answer1']
                    leizi_answer2 = leizi['answer2']
                    leizi_instruction = leizi['instruction']
                    leizi_level = leizi['level']
                    sql.save_leizi(sess_id=sess_id, quesId=leizi_id, question=leizi_question, answer1=leizi_answer1,
                                   answer2=leizi_answer2, instruction=leizi_instruction,
                                   qlevel=leizi_level, qlanguage=leizi_language)
                    print(f"saving leizi {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    sched.add_job(utils.Notify().leizi_post, 'date', run_date=net_time,
                                  args=[leizi_id, leizi_question, leizi_instruction, sess_id], id=str(leizi_id))
            elif bot == 'Odin':
                odins = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 10
                for odin in odins:
                    odin_id = odin['id']
                    odin_language = odin['language']
                    odin_question = odin['question']
                    odin_meaning = odin['meaning']
                    odin_level = odin['level']
                    sql.save_odin(sess_id=sess_id, quesId=odin_id, question=odin_question, meaning=odin_meaning,
                                  qlevel=odin_level,
                                  qlanguage=odin_language)
                    print(f"saving odin {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    sched.add_job(utils.Notify().odin_post, 'date', run_date=net_time,
                                  args=[odin_id, sess_id], id=str(odin_id))
            elif bot == 'Zamo':
                zamos = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 10
                for zamo in zamos:
                    zamo_id = zamo['id']
                    zamo_language = zamo['language']
                    zamo_question = zamo['path']
                    zamo_answer = zamo['question']
                    zamo_level = zamo['level']
                    sql.save_zamo(sess_id=sess_id, quesId=zamo_id, answer=zamo_answer, question=zamo_question,
                                  qlevel=zamo_level, qlanguage=zamo_language)
                    print(f"saving zamo {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    sched.add_job(utils.Notify().zamo_post, 'date', run_date=net_time,
                                  args=[zamo_id, zamo_question, sess_id], id=str(zamo_id))
            elif bot == 'Africa':
                africas = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 15
                for africa in africas:
                    africa_id = africa['id']
                    africa_language = africa['language']
                    africa_question = africa['question']
                    africa_answer = africa['answer1']
                    africa_answer1 = africa['answer1']
                    africa_answer2 = africa['answer2']
                    africa_answer3 = africa['answer3']
                    africa_answer4 = africa['answer4']
                    africa_level = africa['level']
                    pick = [africa_answer1, africa_answer2, africa_answer3, africa_answer4]
                    print(pick, type(pick))
                    sql.save_africa(sess_id=sess_id, quesId=africa_id, question=africa_question, answer=africa_answer,
                                    answer1=africa_answer1, answer2=africa_answer2, answer3=africa_answer3,
                                    answer4=africa_answer4,
                                    qlevel=africa_level, qlanguage=africa_language)
                    print(f"saving africa {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    sched.add_job(utils.Notify().africa_post, 'date', run_date=net_time,
                                  args=[africa_id, africa_question, pick, sess_id], id=str(africa_id))
            elif bot == 'Wala':
                main_mess = {"main": 123}
                walas = utils.Questions(id=int(sess_id)).get_questions()
                wala_time = utils.liner.post_time(start_time=start_time, period=int(182))
                wala_time = wala_time.strftime("%Y-%m-%d %H:%M")

                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 15
                for wala in walas:
                    wala_id = wala['id']
                    wala_language = wala['language']
                    wala_main_question = wala['main_question']
                    wala_question = wala['sub_question']
                    wala_answer = wala['answer1']
                    wala_answer1 = wala['answer1']
                    wala_answer2 = wala['answer2']
                    wala_answer3 = wala['answer3']
                    wala_answer4 = wala['answer4']
                    wala_level = 'Elementary'
                    main_mess["main"] = wala_main_question
                    pick = [wala_answer1, wala_answer2, wala_answer3, wala_answer4]
                    # sess_id, quesId, main_question, question, answer, answer1, answer2, answer3, answer4, qlevel, qlanguage
                    sql.save_wala(sess_id=sess_id, quesId=wala_id, main_question=wala_main_question,
                                  question=wala_question,
                                  answer=wala_answer, answer1=wala_answer1, answer2=wala_answer2, answer3=wala_answer3,
                                  answer4=wala_answer4, qlevel=wala_level, qlanguage=wala_language)

                    # wait for how long before posting
                    stime += int(post_time)
                    # convert to date type
                    net_time = utils.liner.post_time(start_time=wala_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    try:
                        sched.add_job(utils.Notify().wala_post, 'date', run_date=net_time,
                                      args=[wala_id, wala_question, pick, sess_id], id=str(wala_id))
                    except:
                        pass

                main_time = utils.liner.post_time(start_time=start_time, period=int(1))
                sched.add_job(utils.Notify().wala_post_main, 'date', run_date=main_time,
                              args=[main_mess['main']])

            elif bot == 'Kadlu':
                main_mess = {"kadlu": 123}
                kadlus = utils.Questions(id=int(sess_id)).get_questions()
                kadlu_time = utils.liner.post_time(start_time=start_time, period=int(122))
                kadlu_time = kadlu_time.strftime("%Y-%m-%d %H:%M")

                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 15
                for kadlu in kadlus:
                    # print(kadlu)
                    kadlu_id = kadlu['id']
                    kadlu_language = kadlu['language']
                    kadlu_main_question = kadlu['path']
                    kadlu_question = kadlu['sub_question']
                    kadlu_answer = kadlu['answer1']
                    kadlu_answer1 = kadlu['answer1']
                    kadlu_answer2 = kadlu['answer2']
                    kadlu_answer3 = kadlu['answer3']
                    kadlu_answer4 = kadlu['answer4']
                    kadlu_level = 'Elementary'
                    main_mess["kadlu"] = kadlu_main_question
                    pick = [kadlu_answer1, kadlu_answer2, kadlu_answer3, kadlu_answer4]
                    sql.save_kadlu(sess_id=sess_id, quesId=kadlu_id, main_question=kadlu_main_question,
                                   question=kadlu_question,
                                   answer=kadlu_answer, answer1=kadlu_answer1, answer2=kadlu_answer2,
                                   answer3=kadlu_answer3,
                                   answer4=kadlu_answer4, qlevel=kadlu_level, qlanguage=kadlu_language)
                    # wait for how long before posting
                    stime += int(post_time)
                    # convert to date type
                    net_time = utils.liner.post_time(start_time=kadlu_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)
                    try:
                        sched.add_job(utils.Notify().kadlu_post, 'date', run_date=net_time,
                                      args=[kadlu_id, kadlu_question, pick, sess_id], id=str(kadlu_id))
                    except:
                        pass

                main_time = utils.liner.post_time(start_time=start_time, period=int(1))
                sched.add_job(utils.Notify().kadlu_post_main, 'date', run_date=main_time,
                              args=[main_mess['kadlu']])

            elif bot == 'Nuwa':
                nuwas = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 20
                for nuwa in nuwas:
                    nuwa_id = nuwa['id']
                    nuwa_language = nuwa['language']
                    nuwa_question = nuwa['question']
                    nuwa_level = nuwa['level']
                    # utils.mr_logger(nuwa)
                    sql.save_nuwa(sess_id=sess_id, quesId=nuwa_id, question=nuwa_question,
                                    qlevel=nuwa_level, qlanguage=nuwa_language)
                    print(f"saving nuwa {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)

                    sched.add_job(utils.Notify().nuwa_post, 'date', run_date=net_time,
                                  args=[nuwa_question,sess_id,nuwa_id ], id=str(nuwa_id))

            elif bot == 'Gaia':
                gaias = utils.Questions(id=int(sess_id)).get_questions()
                stime = 0
                # post every minute 50+10 seconds
                post_time = int(each_time) + 25
                for gaia in gaias:
                    gaia_id = gaia['id']
                    gaia_language = gaia['language']
                    gaia_answer = gaia['question']
                    gaia_level = gaia['level']
                    gaia_question = gaia['path']
                    sql.save_gaia(sess_id=sess_id, quesId=gaia_id,answer=gaia_answer ,question=gaia_question,
                                    qlevel=gaia_level, qlanguage=gaia_language)
                    print(f"saving gaia {session_name} questions")
                    stime += int(post_time)
                    net_time = utils.liner.post_time(start_time=start_time, period=int(stime))
                    print("start time", stime)
                    print("actual start", net_time)

                    sched.add_job(utils.Notify().gaia_post, 'date', run_date=net_time,
                                  args=[gaia_id,gaia_question,sess_id ], id=str(gaia_id))