def verify():
    # webhook verification
    if request.args.get('hub.mode') == 'subscribe' and request.args.get('hub.challenge'):
        if not request.args.get('hub.verify_token') == Config.VERIFY_TOKEN:
            logger.error("Verification missmatch") ### ERROR ###
            return 'Verification token missmatch', 403
        logger.info("correct hub challenge") ### info ###
        return request.args['hub.challenge'], 200
    return 'verification token', 200
def msg_action():
    msg_data = request.get_data()
    for sender, message, payload in get_msg_data(msg_data):
        ln = len(message)
        if ln>400:
            userr = User.query.filter_by(u_mess_id=sender).first()
            if userr.u_lang=="pl":
                post_msg(sender, "Nie rob", qck_dict["Menu_pl"])
            else:
                post_msg(sender, "Just dont", qck_dict["Menu_en"])
            logger.error("ATTACK: %s, len of msg: %d" %(sender, ln))
            return "ok", 200

        else:
            logger.info("for loop Incoming from %s: %s - and payload: %s" %(sender, message, payload)) ### DEBUG ###
            messg, qck = handle_data(sender, message, payload) ### handle data musi zwracac rozne ###
            logger.debug("return: msg: %s, qck[0][title]: %s" %(messg, qck[0]["title"]))
            
            if messg==None or qck==None:
                logger.error("some fc has err check prev logs to find it, it returns None!!")
                messg = "NULL"
            

            #####   HANDLING LONG MESSAGES   #####
            if len(messg)>=320:
                messages = messg.split("\n")
                msg = ""
                bck = ""
                err_stop = len(messages)
                count = 0
                for message_ in messages:
                    if count-3<err_stop:
                        count += 1
                        msg += message_+"\n"
                        if len(msg)>=320:
                            post_msg(sender, bck, qck)
                            msg = message_+"\n"
                            bck = msg
                        else:
                            if len(msg)>300:
                                post_msg(sender, msg, qck)
                                bck = ""
                                msg = ""
                            else:
                                bck = msg
                    else:
                        logger.error("Message over 320, split not working properly")
                        logger.error("str(messages): "+str(messages))
                        post_msg(sender, "ERROR", qck)
                        return  "ok", 200
                post_msg(sender, msg, qck)
                ### END      HANDLING LONG MESSAGES      END ###

            else:
                post_msg(sender, messg, qck)
        return "ok", 200
Exemple #3
0
def db_update(all_sts_ls):
    """Update databse, as input take double nested list of stats"""
    rtn_change_id = []
    logger.debug(str(len(all_sts_ls)))
    for country in all_sts_ls:
        ctry = search(country[1])
        if ctry == None:
            logger.info("NEW COUNTRY:" + country[1])
            ctry = Country(c_pos=country[0], c_name = country[1], c_name_pl=country[1], c_ill_sum = country[2], c_inf_tdy = country[3],
                            c_dead = country[4], c_deaths_tdy = country[5], c_recover = country[6], c_curr_cases = country[7],
                            c_crit_cases = country[8], c_case_1m = country[9], c_dead_1m = country[10])
            db.session.add(ctry)
        else:
            logger.debug("%d, %s" %(ctry.c_id, ctry.c_name))
            chng = ctry.update(country[0], country[2], country[3], country[4], country[5], country[6], country[8], country[9], country[10], country[11])
            if chng:
                rtn_change_id.append(ctry.c_id)
    db.session.commit()
    return rtn_change_id
def command(text, usr):
    cmd = text[0:4].lower()
    if " " in text:
        atr = text[5:]
    else:
        atr = text[4:]
    lng = usr.u_lang
    if cmd in command_ls:
        if cmd == "foll":
            ctry_to_flw = re.split(",", atr)
            for j in ctry_to_flw:
                cntry = search(j)
                if cntry==None:
                    return info_txt["Cmd_wrong_atr_"+lng], qck_dict["Info_"+lng]
                logger.info("%s following %s" %(usr.u_mess_id, cntry.c_name)) ### DEBUG ###
                logger.debug("cmd==unfl:"+cntry.c_name)
                usr.follow_c(cntry)
            db.session.commit()
            return info_txt["Succ_folw_c_"+lng], qck_dict["Follow_un_"+lng]

        elif cmd == "unfl":
            ctry_to_unfw_str = re.split(",", atr)
            logger.debug("unfl: "+str(ctry_to_unfw_str))
            for j in ctry_to_unfw_str:
                cntry = search(j)
                if cntry==None:
                    return info_txt["Cmd_wrong_atr_"+lng], qck_dict["Info_"+lng]

                logger.info("%s unfollowing %s" %(usr.u_mess_id, cntry.c_name))
                logger.debug("cmd==unfl:"+cntry.c_name)
                usr.unfollow_c(cntry)
            db.session.commit()
            return info_txt["Succ_unfw_c_"+lng], qck_dict["Follow_un_"+lng]


        # oraz dodac do functions.command_ls
        #elif cmd=="nowa_comenda":
        #   to costam 

    else:
        return info_txt["Wrong_cmd_"+lng], qck_dict["Menu_"+lng]
def info_fc_time():
    data = open("/var/www/kwasny.yao.cl/public_html/mess2/mess2/app/file.pckl",
                "rb")
    try:
        ls = load(data)
    except:
        ls = []
    data.close()
    data = open("/var/www/kwasny.yao.cl/public_html/mess2/mess2/app/file.pckl",
                "wb")
    dump([], data)
    data.close()
    logger.info("Since last time changed: " + str(ls))
    for c_id in ls:
        country = search(c_id)
        for usr in country.followers.all():
            if usr.u_foll_type == "time":
                logger.debug("sent TIME class update to: %s, country: %s" %
                             (usr.u_mess_id, country.c_name))
                post_msg(usr.u_mess_id,
                         Country_info(country.info_ls(), usr.u_lang),
                         fast(usr))
Exemple #6
0
            logger.info("NEW COUNTRY:" + country[1])
            ctry = Country(c_pos=country[0], c_name = country[1], c_name_pl=country[1], c_ill_sum = country[2], c_inf_tdy = country[3],
                            c_dead = country[4], c_deaths_tdy = country[5], c_recover = country[6], c_curr_cases = country[7],
                            c_crit_cases = country[8], c_case_1m = country[9], c_dead_1m = country[10])
            db.session.add(ctry)
        else:
            logger.debug("%d, %s" %(ctry.c_id, ctry.c_name))
            chng = ctry.update(country[0], country[2], country[3], country[4], country[5], country[6], country[8], country[9], country[10], country[11])
            if chng:
                rtn_change_id.append(ctry.c_id)
    db.session.commit()
    return rtn_change_id

if __name__ == "__main__":
    chng = db_update(stats_ls())
    logger.info("chng: " + str(chng))
    if chng!=[]:
        from subs import info_fc_chng
        info_fc_chng(chng)
    chng_file = open("/var/www/kwasny.yao.cl/public_html/mess2/mess2/app/file.pckl", "rb")
    try:
        file_ls = load(chng_file)
    except:
        file_ls = []
    chng_file.close()
    
    if not file_ls==chng:
        for c_id in chng:
            if not c_id in file_ls:
                file_ls.append(c_id)
        logger.info("chng file_ls after sum: " + str(file_ls))