Last active
February 25, 2019 06:11
-
-
Save caspartse/5b9c6aa90bbadcaefc08313de9c3c3b9 to your computer and use it in GitHub Desktop.
京东基金播报
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
| #!/usr/bin/env python | |
| # -*- coding:utf-8 -*- | |
| import time | |
| import requests | |
| import re | |
| import json | |
| import os | |
| import notify2 | |
| fundcodes = ['110022', '001740', '001542', '000742', '001583'] | |
| message = [] | |
| for fc in fundcodes: | |
| _callback = 'jQuery18306035377581313748_%d' % (time.time() * 1000) | |
| url = 'http://dp.jr.jd.com/service/fundValuation/%s.do' % (fc) | |
| params = { | |
| 'callback': '', | |
| '_': '%d' % (time.time() * 1000) | |
| } | |
| resp = requests.get(url, params=params) | |
| pattern = re.compile(r'^%s|\)$' % (_callback)) | |
| result = json.loads(re.sub(pattern, '', resp.content))[0] | |
| name = result['fundShortName'] | |
| currentRating = '%+.4f%%' % (float(result['currentRating'])) | |
| data = result['data'] | |
| if data: | |
| for i, v in enumerate(data): | |
| if data[i][-2] is None: | |
| break | |
| if i < 11: | |
| state = '' | |
| else: | |
| now = data[i - 1][-2] | |
| before = data[i - 11][-2] | |
| # print now, before | |
| if before is None: | |
| before = 0.0 | |
| if now > before: | |
| state = u'↑' | |
| elif now < before: | |
| state = u'↓' | |
| else: | |
| state = u'→' | |
| digest = '%s %s %s' % ( | |
| name, | |
| currentRating, | |
| state | |
| ) | |
| # print digest | |
| message.append(digest) | |
| if message: | |
| os.environ.setdefault('DISPLAY', ':0.0') | |
| notify2.init('Funds') | |
| n = notify2.Notification( | |
| '', | |
| '\n'.join(message) | |
| ) | |
| n.show() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment