|
业余时间写的,代码比较粗糙。实现时时彩开奖结果采集,并支持http请求获取结果。- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # author: CrazyWolf
- # qq: 4850498
- import requests
- from pyquery import PyQuery as pq
- from flask import Flask
- app = Flask(__name__)
- def check_shape(number):
- idx = 0
- for i in range(2, 0, -1):
- for j in range(i):
- if number[i + 2] == number[j + 2]:
- idx += 1
- if idx is 0:
- shape = u'组六'
- elif idx is 1:
- shape = u'组三'
- else:
- shape = u'豹子'
- return shape
- def parse(text):
- result = {}
- if not text:
- return None
- doc = pq(text)
- table = doc('table.awardList')
- td_start = table('td.start')
- for ts in td_start.items():
- stage = ts.text().decode('utf-8')
- number = ts.attr['data-win-number']
- #
- if number:
- number = number.replace(' ', '').decode('utf-8')
- result[stage] = number
- # return sorted(result.items(), key=lambda result: result[0], reverse=True)
- return sorted(result.items(), key=lambda result: result[0])
- @app.route('/cqssc')
- def get_ssc():
- ret = ''
- show_num = 1
- url = 'http://caipiao.163.com/award/cqssc/'
- resp = requests.get(url=url)
- if not resp.ok:
- return None
- result = parse(resp.text)
- ret += u'重庆时时彩报号\r\n'
- ret += u'--------------------------\r\n'
- if len(result) >= 10:
- for k, v in result[-10:]:
- if v is not None:
- ret += u'{0}期: 【{1}】 {2}\r\n'.format(k, v, check_shape(v))
- if show_num is 9:
- ret += u'--------------------------\r\n'
- show_num += 1
- if show_num > 10:
- break
- else:
- for k, v in result:
- if v is not None:
- ret += u'{0}期: 【{1}】 {2}\r\n'.format(k, v, check_shape(v))
- if show_num is len(result) - 1:
- ret += u'--------------------------\r\n'
- show_num += 1
- if show_num > len(result):
- break
- return ret
- def main():
- app.run('0.0.0.0', 8080)
- if __name__ == '__main__':
- main()
复制代码 脚本运行效果图:
cqssc-result
还可以通过链接查询结果
http://本机IP:8080/cqssc
|
|