def doDataUpdate(): times = str(int(time.time())) # 损益表 finalcialIncreaseUrl = 'https://xueqiu.com/stock/f10/incstatement.json?symbol=' \ + stockCodes + '&page=1&size=500&_=' + times finalcialDebatUrl = 'https://xueqiu.com/stock/f10/balsheet.json?symbol=' \ + stockCodes + '&page=1&size=500&_=' + times finalcialCashUrl = 'https://xueqiu.com/stock/f10/cfstatement.json?symbol=' \ + stockCodes + '&page=1&size=500&_=' + times # 获取数据 httpMethod = 'GET' decode = rpc.getResponse(finalcialIncreaseUrl, httpMethod, data) decode2 = rpc.getResponse(finalcialDebatUrl, httpMethod, data) decode3 = rpc.getResponse(finalcialCashUrl, httpMethod, data) # 打开数据库连接 db = rpc.getPyMySQLConnection() # 使用cursor()方法获取操作游标 cursor = db.cursor() try: # 更新损益财务指标 addData(tableType='1', data=decode, cursor=cursor, db=db, description='利润指标', dateName='enddate') # 更新负债指标 addData(tableType='2', data=decode2, cursor=cursor, db=db, description='负债指标', dateName='reportdate') # 更新现金流指标 addData(tableType='3', data=decode3, cursor=cursor, db=db, description='现金流指标', dateName='enddate') except Exception, e: print e db.rollback()
# 公司基本经营信息获取 print '更新公司基本信息:', str(sys.argv[1]), str(sys.argv[2]) # 参数 reqdata = {'symbol': 'SZ002561', 'page': 1, 'size': 1, '_': 1502605245564} data = urllib.urlencode(reqdata) stockCode = sys.argv[2] stockCodes = sys.argv[1] + sys.argv[2] finalcialUrl = 'https://xueqiu.com/stock/f10/compinfo.json?symbol=' + stockCodes + '&page=1&size=4&_=150313634190' httpMethod = 'GET' # 获取数据 decode = rpc.getResponse(finalcialUrl, httpMethod, data) company = decode['tqCompInfo'] # 公司地址 addr = company['officeaddr'] # 公司名称 compname = company['compname'] # 创建时间 founddate = company['founddate'] orgtype = company['orgtype'] regcapital = company['regcapital'] * 10000 print addr, compname, founddate, orgtype, regcapital quit() # 打开数据库连接