puppylpg / oddish

Crawl csgo skin info from `buff.163.com` and steam, then find the most suitable one to buy from the former and to sell to the latter.
https://puppylpg.github.io/2019/12/07/python-crawler-buff-optimaze/
GNU General Public License v3.0
323 stars 81 forks source link

关于读取cache时的异常判断 #31

Closed RaymondMcGuire closed 4 years ago

RaymondMcGuire commented 4 years ago

今天再跑程序的时候,不知道为什么存储缓存文件地方出了问题。 而后重新开程序的时候就会在这个地方报错(原因是存在cache文件内容却是空,我把那个空的缓存文件删掉就可以运行了), 这个地方可能需要进行一下异常判断如果存在缓存文件但是格式不对之类的时候进行处理。

def fetch(url): urlid = url_id(url) log.info('Successful attempt to fetch from {}'.format(urlid)) with open(os.path.join(cache_root, urlid), "r", encoding='utf-8') as f: return f.read()

ccinv commented 4 years ago

现在会检查是否为合法的 json 格式,除了一些极端状况之外应该都没事了。