This commit is contained in:
fasiondog 2020-11-29 19:01:18 +08:00
parent 62cab0619d
commit 9b3bc0df7c
10 changed files with 156 additions and 127 deletions

View File

@ -0,0 +1,8 @@
# coding:utf-8
#
# The MIT License (MIT)
#
# Created on: 2020-11-29
# Author: fasiondog
__version__ = "0.0.1"

14
hikyuu/fetcher/proxy.py Normal file
View File

@ -0,0 +1,14 @@
# coding:utf-8
#
# The MIT License (MIT)
#
# Created on: 2020-11-29
# Author: fasiondog
def getProxy():
"""
:ip地址:183.164.239.57:4264
None
"""
return None

View File

@ -0,0 +1,8 @@
# coding:utf-8
#
# The MIT License (MIT)
#
# Created on: 2020-11-29
# Author: fasiondog
__version__ = "0.0.1"

View File

@ -0,0 +1,66 @@
# coding:utf-8
#
# The MIT License (MIT)
#
# Created on: 2020-11-29
# Author: fasiondog
import requests
def parse_one_result(resultstr):
result = {}
if not resultstr:
return result
if len(resultstr) <= 3 and resultstr[:3] != 'var':
return result
a = resultstr.split(',')
if len(a) < 9:
return
try:
tmp = a[0].split('"')
result['name'] = tmp[1]
except Exception as e:
print(e)
return result
def request_func(querystr):
try:
result = requests.get(querystr).text
except Exception as e:
print(result)
print(e)
return
result = result.split('\n')
for tmpstr in result:
parse_one_result(tmpstr)
return
def get_spot_from_sina(stocklist):
queryStr = "http://hq.sinajs.cn/list="
max_size = 140
count = 0
tmpstr = queryStr
for stock in stocklist:
tmpstr += ("%s,") % (stock)
count = count + 1
if count >= max_size:
request_func(tmpstr)
count = 0
tmpstr = queryStr
if tmpstr != queryStr:
request_func(tmpstr)
if __name__ == "__main__":
print("a")

View File

@ -22,6 +22,7 @@ from hikyuu.gui.data.UsePytdxImportToH5Thread import UsePytdxImportToH5Thread
from hikyuu.gui.data.CollectThread import CollectThread
from hikyuu.data import hku_config_template
from hikyuu.util.mylog import add_class_logger_handler
class EmittingStream(QObject):
@ -125,14 +126,16 @@ class MyMainWindow(QMainWindow, Ui_MainWindow):
)
con.setFormatter(FORMAT)
logger_name_list = [
self.__class__.__name__, CollectThread.__name__, UsePytdxImportToH5Thread.__name__,
UseTdxImportToH5Thread.__name__
self.__class__.__name__, UsePytdxImportToH5Thread.__name__,
UseTdxImportToH5Thread.__name__, CollectThread.__name__
]
for name in logger_name_list:
logger = logging.getLogger(name)
logger.addHandler(con)
logger.setLevel(logging.INFO)
#add_class_logger_handler(con, [CollectThread])
def initUI(self):
if self._capture_output:
stream = EmittingStream(textWritten=self.normalOutputWritten)

View File

@ -378,7 +378,7 @@ def realtime_update_from_sina_qq(source):
return
count = 0
urls = []
#urls = []
tmpstr = queryStr
for stock in sm:
if stock.valid and stock.type in (

View File

@ -9,4 +9,4 @@
#from singleton import Singleton
__all__ = ['mylog']
__all__ = ['mylog', 'check']

View File

@ -18,8 +18,33 @@ class CheckError(Exception):
def checkif(expression, message, excepion=None, **kwargs):
"""如果 expression 为 True则抛出异常。注意该函数的判定和 assert 是相反的。
:param boolean expression:
:param str message:
:param Exception exception: None时 CheckError
"""
if expression:
if excepion is None:
raise CheckError(expression, message)
else:
raise excepion(message, **kwargs)
def HKU_CHECK(exp, msg):
if not exp:
raise CheckError(exp, msg)
def HKU_CHECK_THROW(expression, message, excepion=None, **kwargs):
"""如果 expression 为 False则抛出异常。
:param boolean expression:
:param str message:
:param Exception exception: None时 CheckError
"""
if not expression:
if excepion is None:
raise CheckError(expression, message)
else:
raise excepion(message, **kwargs)

View File

@ -2,88 +2,37 @@
# -*- coding: utf8 -*-
# cp936
"""
escapetime函数外SQLAlchemy
Logging control and utilities.
Control of logging for SA can be performed from the regular python logging
module. The regular dotted module namespace is used, starting at
'sqlalchemy'. For class-level logging, the class name is appended.
The "echo" keyword parameter which is available on SQLA ``Engine``
and ``Pool`` objects corresponds to a logger specific to that
instance only.
E.g.::
engine.echo = True
is equivalent to::
import logging
logger = logging.getLogger('sqlalchemy.engine.Engine.%s' % hex(id(engine)))
logger.setLevel(logging.DEBUG)
"""
import logging
import sys
import time
from functools import wraps
def escapetime( func ):
def wrappedFunc( *args, **kargs ):
def escapetime(func):
@wraps(func)
def wrappedFunc(*args, **kargs):
starttime = time.time()
try:
print("\nCalling: %s" % func.__name__)
return func(*args, **kargs)
finally:
endtime = time.time()
#print( "Called: %r" % func)
print( "Escaped time: %.4fs, %.2fm" % (endtime-starttime, (endtime-starttime)/60) )
print("Escaped time: %.4fs, %.2fm" % (endtime - starttime, (endtime - starttime) / 60))
return wrappedFunc
mylogger = logging.getLogger('my')
mylogger_name = 'hikyuu'
mylogger = logging.getLogger(mylogger_name)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s %(name)s %(message)s'))
handler.setFormatter(
logging.Formatter('%(asctime)-15s [%(levelname)s]: %(message)s [%(name)s::%(funcName)s]')
)
mylogger.addHandler(handler)
def set_debug_mode(logtype='debug'):
global mylogger
if logtype == 'debug':
mylogger.setLevel(logging.DEBUG)
elif logtype == 'info':
mylogger.setLevel(logging.INFO)
elif logtype == 'warning':
mylogger.setLevel(logging.WARNING)
elif logtype == 'error':
mylogger.setLevel(logging.ERROR)
elif logtype == 'critical':
mylogger.setLevel(logging.CRITICAL)
else:
mylogger.setLevel(logging.ERROR)
rootlogger = logging.getLogger('stock')
if rootlogger.level == logging.NOTSET:
rootlogger.setLevel(logging.WARN)
default_enabled = False
def default_logging(name):
global default_enabled
if logging.getLogger(name).getEffectiveLevel() < logging.WARN:
default_enabled = True
if not default_enabled:
default_enabled = True
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s %(name)s %(message)s'))
rootlogger.addHandler(handler)
def class_logger(cls, enable=False):
logger = logging.getLogger(cls.__module__ + "." + cls.__name__)
logger = logging.getLogger("{}.{}".format(cls.__module__, cls.__name__))
if enable == 'debug':
logger.setLevel(logging.DEBUG)
elif enable == 'info':
@ -92,62 +41,15 @@ def class_logger(cls, enable=False):
cls._should_log_info = logger.isEnabledFor(logging.INFO)
cls.logger = logger
def instance_logger(instance, echoflag=None):
"""create a logger for an instance.
Warning: this is an expensive call which also results in a permanent
increase in memory overhead for each call. Use only for
low-volume, long-time-spanning objects.
def add_class_logger_handler(handler, class_list, level=logging.INFO):
"""为指定的类增加日志 handler并设定级别
:param handler: logging handler
:param class_list:
:param level:
"""
# limit the number of loggers by chopping off the hex(id).
# many novice users unfortunately create an unlimited number
# of Engines in their applications which would otherwise
# cause the app to run out of memory.
name = "%s.%s.0x...%s" % (instance.__class__.__module__,
instance.__class__.__name__,
hex(id(instance))[-4:])
if echoflag is not None:
l = logging.getLogger(name)
if echoflag == 'debug':
default_logging(name)
l.setLevel(logging.DEBUG)
elif echoflag is True:
default_logging(name)
l.setLevel(logging.INFO)
elif echoflag is False:
l.setLevel(logging.NOTSET)
else:
l = logging.getLogger(name)
if not l.handlers:
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s %(name)s %(message)s'))
l.addHandler(handler)
instance._should_log_debug = l.isEnabledFor(logging.DEBUG)
instance._should_log_info = l.isEnabledFor(logging.INFO)
return l
class echo_property(object):
__doc__ = """\
When ``True``, enable log output for this element.
This has the effect of setting the Python logging level for the namespace
of this element's class and object reference. A value of boolean ``True``
indicates that the loglevel ``logging.INFO`` will be set for the logger,
whereas the string value ``debug`` will set the loglevel to
``logging.DEBUG``.
"""
def __get__(self, instance, owner):
if instance is None:
return self
else:
return instance._should_log_debug and 'debug' or (instance._should_log_info and True or False)
def __set__(self, instance, value):
instance_logger(instance, echoflag=value)
for cls in class_list:
logger = logging.getLogger("{}.{}".format(cls.__module__, cls.__name__))
logger.addHandler(handler)
logger.setLevel(level)

View File

@ -49,6 +49,8 @@ packages = [
'hikyuu/data/sqlite_upgrade',
'hikyuu/data_driver',
'hikyuu/examples',
'hikyuu/fetcher',
'hikyuu/fetcher/stock',
'hikyuu/gui',
'hikyuu/gui/data',
'hikyuu/indicator',
@ -127,6 +129,7 @@ setup(
'gitpython',
'SQLAlchemy',
'mysql-connector-python',
'pyperclip'
'pyperclip',
'requests'
],
)