Remove the nginx cache file example of a python file operation using python
- 2020-04-02 13:30:05
- OfStack
When invoked, input parameters are as follows:
www.jb51.net/ means to delete the cache of www.jb51.net homepage, (link: #) means to delete the cache of /test.php
#coding=utf8
import sys,os
import hashlib
if len(sys.argv)<2:
print(" You didn't enter the address. ")
sys.exit()
path="/home/cache"# The cache directory
md5v = hashlib.md5(sys.argv[1].encode(encoding='gb2312')).hexdigest()# documented hash value
onep=md5v[31:32]
twop=md5v[29:31]
filename=path+"/"+onep+"/"+twop+"/"+md5v
if os.path.isfile(filename):
if os.remove(filename)==None:
print(filename+" ==> Clear success ")
else:
print(" Removal of failure ")
else:
print(" There is no cache file ")