def __init__(self, update=False): super(GeoIP, self).__init__() qdat = os.path.join(os.path.dirname(os.path.abspath(__file__)), "qqwry.dat") if not os.path.exists(qdat) or update: ret = qqwry.updateQQwry(qdat) self.q = qqwry.QQwry() self.q.load_file(qdat)
def init(): result = updateQQwry(IP_DATA_FILE) if result < 0: print("Update File Error: ", result) sys.exit(result) else: print("File Load Successfully: ", result)
def fetch_cz_ip_database(): """每月下载纯真数据库""" try: updateQQwry(PARAS().IP_DATABASE_FILENAME) try: # 发邮件通知 threading.Thread(target=send_mail, args=( {'text': '下载最新版纯真数据库', 'header': '当前纯真数据库下载完成,一切OK!'}, PARAS().EMAIL_SEND_ACCOUNT, PARAS().EMAIL_KEY, PARAS().EMAIL_RECEIVE_ACCOUNT)).start() except: pass except Exception as e: try: # 发邮件通知 threading.Thread(target=send_mail, args=( {'text': '下载最新版纯真数据库失败', 'header': '当前纯真数据库出错:%s' % e}, PARAS().EMAIL_SEND_ACCOUNT, PARAS().EMAIL_KEY, PARAS().EMAIL_RECEIVE_ACCOUNT)).start() except: pass
def update_dat(self): ''' 异步更新,使用线程或者celery更新IP数据库源 :return:(bool) 成功后返回一个正整数,是文件的字节数;失败则返回一个负整数。 ''' result = updateQQwry(self.dat_path) if result > 0: print('ip库更新成功') return True print('ip库更新失败,网络出现故障') return False
if __name__ == '__main__': UsePlatform() if runos != 'Linux': print('%sOnly sup Linux! Now:%s' % (ret_time(), runos)) sys.exit() print('\n############# Cloud Front Scan #################') print(' Author hostloc.com') print('################################################') print('Init->Update 2020.10.16 Author Ali') print('Init->OS: %s' % runos) print('Init->IP Data File exists: %s' % os.path.exists('QQway.dat')) if not os.path.exists('QQway.dat'): print("%sDownload QQwry.dat" % ret_time()) download_ret = updateQQwry('QQway.dat') if int(download_ret) < 0: print("%sDownload QQwry.dat Error:" % ret_time(), int(download_ret)) print("-1:下载copywrite.rar时出错\n" "-2:解析copywrite.rar时出错\n" "-3:下载qqwry.rar时出错\n" "-4:qqwry.rar文件大小不符合copywrite.rar的数据\n" "-5:解压缩qqwry.rar时出错\n" "-6:保存到最终文件时出错") sys.exit() else: print("%sDownload QQwry.dat Success~ Status:%s" % (ret_time(), int(download_ret))) qq_wry = QQwry() qq_wry.load_file('QQway.dat') # Run print(
#更新数据库 from qqwry import updateQQwry ret = updateQQwry('qqwry.dat')