Skip to content

Commit

Permalink
fixed base demo19 & add base demo20
Browse files Browse the repository at this point in the history
  • Loading branch information
mgss committed Nov 9, 2017
1 parent fe96d0d commit fc37a6e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## 目录


* [Python基础语法练习](https://github.com/mgss/python-demo/blob/master/docs/basic.md) (19)
* [Python基础语法练习](https://github.com/mgss/python-demo/blob/master/docs/basic.md) (20)
* [Python基本算法练习](https://github.com/mgss/python-demo/blob/master/docs/algo.md) (2)
* Python面向对象
* python网络编程
Expand Down
6 changes: 6 additions & 0 deletions docs/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,9 @@ PS:字典中的value只能是字符串或列表
* 实现命令行进度条,带百分比

参考Demo:[链接](https://github.com/mgss/python-demo/blob/master/example/basic/demo19.py)

## Demo-20

* 利用第三方接口实现输入QQ号判断是否在线

参考Demo:[链接](https://github.com/mgss/python-demo/blob/master/example/basic/demo20.py)
2 changes: 1 addition & 1 deletion example/basic/demo19.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sys.stdout.write("\r")

# 显示百分比和进度条
sys.stdout.write("[%s%%|%s%s]" % (i, i * ('█'), (100 - i) * ('░')))
sys.stdout.write("[%s%%|%-100s]" % (i, i * ('█')))

# 从缓存刷入到屏幕
sys.stdout.flush()
Expand Down
32 changes: 32 additions & 0 deletions example/basic/demo20.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-

# 利用第三方接口实现输入QQ号判断是否在线

import requests
from xml.etree import ElementTree as ET


def is_online(qq_num):
data = requests.get("http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx/qqCheckOnline?qqcode=%s" % qq_num)
result = data.text
node = ET.XML(result)

return node.text


def main():
inp = input("请输入要查询的QQ号:")
result = is_online(inp)
if result == "Y":
print("[%s]在线" % inp)
elif result == "N":
print("[%s]离线" % inp)
elif result == "E":
print("QQ号码错误!")
else:
print("您输入的内容有误!")


if __name__ == '__main__':
main()

0 comments on commit fc37a6e

Please sign in to comment.