#coding=utf-8
import os, io, sys, re, time, json, base64
import webbrowser, urllib.request
period_All_List = [
"min",
"daily",
"weekly",
"monthly"
]
period_min = period_All_List[0]
ChinaStockIndividualList = [
"600801",#股票代码
"002511"#
]
#键值对
ChinaStockIndividualList2 = {
"600801":11.602,#股票代码,成本价
"002511":14.469#股票代码,成本价
}
bodong = 0
def getChinaStockIndividualInfo(stockCode, period):
try:
exchange = "sh" if (int(stockCode) // 100000 == 6) else "sz"
dataUrl = "http://hq.sinajs.cn/list=" + exchange + stockCode
stdout = urllib.request.urlopen(dataUrl)
stdoutInfo = stdout.read().decode('gb2312')
tempData = re.search('''(")(.+)(")''', stdoutInfo).group(2)
stockInfo = tempData.split(",")
stockName = stockInfo[0]
stockStart = stockInfo[1]
stockLastEnd= stockInfo[2]
stockCur = stockInfo[3]
stockMax = stockInfo[4]
stockMin = stockInfo[5]
stockUp = round(float(stockCur) - float(stockLastEnd), 2)
stockRange = round(float(stockUp) / float(stockLastEnd), 2) * 100
stockVolume = round(float(stockInfo[8]) / (100 * 10000), 2)
stockMoney = round(float(stockInfo[9]) / (100000000), 2)
stockTime = stockInfo[31]
stockUpRate = round((float(stockUp)/float(stockLastEnd)),3)*100
content = "" + stockName + "(" + stockCode + ")\n" + "当前:" + stockCur+",昨收:"+str(stockLastEnd)\
+ ",涨跌:" + str(stockUp)+" ,比例:"+str(stockUpRate)+"%"
twitter = {'message': content}
except Exception as e:
print(">>>>>> Exception: " + str(e))
else:
return content
#return twitter
finally:
None
def getChinaStockIndividualInfo2(stockCode, period,stockCodeValue):
try:
exchange = "sh" if (int(stockCode) // 100000 == 6) else "sz"
dataUrl = "http://hq.sinajs.cn/list=" + exchange + stockCode
stdout = urllib.request.urlopen(dataUrl)
stdoutInfo = stdout.read().decode('gb2312')
tempData = re.search('''(")(.+)(")''', stdoutInfo).group(2)
stockInfo = tempData.split(",")
stockName = stockInfo[0]
stockStart = stockInfo[1]
stockLastEnd= stockInfo[2]
stockCur = stockInfo[3]
stockMax = stockInfo[4]
stockMin = stockInfo[5]
stockUp = round(float(stockCur) - float(stockLastEnd), 2)
stockRange = round(float(stockUp) / float(stockLastEnd), 2) * 100
stockVolume = round(float(stockInfo[8]) / (100 * 10000), 2)
stockMoney = round(float(stockInfo[9]) / (100000000), 2)
stockTime = stockInfo[31]
stockUpRate ="%.2f" %(round((float(stockUp)/float(stockLastEnd)),3)*100)#格式化输出
zenfu = round((float(stockCur)-stockCodeValue),3)
content =stockName + "(" + stockCode + ")\n" + "当前价:" + stockCur+", 昨天收盘价:"+str(stockLastEnd)\
+ ", 波动幅度:" + str(stockUp)+", 波动比率:"+str(stockUpRate)+"%"+", 总涨跌幅度:"+str(zenfu)
twitter = {'message': content}
except Exception as e:
print(">>>>>> Exception: " + str(e))
else:
return content
#return twitter
finally:
None
def test_china_individual_data2():
for stockCodeKey,stockCodeValue in ChinaStockIndividualList2.items():
#print(type(stockCodeKey),type(stockCodeValue)) #字符串型,浮点型
twitter = getChinaStockIndividualInfo2(stockCodeKey, period_min,stockCodeValue)
print(twitter)
# print(twitter['message'])
def test_china_individual_data():
for stockCodeKey in ChinaStockIndividualList:
twitter = getChinaStockIndividualInfo(stockCodeKey, period_min)
print(twitter)
# print(twitter['message'])
def main():
"main function"
print(base64.b64decode(b'Q29we**Z2h0IChjKSAyMDEyIERvdWN1YmUgSW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLg==').decode())
print("\n")
test_china_individual_data2()
if __name__ == '__main__':
main()
阅读(1900) | 评论(0) | 转发(0) |
0
上一篇:没有了
下一篇:没有了