Пример #1
0
 def __init__(self):
     self.tools = sTools()
     self.benchmart_start = time.clock()
     self.__read_config()
     mysql_db = self.config['mysql']['stock']
     self.mysql = sMysql(mysql_db['host'], mysql_db['user'],
                         mysql_db['password'], mysql_db['dbname'])
Пример #2
0
def main_while(abc):

    i = 1
    tools = sTools()
    today = tools.d_date('%Y%m%d')
    today = 20160226
    while True:
       # print i
        #os.system('php /htdocs/soga/trader/index.php Base daily_stock_list')
        _st_data = mysql.getRecord("select chg from s_stock_list where dateline= %s" % today)
        unixtime = datetime.datetime.now().strftime("%s")
        print unixtime
        #sys.exit()
        for i in range(len(_st_data)):
            chg = _st_data[i][0]
            #print chg
            #sys.exit()

            if chg <= -5:
                _type = 1
            elif chg > -5 and chg <= -3:
                _type = 2
            elif chg > -3 and chg <= 0:
                _type = 3
            elif chg > 0 and chg <= 3:
                _type = 4
            elif chg > 3 and chg <= 7:
                _type = 5
            else:
                _type = 6

            _has = mysql.fetch_one("select * from  s_status where s_t=%s" % unixtime)
            #print res
            #sys.exit()
            _where = "s_t=%s" % unixtime
            _field = "t_%s" % _type
            res = {'s_t': unixtime, _field: 1}
            #print res
            #sys.exit()
            if _has is not None:
                mysql.dbQuery('update s_status set %s=%s+1 where %s' % (_field, _field, _where))
            else:
                mysql.dbInsert('s_status', res)

        time.sleep(65)
Пример #3
0
    arr['run_script'] = "php /htdocs/soga/trader/index.php XueQiu get_xq_user_from_follows %s "
    return arr


def get_xq_title(params):
    arr = {}
    arr['sql'] = "SELECT user_id FROM user_xq WHERE original_count>30 and followers_count >=80 ORDER BY  original_count DESC"
    arr['limit'] = 15
    arr['run_script'] = "php /htdocs/soga/trader/index.php XueQiu get_xq_title %s "
    return arr


if __name__ == '__main__':
    mysql = sMysql('127.0.0.1', 'root', '1234asdf', 'stock')
    spider = SpiderEngine()
    sTools = sTools()

print sys.argv

function = eval(sys.argv[1])
params = 0
if (len(sys.argv) == 3):
    params = sys.argv[2]

#build params
script = function(params)

run_worker_template(script)

sys.exit()
Пример #4
0
 def __init__(self, name, setting):
     self.bk_start = time.clock()
     print sys.argv
     self.tools = sTools()
     self.init(setting)
Пример #5
0
# -*- coding: utf-8 -*-
import sys
import pandas
import hashlib
import math
from settings import *
from quant.core.DB import sMysql
from quant.tools.Util import sTools
tools = sTools()


class Average(object):

    def __init__(self):
        self.mysql = sMysql(MYSQL_DB['host'], MYSQL_DB['user'], MYSQL_DB['password'], MYSQL_DB['dbname'])

    def getChuQuan(self, s_code):
        '''获取历史除权数据,重写open and s_code in('sh600365')'''
        chuQuan = pandas.read_sql("select s_code,dateline,factor from s_stock_fuquan where 1 and s_code in('%s') order by dateline DESC" % s_code, self.mysql.db)

        _chQ = {}
        _fa = 1
        #只有一条记录的特殊处理
        if len(chuQuan) == 1:
            print chuQuan.iloc[0].dateline
            _chQ[s_code] = []
            _chQ[s_code].append({'start': 0, 'end': chuQuan.iloc[0].dateline, 'factor': chuQuan.iloc[0].factor})
            _chQ[s_code].append({'start': chuQuan.iloc[0].dateline, 'end': tools.d_date('%Y%m%d'), 'factor': 1})

        else:
            for i in range(len(chuQuan)):
Пример #6
0
 def __init__(self):
     self.tools = sTools()
     self.benchmart_start = time.clock()
     self.__read_config()
     mysql_db = self.config['mysql']['stock']
     self.mysql = sMysql(mysql_db['host'], mysql_db['user'], mysql_db['password'], mysql_db['dbname'])
Пример #7
0
def main_elasticsearch():
    es = Elasticsearch(host="localhost", port="9200")
    tools = sTools()
    today = tools.d_date('%Y%m%d')
    #today = 20160112
    #print today
    #sys.exit()
    data = mysql.getRecord("select * from s_stock_list where dateline=%s " % today)

    tags = mysql.getRecord("select s_code,category_name from s_stock_cate_list where 1")
    tags_list = {}
    for i in range(len(tags)):
        if tags[i][0] not in tags_list.keys():
            tags_list[tags[i][0]] = [tags[i][1]]
        else:
            tags_list[tags[i][0]].append(tags[i][1])

    i = 1
    for row in data:
        row = list(row)
        tagss = ''
        if row[2] in tags_list.keys():
            tags_ids = tags_list[row[2]]
            tagss = ','.join(list(set(tags_ids)))
        #取财务指标
        s_code = row[2]
        #s_code = 'sh600836'
        tes = mysql.fetch_one("select * from s_company_finance where code=%s order by reportdate desc limit 1" % s_code[2:])

        if tes is None:
            tes = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        average = mysql.fetch_one("select * from s_stock_average where s_code ='%s' and dateline=%s" % (s_code, today))
        if average is None:
            average = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        doc = {
            's_code': s_code,
            'name': row[6],
            'tagss': tagss,
            'last_close': row[8],
            'open': row[9],
            'close': row[10],
            'high': row[11],
            'low': row[12],
            'chg': row[13],
            'chg_m': row[14],
            'volumes': row[15]/100,
            'amount': row[16]/10000,
            'now_zf': row[17],
            'turnover': row[18],
            'run_market': row[19]/100000000,
            'all_market': row[20]/100000000,
            'reportdate': tes[2],
            'basiceps': tes[3],                 # 基本每股收益
            'epsweighted': tes[4],              # 每股收益(加权)
            'epsdiluted': tes[5],               # 每股收益(摊薄)
            'naps': tes[6],                     # 每股净资产
            'opercashpershare': tes[7],         # 每股现金流
            'peropecashpershare': tes[8],       # 每股经营性现金流
            'netassgrowrate': tes[9],           # 净资产增长率(%)
            'netincgrowrate': tes[13],          # 净利润增长率(%)
            'salegrossprofitrto': tes[15],      # 销售毛利率

            'on_ma5': average[4],
            'on_ma10': average[5],
            'on_ma20': average[6],
            'on_ma30': average[7],
            'on_ma60': average[8],
        }
        #print doc
        #sys.exit()
        es.index(index="stock8", doc_type='info', id=i, body=doc)
        #sys.exit()
        i += 1
    es.indices.refresh(index="stock8")