def superpower_countdown_calc():

    ist = pytz.timezone("Asia/Kolkata")

    # Current time in IST
    now = datetime.now(ist)

    # Dec 31 in IST
    superpower_day = datetime(year=2020, month=1, day=1, hour=0, minute=0, second=0)
    superpower_day = ist.localize(superpower_day)

    # Get timedelta
    td = superpower_day - now

    if td.total_seconds() > 0:
        response = (
            "🇮🇳🙏 Time Until Super Power™️: "
            + util.pretty_time_delta(td.total_seconds())
            + " 🙏🇮🇳"
        )
    else:
        td = now - superpower_day
        response = (
            "🇮🇳🙏 WE INVANT SUPER POWER 🙏🇮🇳 \n Time Since: "
            + util.pretty_time_delta(td.total_seconds())
        )

    return response
Exemple #2
0
def generate_pretty_roll(roll):

    pretty_roll = None

    victim = dao.get_bakchod_by_id(roll["victim"])

    try:

        if roll["winrar"] is None:

            pretty_roll = "Roll a {} to {} {}!".format(
                roll["roll_number"],
                pretty_roll_rule(roll["rule"]),
                util.extract_pretty_name_from_bakchod(victim),
            )

        else:

            winrar = dao.get_bakchod_by_id(roll["winrar"])

            try:
                roll_expiry = ciso8601.parse_datetime(roll["expiry"])
            except Exception as e:
                roll_expiry = roll["expiry"]

            now = datetime.datetime.now()
            td = roll_expiry - now

            if roll["rule"] == "kick_user":
                pretty_roll = "{} won by rolling a {}! {} has been kicked from this group!".format(
                    util.extract_pretty_name_from_bakchod(winrar),
                    roll["roll_number"],
                    util.extract_pretty_name_from_bakchod(victim),
                )
            else:
                pretty_roll = "{} won by rolling a {}! {} is now {} for {}".format(
                    util.extract_pretty_name_from_bakchod(winrar),
                    roll["roll_number"],
                    util.extract_pretty_name_from_bakchod(victim),
                    pretty_roll_rule(roll["rule"]),
                    util.pretty_time_delta(td.total_seconds()),
                )

    except Exception as e:
        logger.error(
            "Caught Error in roll.generate_pretty_roll - {} \n {}",
            e,
            traceback.format_exc(),
        )

    return pretty_roll
Exemple #3
0
def superpower_countdown_calc():

    ist = pytz.timezone("Asia/Kolkata")

    # Current time in IST
    now = datetime.now(ist)

    # Dec 31 in IST
    superpower_day = datetime(year=2020,
                              month=1,
                              day=1,
                              hour=0,
                              minute=0,
                              second=0)
    superpower_day = ist.localize(superpower_day)

    # Get timedelta
    td = superpower_day - now
    pretty_td = util.pretty_time_delta(td.total_seconds())

    return (pretty_td)
Exemple #4
0
def handle(update, context):

    try:

        util.log_chat("webm", update)

        document = update.message.document

        # return if the document isn't a webm
        if not document.file_name.endswith(".webm"):
            return

        try:

            # Count time taken for webm conversion
            time_start = datetime.datetime.now()

            # Download the webm file
            logger.info("[webm] Starting webm download - " +
                        str(document.file_id) + ".webm")
            webm_file = context.bot.get_file(document.file_id)
            webm_file.download(WEBM_RESOURCES_DIR + str(document.file_id) +
                               ".webm")
            logger.info("[webm] Finished downloading webm - " +
                        str(document.file_id) + ".webm")

            # Webm to mp4 conversion via ffmpeg
            logger.info("[webm] Starting webm conversion with ffmpeg - " +
                        str(document.file_id) + ".webm")
            ffmpeg_conversion = subprocess.run([
                "ffmpeg",
                "-i",
                WEBM_RESOURCES_DIR + str(document.file_id) + ".webm",
                WEBM_RESOURCES_DIR + str(document.file_id) + ".mp4",
            ])

            if ffmpeg_conversion.returncode != 0:
                logger.error(
                    "[webm] ffmpeg conversion had a non-zero return code! webm={} ffmpeg_conversion={}",
                    str(document.file_id),
                    ffmpeg_conversion,
                )
                update.message.reply_text(
                    text="(。•́︿•̀。) webm conversion failed (。•́︿•̀。)")
                return

            # Calculate time taken to convert
            time_end = datetime.datetime.now()
            diff = time_end - time_start
            pretty_diff = util.pretty_time_delta(diff.seconds)

            logger.info(
                "[webm] ffmpeg conversion complete! webm={} time_taken={}",
                str(document.file_id),
                pretty_diff,
            )

            original_sender = util.extract_pretty_name_from_tg_user(
                update.message.from_user)

            caption = random_webm_caption(original_sender, pretty_diff)

            logger.info(
                "[webm] sending converted video webm={} caption={}",
                str(document.file_id),
                caption,
            )
            context.bot.send_video(
                chat_id=update.message.chat_id,
                video=open(WEBM_RESOURCES_DIR + str(document.file_id) + ".mp4",
                           "rb"),
                timeout=5000,
                caption=caption,
            )

            delete_file(WEBM_RESOURCES_DIR + str(document.file_id) + ".webm")
            delete_file(WEBM_RESOURCES_DIR + str(document.file_id) + ".mp4")

        except Exception as e:
            logger.error(
                "Caught Error in webm.conversion - {} \n {}",
                e,
                traceback.format_exc(),
            )

    except Exception as e:
        logger.error(
            "Caught Error in webm.handle - {} \n {}",
            e,
            traceback.format_exc(),
        )
Exemple #5
0
def timesince_calculator(lastseen):

    now = datetime.now()
    td = now - lastseen
    pretty_td = util.pretty_time_delta(td.total_seconds())
    return (pretty_td)