小编Gui*_*eus的帖子

如何从日志功能中获取消息?

我有一个包logger中的函数logging,调用它后,我可以通过 发送消息logging level

我还想将此消息发送到另一个函数,这是一个名为 的 Telegram 函数SendTelegramMsg()

例如,在调用函数setup_logger发送消息后如何获取消息,然后将完全相同的消息发送到函数内部的函数?logger.info("Start")SendTelegramMsg()setup_logger

我目前的setup_logger功能:

# Define the logging level and the file name
def setup_logger(telegram_integration=False):
    """To setup as many loggers as you want"""

    filename = os.path.join(os.path.sep, pathlib.Path(__file__).parent.resolve(), 'logs', str(dt.date.today()) + '.log')
    formatter = logging.Formatter('%(levelname)s: %(asctime)s: %(message)s', datefmt='%m/%d/%Y %H:%M:%S')
    level = logging.DEBUG

    handler = logging.FileHandler(filename, 'a')    
    handler.setFormatter(formatter)

    consolehandler = logging.StreamHandler()
    consolehandler.setFormatter(formatter)

    logger = logging.getLogger('logs')
    if logger.hasHandlers():
        # Logger is already configured, …
Run Code Online (Sandbox Code Playgroud)

python logging python-telegram-bot

7
推荐指数
1
解决办法
2475
查看次数

Pywinauto:如何调整活动窗口的大小

我正在尝试自动化一些 Windows 任务,并且获得了所有打开的窗口的数据框,然后添加了更多列,以便在继续自动化之前进行一些验证。

\n

从功能激活窗口后set_focus(),我根本无法调整任何窗口的大小,根本没有任何反应。

\n

我已经尝试使用win32gui解决方案:

\n
current = win32gui.GetForegroundWindow()\nwin32gui.MoveWindow(current, 0, 0, 100, 100, True)\n
Run Code Online (Sandbox Code Playgroud)\n

我也尝试使用pygetwindow函数resizeToor size,但也没有任何反应。

\n

如果我运行以下命令app.move_window(x=None, y=None, width=100, height=100, repaint=True)AttributeError: \'UIAWrapper\' object has no attribute \'move_window\'

\n

我的代码:

\n
from pywinauto import Desktop\nimport pandas as pd\n\nwindows = Desktop(backend="uia").windows()\nwindow = [w.window_text() for w in windows]\n\n# Create a dataframe in order to store the windows needed\ndf_windows = pd.DataFrame(window, columns =[\'WebBrowser\'])\n# Filter dataframe only …
Run Code Online (Sandbox Code Playgroud)

python pywin32 win32gui pywinauto

5
推荐指数
1
解决办法
2128
查看次数

如何使用 AsyncIOScheduler 从另一个函数运行函数?

我很难理解它是如何AsyncIOScheduler工作的以及如何在主函数内安排一个函数,或者如何是正确的方法来做到这一点。

如何foo每 10 秒运行一次该函数?

假设我有这样的结构:

package/
    controllers.py
    main.py
Run Code Online (Sandbox Code Playgroud)

从文件中controllers.py我调用了一个函数foo,该函数如下所示:

async def foo():
    print('Hello World')
Run Code Online (Sandbox Code Playgroud)

我想foo从文件运行该函数(以及许多其他函数)main.py,该文件如下:

import asyncio
from controllers import foo, bar
from apscheduler.schedulers.asyncio import AsyncIOScheduler

async def main():

    # Init message
    print('\nPress Ctrl-C to quit at anytime!\n' )
    
    await asyncio.create_task(bar())

    scheduler = AsyncIOScheduler()
    scheduler.add_job(await asyncio.create_task(foo()), "interval", seconds=10)
    scheduler.start()

if __name__ == "__main__":
    while True:
        try:
            asyncio.run(main())
        except Exception as e:
            print("Exception: " + str(e))
Run Code Online (Sandbox Code Playgroud)

这样运行调度程序是否正确?或者每次main函数运行时定时器都会被重置?

我尝试了下面的代码,循环间隔有效,但该main …

python asynchronous apscheduler python-asyncio

4
推荐指数
1
解决办法
2726
查看次数