Exemplo n.º 1
0
    async def market_prices_coroutine(knobs):
        price_url = 'https://api.blockchair.com/stats'

        try:
            context = ssl._create_unverified_context()
            request = urllib.request.Request(
                price_url,
                headers={},
            )
            resp = json.loads(
                urllib.request.urlopen(
                    request, context=context).read().decode())['data']
            btc_price = format(
                round(resp['bitcoin']['data']['market_price_usd'], 2), ',')
            eth_price = format(
                round(resp['ethereum']['data']['market_price_usd'], 2), ',')
            bch_price = format(
                round(resp['bitcoin-cash']['data']['market_price_usd'], 2),
                ',')
            ltc_price = format(
                round(resp['litecoin']['data']['market_price_usd'], 2), ',')
        except:
            raise
        else:
            return f'BTC ${btc_price}  ETH ${eth_price} BCH ${bch_price}  LTC ${ltc_price}'

    await component.async_register(connection, market_prices_coroutine)


iterm2.run_forever(main)
        knobs=[],
        exemplar=f"{Timer.ICON_RUNNING} 45s",
        update_cadence=1,
        identifier="local.jbradt.command-timer",
    )

    monitor_manager = CommandMonitorManager(
        pm_factory=lambda sid: PromptMonitor(connection, sid, ALL_MODES)
    )

    @StatusBarRPC
    async def status_bar_update(knobs, session_id=Reference("id")):
        timer = monitor_manager.get_timer_for_session_id_or_none(session_id)
        if timer:
            return timer.formatted_duration

        return ""

    async def monitor_commands(session_id: str):
        with monitor_manager.instance_for_session_id(session_id) as monitor:
            await monitor.command_monitor()

    await component.async_register(connection, status_bar_update)
    await EachSessionOnceMonitor.async_foreach_session_create_task(
        app, monitor_commands
    )


if __name__ == "__main__":
    run_forever(main)
Exemplo n.º 3
0
#!/usr/bin/env python3

import asyncio
import iterm2
import theme_switcher


async def switch_on_theme_change(connection):
    """Continuously monitor the effective theme for changes."""
    async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP,
                                      "effectiveTheme", None) as mon:
        while True:
            theme = await mon.async_get()
            is_dark = theme_switcher.is_dark_theme(theme)
            preset = await theme_switcher.get_colour_preset(
                connection, is_dark)
            ansi_8_color = theme_switcher.get_ansi_8_color(is_dark)
            await theme_switcher.set_colours(connection, preset, ansi_8_color)


if __name__ == '__main__':
    iterm2.run_forever(switch_on_theme_change)
Exemplo n.º 4
0
#!/usr/bin/env python3

import iterm2
# To install, update, or remove packages from PyPI, use Scripts > Manage > Manage Dependencies...

async def main(connection):
    # This is an example of using an asyncio context manager to register a custom control
    # sequence. You can send a custom control sequence by issuing this command in a
    # terminal session in iTerm2 while this script is running:
    #
    # printf "\033]1337;Custom=id=%s:%s\a" "shared-secret" "create-window"
    async with iterm2.CustomControlSequenceMonitor(connection, "shared-secret", r'^create-window$') as mon:
        while True:
            match = await mon.async_get()
            await iterm2.Window.async_create(connection)

# This instructs the script to run the "main" coroutine and to keep running even after it returns.
iterm2.run_forever(main)