mirror of
https://github.com/JamesonHuang/OpenWrt_Luci_Lua.git
synced 2025-06-30 14:03:24 +00:00
build http cache proxy protocol
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 14 KiB |
Binary file not shown.
@ -28,30 +28,32 @@ class CacheUtils:
|
||||
with open("./cache/" + fileName + range, "a+") as fp:
|
||||
fp.write(buffer)
|
||||
|
||||
def saveReq(self, url):
|
||||
def saveReq(self, url, range):
|
||||
|
||||
# Reading data back
|
||||
with open('data.json', 'r') as fp:
|
||||
data = json.load(fp)
|
||||
data[url] = 4000
|
||||
data[url] = range
|
||||
# Writing JSON data
|
||||
with open('data.json', 'w') as fp:
|
||||
json.dump(data, fp)
|
||||
|
||||
|
||||
def checkReq(self):
|
||||
def checkReq(self, url):
|
||||
# Reading data back
|
||||
with open('data.json', 'r') as fp:
|
||||
data = json.load(fp)
|
||||
#print(data)
|
||||
#print(data.keys())
|
||||
print(data["www.baidu.com"])
|
||||
if data.get("key"):
|
||||
print(data["key"])
|
||||
if data.get(url):
|
||||
fileName = url.split('/')[-1]
|
||||
with open('GotIt.txt', 'a+') as fp:
|
||||
if data[url] == "None":
|
||||
fp.write("./download/" + fileName + "\n")
|
||||
else:
|
||||
fp.write("./cache/" + fileName + " " + data[url] + "\n")
|
||||
return True
|
||||
else:
|
||||
print("error")
|
||||
return False
|
||||
|
||||
"""
|
||||
if __name__ == '__main__':
|
||||
cacheUtils = CacheUtils()
|
||||
|
||||
@ -63,7 +65,6 @@ if __name__ == '__main__':
|
||||
#cacheUtils.cache("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superplus/img/logo_white_ee663702.png", "0-7000")
|
||||
#cacheUtils.cache("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superplus/img/logo_white_ee663702.png", "7001-14175")
|
||||
|
||||
cacheUtils.saveReq("http://www.sina.com.cn")
|
||||
#cacheUtils.saveReq("http://www.sina.com.cn")
|
||||
|
||||
#cacheUtils.loadReq()
|
||||
"""
|
||||
|
@ -1 +1 @@
|
||||
{"http://www.sina.com.cn": 4000}
|
||||
{"http://www.sina.com.cn": "helloworld"}
|
Reference in New Issue
Block a user