Last active
August 29, 2015 14:07
-
-
Save yuercl/94c4c61fc8374c3fb22d to your computer and use it in GitHub Desktop.
Stock.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#!/usr/bin/python | |
__author__ = 'Long' | |
import json | |
import os | |
import os.path | |
import time | |
import sys | |
import subprocess | |
if __name__ == "__main__": | |
array = [] | |
config = ''' | |
[ | |
{ | |
"stock":"000017", | |
"amount":1629.84, | |
"name":"kechixu", | |
"cost":5000, | |
"done":2690.98 | |
},{ | |
"stock":"233009", | |
"amount":1263.13, | |
"name":"damo", | |
"cost":4000, | |
"done":2185.92 | |
},{ | |
"stock":"161024", | |
"amount":0, | |
"name":"jungong", | |
"cost":4000, | |
"done":4424.81 | |
},{ | |
"stock":"000550", | |
"amount":1530.30, | |
"name":"xindongli", | |
"cost":4000, | |
"done":2606.25 | |
},{ | |
"stock":"519983", | |
"amount":0, | |
"name":"changxinlianghua", | |
"cost":5000, | |
"done":5430.00 | |
} | |
] | |
''' | |
stocks = json.loads(config) | |
total = 0 | |
index = 0 | |
cost = 0 | |
dones = 0 | |
print 'Calculation of earnings...' | |
os.system('date') | |
for stock in stocks: | |
cmd = "curl -s http://fund.eastmoney.com/%s.html?spm=aladin | sed -n '/statuspzgz/p' | sed 's/<\/span>/<\/span>\\n/g' | sed -n '/statuspzgz/p' | sed 's/>/ /g' | sed 's/</ /g' | awk '{print $8}'" % \ | |
stock['stock'] | |
result = subprocess.check_output(cmd, shell=True) | |
result = result.strip() | |
now = float(result)*stock['amount'] | |
print 'Code: %s , Price: %s , Amount: %s , Cost: %s , Total: %s ,Done: %s , Percent: %s' % (stock['stock'] , result , stock['amount'] , stock['cost'] , now , stock['done'], (now + stock['done'] - stock['cost'] ) / stock['cost']) | |
total = total + float(result)*stock['amount'] | |
cost = cost + stock['cost'] | |
dones = dones + stock['done'] | |
print "Cost: %s , Total: %s , Win: %s , Dones: %s , Percent: %s" % (cost , total , (total + dones - cost) , dones ,(total + dones - cost) / cost) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mac 下sed存在问题,需要安装gnu-sed,然后替换sed为gsed,在Vim里0,$s/sed/gsed/g