Lv110版本源码上传
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
|
||||
host_window = r"C:\Windows\System32\drivers\etc\hosts"
|
||||
host_mac = r"/etc/hosts"
|
||||
|
||||
|
||||
HOST_LIVE = ["#dcalc",
|
||||
"127.0.0.1:17173 www.dcalc.com"]
|
||||
|
||||
def search_host(hostvalue):
|
||||
if platform.system().lower() != "windows":
|
||||
host_path = host_mac
|
||||
else:
|
||||
host_path = host_window
|
||||
hostfile = open(host_path, 'r',errors='ignore')
|
||||
each_line = hostfile.readlines()
|
||||
hostfile.close()
|
||||
findresult = re.findall(hostvalue, ''.join(each_line))
|
||||
return findresult
|
||||
|
||||
def write_host(hostvalue):
|
||||
if platform.system().lower() != "windows":
|
||||
output = open(host_mac, 'a')
|
||||
else:
|
||||
output = open(host_window, 'a')
|
||||
|
||||
for insid in hostvalue:
|
||||
output.write(insid)
|
||||
output.write("\n")
|
||||
output.close()
|
||||
|
||||
def host_init():
|
||||
if not search_host(HOST_LIVE[0]):
|
||||
write_host(HOST_LIVE)
|
||||
@@ -0,0 +1,30 @@
|
||||
# 用于实现排行的最小堆
|
||||
from heapq import heapify, heappush, heappushpop
|
||||
|
||||
|
||||
class MinHeap:
|
||||
def __init__(self, top_n,h=[]):
|
||||
self.h = h[:]
|
||||
self.length = top_n
|
||||
heapify(self.h)
|
||||
|
||||
def add(self, element):
|
||||
if len(self.h) < self.length:
|
||||
heappush(self.h, element)
|
||||
else:
|
||||
heappushpop(self.h, element)
|
||||
|
||||
def getTop(self):
|
||||
return sorted(self.h, reverse=True)
|
||||
|
||||
def merge(self, other):
|
||||
"""
|
||||
合并另一个堆
|
||||
@type other MinHeap
|
||||
"""
|
||||
for elem in other.h:
|
||||
self.add(elem)
|
||||
|
||||
def reset(self):
|
||||
self.h = []
|
||||
heapify(self.h)
|
||||
@@ -0,0 +1,58 @@
|
||||
from numbers import Number
|
||||
|
||||
|
||||
def is_number(num_str):
|
||||
"""
|
||||
判断数据是否为一个数字
|
||||
|
||||
:param num_str: 字符串对象
|
||||
:return:
|
||||
"""
|
||||
"""
|
||||
判断数据是否为一个数字
|
||||
|
||||
:param num_str: 字符串对象
|
||||
:return: 布尔值 True 是一个数字 False 不是一个数字 None 本就是数值类型
|
||||
"""
|
||||
# 防止非字段类型类型输入报错
|
||||
if isinstance(num_str, Number):
|
||||
return None
|
||||
elif not isinstance(num_str, str):
|
||||
return False
|
||||
|
||||
if num_str.isdigit():
|
||||
return True
|
||||
# 对Float类型的数字进行判断
|
||||
if num_str.count('.') == 1:
|
||||
num_str_list = num_str.split('.')
|
||||
left = num_str_list[0]
|
||||
right = num_str_list[1]
|
||||
if left.startswith('-') and left.count('-') == 1 and right.isdigit():
|
||||
_left = left.split('-')[1]
|
||||
if _left.isdigit():
|
||||
return True
|
||||
elif left.isdigit() and right.isdigit():
|
||||
return True
|
||||
# 负数判断
|
||||
elif num_str.startswith('-'):
|
||||
_left = num_str.split('-')[1]
|
||||
if _left.isdigit():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def str_to_num(value, default=0, num_type=float):
|
||||
"""
|
||||
将字符串类型转化为数据类型
|
||||
|
||||
:param value: 需要转化的值,不一定需要是字符串类型
|
||||
:param default: 设置转换失败返回数值,默认原值
|
||||
:param num_type: 设置转换成的数据类型
|
||||
:return:
|
||||
"""
|
||||
num_flag = is_number(value)
|
||||
if num_flag:
|
||||
return num_type(value)
|
||||
elif num_flag is None:
|
||||
return num_type(value)
|
||||
return value if default is None else default
|
||||
@@ -0,0 +1,18 @@
|
||||
import hashlib
|
||||
import sys
|
||||
from core.store import store
|
||||
|
||||
|
||||
def get_mac_address():
|
||||
try:
|
||||
import wmi
|
||||
uniqueCode = store.get("uniqueCode")
|
||||
if uniqueCode is None:
|
||||
w = wmi.WMI()
|
||||
uniqueCode = hashlib.md5(
|
||||
w.Win32_DiskDrive()[0].SerialNumber.encode(
|
||||
encoding='UTF-8')).hexdigest()
|
||||
store.set("uniqueCode", uniqueCode)
|
||||
return uniqueCode
|
||||
except Exception:
|
||||
return ''
|
||||
Reference in New Issue
Block a user