如何解决每天在网页上生成加密文件
我有一个 python 程序,它读取加密文件以提取所需的设置和时间。加密文件应每分钟更新一次,并应由多个用户远程访问。
有没有办法在网页上生成加密文件(带有固定的超链接;比如 www.website-name.com/log.txt)并在特定时间范围内(例如,每分钟、每小时、每天等)替换旧文件)。然后,我可以从它的 url 访问该文件。
有没有办法做到这一点?
解决方法
在服务器上安装redis并安装redis-py 参考链接https://github.com/andymccurdy/redis-py
$ pip install redis
然后将其添加到程序中
import redis
r = redis.Redis(host='localhost',port=6379,db=0)
file_name = ''
# 60 can change to any time you want
expire_time = 60
encrypted_file_content = r.get('file_content')
if not encrypted_file_content:
encrypted_file_content = do_something()
r.set('file_content',encrypted_file_content,expire_time)
with open(file_name,'w') as f:
f.write(encrypted_file_content)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。