#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Date    : 2018/3/3 0003 22:30
# @Author  : wangxian (908686161@qq.com)

# ------------------------------------------
#   作用：清空Redis数据，重新跑数据时用。
# ------------------------------------------

import settings
import redis

if __name__ == '__main__':
    try:
        rconn = redis.Redis(settings.REDIS_HOST, settings.REDIS_PORT, settings.REDIS_DB)
    except Exception:
        rconn = redis.Redis(settings.REDIS_HOST, settings.REDIS_PORT)

    try:
        rconn_filter = redis.Redis(settings.FILTER_HOST, settings.FILTER_PORT, settings.FILTER_DB)
    except Exception:
        try:
            rconn_filter = redis.Redis(settings.FILTER_HOST, settings.FILTER_PORT)
        except Exception:
            rconn_filter = None

    if rconn:
        if 'SinaSpider:requests' in rconn.keys():
            rconn.delete('SinaSpider:requests')

    if rconn_filter:
        if 'SinaSpider:dupefilter0' in rconn.keys():
            rconn.delete('SinaSpider:dupefilter0')
        if 'SinaSpider:dupefilter1' in rconn.keys():
            rconn.delete('SinaSpider:dupefilter1')

    print('Finish!')
