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

2023-02-23 18:36:39 +08:00
 XentaiZ

事情是这样的:

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

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

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

求大佬帮忙呜呜呜>_<

634 次点击
所在节点    程序员
4 条回复
heybuddy
2023-02-23 21:25:27 +08:00
python 写个定时脚本,cd 到指定目录,执行完后记录最后脚本的执行时间,再去对应的文件夹里查看有没有比最后检测时间大的,有的话用 webhook/钉钉机器人 /server 酱 /bark 通知一下
XentaiZ
2023-02-23 22:20:06 +08:00
@heybuddy 感谢,有那么点感觉,我研究研究
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
2023-02-24 04:56:14 +08:00
@vivisidea 我艹,大佬大佬🤣🤣🤣,膜拜。我个人比较常用 C charp ,python 我只学了三天🥲🥲🥲不过我还是能大致读懂的,我按照你们思路摸索一下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/918631

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX