Skip to content

Commit

Permalink
🔨 refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
shidenggui committed Aug 8, 2018
1 parent 3ec661b commit 9696354
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 61 deletions.
10 changes: 8 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=invalid-envvar-default,
disable=too-many-arguments,
too-many-instance-attributes,
arguments-differ,
len-as-condition,
missing-docstring,
invalid-envvar-default,
ungrouped-imports,
bad-continuation,
too-many-ancestors,
Expand Down Expand Up @@ -250,7 +255,8 @@ good-names=i,
r,
x,
y,
e
e,
f

# Include a hint for the correct naming format with invalid-name
include-naming-hint=no
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python

python:
- "3.4"
- "3.5"
- "3.6"

Expand Down
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ verify_ssl = false
name = "pypi"

[packages]
six = "*"
requests = "*"
easyutils = "*"

[dev-packages]
pytest-cov = "*"
Expand Down
105 changes: 103 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion easyquotation/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# coding:utf8

from . import boc, jsl, sina, tencent, daykline, hkqoute, timekline
from . import boc, daykline, hkqoute, jsl, sina, tencent, timekline


# pylint: disable=too-many-return-statements
def use(source):
if source in ["sina"]:
return sina.Sina()
Expand Down
2 changes: 1 addition & 1 deletion easyquotation/basequotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def real(self, stock_codes, prefix=False):
If prefix with True, key start with sh/sz market flag
"""
if type(stock_codes) is not list:
if not isinstance(stock_codes, list):
stock_codes = [stock_codes]

stock_list = self.gen_stock_list(stock_codes)
Expand Down
6 changes: 3 additions & 3 deletions easyquotation/boc.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# coding:utf8
import re
import requests

from .basequotation import BaseQuotation
import requests


class Boc(object):
class Boc:
"""中行美元最新汇率"""

url = "http://www.boc.cn/sourcedb/whpj/"
Expand All @@ -16,3 +15,4 @@ def get_exchange_rate(self, currency="usa"):

if currency == "usa":
return {"sell": data[-13], "buy": data[-15]}
return {}
14 changes: 8 additions & 6 deletions easyquotation/daykline.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# coding:utf8
import json
import re

from . import basequotation

"""
# pylint: disable=line-too-long
url = "http://web.ifzq.gtimg.cn/appstock/app/hkfqkline/get?_var=kline_dayqfq&param=hk00001,day,,,660,qfq&r=0.7773272375526847"
url 参数改动
Expand All @@ -13,9 +9,14 @@
更改为需要获取的股票代码和天数例如:
# pylint: disable=line-too-long
url = "http://web.ifzq.gtimg.cn/appstock/app/hkfqkline/get?_var=kline_dayqfq&param=hk00700,day,,,350,qfq&r=0.7773272375526847"
"""
import json
import re

from . import basequotation


class DayKline(basequotation.BaseQuotation):
Expand All @@ -25,12 +26,13 @@ class DayKline(basequotation.BaseQuotation):

@property
def stock_api(self) -> str:
# pylint: disable=line-too-long
return "http://web.ifzq.gtimg.cn/appstock/app/hkfqkline/get?_var=kline_dayqfq&param="

def _gen_stock_prefix(self, stock_codes, day=1500):
return ["hk{},day,,,{},qfq".format(code, day) for code in stock_codes]

def format_response_data(self, rep_data, prefix=False):
def format_response_data(self, rep_data, **kwargs):
stock_dict = {}
for raw_quotation in rep_data:
raw_stocks_detail = re.search(r"=(.*)", raw_quotation).group(1)
Expand Down
10 changes: 5 additions & 5 deletions easyquotation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def update_stock_codes():
"""获取所有股票 ID 到 all_stock_code 目录下"""
all_stock_codes_url = "http://www.shdjt.com/js/lib/astock.js"
grep_stock_codes = re.compile("~(\d+)`")
grep_stock_codes = re.compile(r"~(\d+)`")
response = requests.get(all_stock_codes_url)
all_stock_codes = grep_stock_codes.findall(response.text)
with open(stock_code_path(), "w") as f:
Expand All @@ -22,15 +22,15 @@ def get_stock_codes(realtime=False):
"""获取所有股票 ID 到 all_stock_code 目录下"""
if realtime:
all_stock_codes_url = "http://www.shdjt.com/js/lib/astock.js"
grep_stock_codes = re.compile("~(\d+)`")
grep_stock_codes = re.compile(r"~(\d+)`")
response = requests.get(all_stock_codes_url)
stock_codes = grep_stock_codes.findall(response.text)
with open(stock_code_path(), "w") as f:
f.write(json.dumps(dict(stock=stock_codes)))
return stock_codes
else:
with open(stock_code_path()) as f:
return json.load(f)["stock"]

with open(stock_code_path()) as f:
return json.load(f)["stock"]


def stock_code_path():
Expand Down
14 changes: 7 additions & 7 deletions easyquotation/hkqoute.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# coding:utf8

import re

from . import basequotation

"""
url = "http://sqt.gtimg.cn/utf8/q=r_hk00981"
Expand All @@ -12,6 +7,11 @@
"""


import re

from . import basequotation


class HKQuote(basequotation.BaseQuotation):
"""腾讯免费行情获取"""

Expand All @@ -22,11 +22,11 @@ def stock_api(self) -> str:
def _gen_stock_prefix(self, stock_codes):
return ["r_hk{}".format(code) for code in stock_codes]

def format_response_data(self, rep_data, prefix=False):
def format_response_data(self, rep_data, **kwargs):
stocks_detail = "".join(rep_data)

stock_dict = {}
for raw_quotation in re.findall('v_r_hk\d+=".*?"', stocks_detail):
for raw_quotation in re.findall(r'v_r_hk\d+=".*?"', stocks_detail):
quotation = re.search('"(.*?)"', raw_quotation).group(1).split("~")
stock_dict[quotation[2]] = dict(
lotSize=float(quotation[0]),
Expand Down
Loading

0 comments on commit 9696354

Please sign in to comment.