V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
XentaiZ
V2EX  ›  程序员

[求助]网络映射地址是否有办法实现新文件提醒?

  •  
  •   XentaiZ · 2023-02-23 18:36:39 +08:00 · 622 次点击
    这是一个创建于 421 天前的主题,其中的信息可能已经有所发展或是发生改变。

    事情是这样的:

    本人目前在高校工作,学校有一个大型 NAS ,校园网内可以通过映射网络驱动器的选项添加在自己的计算机里,然后每个所都有自己的一个文件夹,文件夹里每位同事又有自己的一个文件夹(没错就是套娃)。

    我每次给楼下电镜的阿姨送样,阿姨测完之后,会把电镜照片,样品组分等等文件塞到我的网盘文件夹里,问题是,我根本不知道阿姨什么时候测好,什么时候上传文件。我只有自己去问,或者不断查看我的文件夹。。。很累。。。

    有没有办法写个脚本,对我的文件夹进行监控,发现有新文件了,马上通知我,这样我就知道样品测好了。。。

    求大佬帮忙呜呜呜>_<

    heybuddy
        1
    heybuddy  
       2023-02-23 21:25:27 +08:00
    python 写个定时脚本,cd 到指定目录,执行完后记录最后脚本的执行时间,再去对应的文件夹里查看有没有比最后检测时间大的,有的话用 webhook/钉钉机器人 /server 酱 /bark 通知一下
    XentaiZ
        2
    XentaiZ  
    OP
       2023-02-23 22:20:06 +08:00
    @heybuddy 感谢,有那么点感觉,我研究研究
    vivisidea
        3
    vivisidea  
       2023-02-23 22:46:22 +08:00
    这种需求可以试试问问 chatgpt ,我感觉是比较能出方案的,我瞎问了一个,你参考参考 :D
    ```
    # write python program to monitor a network directory, if directory changes detected, invoke dingtalk webhook api

    import os
    import requests

    # Set the directory you want to monitor
    directory = '/tmp/some_folder'
    # DingTalk webhook URL
    dingtalk_url = 'https://oapi.dingtalk.com/robot/send?access_token=YOUR_DINGTALK_ACCESS_TOKEN'

    # Get the files in the directory
    files = os.listdir(directory)
    # Get the modified times of the files
    modified_times = [os.path.getmtime(os.path.join(directory, file)) for file in files]
    # Make a copy of the modified times
    previous_times = modified_times.copy()
    # Monitor the directory
    while True:
    # Get the modified times
    modified_times = [os.path.getmtime(os.path.join(directory, file)) for file in files] # Compare the modified times
    for index, time in enumerate(modified_times):
    if time != previous_times[index]:
    # Invoke DingTalk webhook
    data = {
    "msgtype": "text",
    "text": {
    "content": f"Directory {directory} changed"
    }
    }
    requests.post(dingtalk_url, json=data)
    break
    # Make a copy of the current modified times
    previous_times = modified_times.copy()


    ```
    XentaiZ
        4
    XentaiZ  
    OP
       2023-02-24 04:56:14 +08:00
    @vivisidea 我艹,大佬大佬🤣🤣🤣,膜拜。我个人比较常用 C charp ,python 我只学了三天🥲🥲🥲不过我还是能大致读懂的,我按照你们思路摸索一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   895 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:14 · PVG 05:14 · LAX 14:14 · JFK 17:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.