├── Day01-15 ├── Day03 │ ├── .py │ ├── piecewise.py │ ├── convert.py │ ├── rolldice.py │ ├── verify.py │ ├── grade.py │ ├── triangle.py │ └── tax.py ├── Day11 │ ├── .py │ ├── teacher.csv │ ├── mm.jpg │ ├── 致橡树.txt │ ├── res │ │ └── file-open-mode.png │ ├── example.csv │ ├── ex4.py │ ├── file2.py │ ├── ex2.py │ ├── file4.py │ ├── csv1.py │ ├── json2.py │ ├── ex1.py │ ├── file3.py │ ├── ex3.py │ ├── file1.py │ ├── csv2.py │ └── json1.py ├── Day08 │ ├── test.py │ ├── res │ │ ├── oop-zhihu.png │ │ └── object-feature.png │ ├── access.py │ ├── hack.py │ ├── rect.py │ ├── student.py │ ├── circle.py │ ├── guess.py │ └── clock.py ├── Day05 │ ├── 总结和练习.md │ ├── table.py │ ├── fibonacci.py │ ├── lily.py │ ├── prime.py │ ├── chicken.py │ ├── palindrome.py │ ├── guess.py │ ├── perfect.py │ └── craps.py ├── Day14 │ ├── guido.jpg │ ├── res │ │ ├── arpanet.png │ │ ├── browers.jpg │ │ ├── osi_rm.gif │ │ ├── osimodel.png │ │ ├── telnet.png │ │ ├── TCP-IP-model.png │ │ ├── after-browser.jpg │ │ ├── before-browser.jpg │ │ ├── tcpipprotocols.png │ │ ├── browser-market-place.jpeg │ │ └── how-data-is-processed.jpg │ ├── timeclient.py │ ├── socket3.py │ ├── socket2.py │ ├── socket4.py │ ├── socket5.py │ ├── socket1.py │ ├── fileclient.py │ ├── mmdownloader.py │ ├── chatclient.py │ ├── timeserver.py │ ├── chatserver.py │ └── fileserver.py ├── Day10 │ ├── res │ │ ├── ball.png │ │ └── ball-game.png │ ├── turtle1.py │ ├── gui3.py │ ├── gui2.py │ └── gui1.py ├── Day07 │ ├── res │ │ ├── python-set.png │ │ ├── ipython-timeit.png │ │ └── fibonacci-blocks.png │ ├── fibonacci.py │ ├── marquee.py │ ├── dict2.py │ ├── avgscore.py │ ├── findmax.py │ ├── dict1.py │ ├── list2.py │ ├── yanghui.py │ ├── scoretable.py │ ├── list1.py │ ├── set1.py │ ├── tuple.py │ ├── set2.py │ ├── list3.py │ ├── lottery.py │ └── tic-tac-toe.py ├── Day01 │ ├── res │ │ ├── python-idle.png │ │ ├── python-ipython.png │ │ ├── python-pycharm.png │ │ ├── python-sublime.png │ │ ├── python-jupyter-1.png │ │ └── python-jupyter-2.png │ └── hello.py ├── Day09 │ ├── res │ │ ├── uml-example.png │ │ └── uml-components.png │ ├── diamond.py │ ├── pet.py │ ├── car2.py │ ├── clock.py │ ├── triangle.py │ ├── shape.py │ ├── multi.py │ ├── car1.py │ ├── association.py │ ├── employee.py │ └── dependency.py ├── Day13 │ ├── res │ │ └── macos-monitor.png │ ├── generator2.py │ ├── multiprocess4.py │ ├── generator1.py │ ├── multiprocess3.py │ ├── asyncio2.py │ ├── singlethread1.py │ ├── asyncio1.py │ ├── multiprocess2.py │ ├── multiprocess1.py │ ├── multithread2.py │ ├── coroutine1.py │ ├── multithread6.py │ ├── asyncio3.py │ ├── coroutine2.py │ ├── multithread3.py │ ├── multithread1.py │ ├── singlethread2.py │ ├── test2.py │ ├── multithread4.py │ └── multithread5.py ├── Day12 │ ├── res │ │ └── tel-start-number.png │ ├── test5.py │ ├── test3.py │ ├── test4.py │ ├── str1.py │ └── str2.py ├── Day04 │ ├── for2.py │ ├── for1.py │ ├── while1.py │ ├── while2.py │ ├── for3.py │ ├── for5.py │ ├── for4.py │ └── for6.py ├── Day02 │ ├── centigrade.py │ ├── variable1.py │ ├── leap.py │ ├── variable2.py │ ├── circle.py │ ├── variable4.py │ ├── variable3.py │ ├── operator.py │ ├── string.py │ └── variable5.py └── Day06 │ ├── function1.py │ ├── function2.py │ ├── function6.py │ ├── function3.py │ ├── function5.py │ └── function4.py ├── Day56-65 ├── 数据库操作.md ├── 模板的使用.md ├── 表单的处理.md ├── Flask安装和入门.md ├── Flask项目实战.md └── 使用Flask进行项目开发.md ├── Day76-90 ├── 机器学习.md └── 数据处理和可视化.md ├── Day41-55 ├── Django2项目实战.md ├── oa │ ├── hrs │ │ ├── __init__.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ ├── 0003_auto_20180524_1646.py │ │ │ ├── 0002_auto_20180523_0923.py │ │ │ └── 0001_initial.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── urls.py │ │ ├── admin.py │ │ ├── models.py │ │ └── views.py │ ├── oa │ │ ├── __init__.py │ │ ├── wsgi.py │ │ └── urls.py │ ├── static │ │ └── images │ │ │ └── mm.jpg │ ├── templates │ │ └── index.html │ └── manage.py ├── car │ ├── search │ │ ├── __init__.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ ├── 0002_auto_20180524_1420.py │ │ │ └── 0001_initial.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── admin.py │ │ └── models.py │ ├── car │ │ ├── __init__.py │ │ ├── wsgi.py │ │ └── urls.py │ ├── static │ │ └── images │ │ │ ├── icon-yes.svg │ │ │ └── icon-no.svg │ ├── manage.py │ └── templates │ │ └── add.html ├── shop │ ├── cart │ │ ├── __init__.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ └── 0001_initial.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── admin.py │ │ └── models.py │ ├── shop │ │ ├── __init__.py │ │ ├── wsgi.py │ │ └── urls.py │ ├── static │ │ └── images │ │ │ ├── lay.jpg │ │ │ ├── oil.jpg │ │ │ ├── wang.jpg │ │ │ ├── wine.jpg │ │ │ ├── Thumbs.db │ │ │ ├── dolbee.jpg │ │ │ └── noodle.jpg │ ├── manage.py │ └── templates │ │ ├── goods.html │ │ └── cart.html ├── shop_origin │ ├── cart │ │ ├── __init__.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ └── 0001_initial.py │ │ ├── tests.py │ │ ├── apps.py │ │ ├── admin.py │ │ ├── views.py │ │ └── models.py │ ├── shop │ │ ├── __init__.py │ │ ├── wsgi.py │ │ └── urls.py │ ├── static │ │ └── images │ │ │ ├── lay.jpg │ │ │ ├── oil.jpg │ │ │ ├── wang.jpg │ │ │ ├── wine.jpg │ │ │ ├── dolbee.jpg │ │ │ └── noodle.jpg │ ├── shop_create_sql.sql │ ├── manage.py │ └── templates │ │ ├── goods.html │ │ └── cart.html ├── Django2实战04.md ├── Django2实战03.md ├── Django2实战06.md ├── Django2实战05.md ├── Django2实战07.md ├── Django2实战08.md ├── Django2实战09.md ├── Django2实战10.md └── res │ ├── mvc.png │ ├── er-graph.png │ ├── runserver.png │ ├── admin-login.png │ ├── admin-model.png │ ├── admin-welcome.png │ ├── django-index-1.png │ ├── django-index-2.png │ ├── http-request.png │ ├── http-response.png │ ├── admin-model-emps.png │ ├── admin-model-read.png │ ├── web-application.png │ ├── admin-model-create.png │ ├── admin-model-depts.png │ ├── admin-model-emps-modified.png │ └── admin-model-delete-and-update.png ├── Day91-100 └── 团队项目开发.md ├── Day66-75 ├── code │ ├── douban │ │ ├── douban │ │ │ ├── __init__.py │ │ │ ├── spiders │ │ │ │ ├── __init__.py │ │ │ │ └── movie.py │ │ │ ├── items.py │ │ │ └── pipelines.py │ │ └── scrapy.cfg │ ├── image360 │ │ ├── image360 │ │ │ ├── __init__.py │ │ │ ├── spiders │ │ │ │ ├── __init__.py │ │ │ │ ├── image.py │ │ │ │ └── taobao.py │ │ │ ├── items.py │ │ │ └── pipelines.py │ │ └── scrapy.cfg │ ├── guido.jpg │ ├── tesseract.png │ ├── myutils.py │ ├── example10.py │ ├── generator02.py │ ├── generator01.py │ ├── example09.py │ ├── asyncio01.py │ ├── coroutine01.py │ ├── example11.py │ ├── asyncio02.py │ ├── example03.py │ ├── example08.py │ ├── example04.py │ ├── example12.py │ ├── coroutine02.py │ ├── example07.py │ └── example06.py ├── res │ ├── postman.png │ ├── redis-aof.png │ ├── redis-rdb.png │ ├── tesseract.gif │ ├── redis-bind.png │ ├── redis-port.png │ ├── redis-save.png │ ├── douban-xpath.png │ ├── http-request.png │ ├── http-response.png │ ├── redis-database.png │ ├── redis-security.png │ ├── redis-slow-log.png │ ├── crawler-workflow.png │ ├── baidu-search-taobao.png │ ├── redis-replication.png │ ├── scrapy-architecture.png │ └── chrome-developer-tools.png ├── 05.解析动态内容.md ├── 06.表单交互和验证码处理.md ├── Scrapy爬虫框架分布式实现.md └── Scrapy爬虫框架高级应用.md ├── Day16-20 └── Python语言进阶.md ├── .gitignore ├── res ├── modularity.png ├── concurrency.png ├── encapsulation.png ├── object-roles.png ├── python-salary.png ├── python-top-10.png ├── result-of-dis.png ├── zen-of-python.png ├── pycharm-plugins.png ├── pycharm-welcome.png ├── python-job-all.png ├── abstraction-view.png ├── class-and-object.png ├── int-is-comparation.png ├── multi-inheritance.png ├── objects-lifetime.png ├── pycharm-activate.png ├── pycharm-workspace.png ├── python-bj-salary.png ├── python-cd-salary.png ├── python-job-chengdu.png ├── objects-collaborate.png ├── pycharm-new-project.png ├── pycharm-set-ui-theme.png ├── pycharm-import-settings.png ├── python-salary-beijing.png ├── python-salary-chengdu.png ├── python-salary-hangzhou.png ├── python-salary-shanghai.png ├── python-salary-shenzhen.png ├── python-tutor-visualize.png ├── python-tutor-visualize2.png ├── python-built-in-functions.png └── pycharm-create-launcher-script.png ├── Day21-30 ├── img │ ├── a1.jpg │ ├── a2.jpg │ ├── a3.jpg │ └── Thumbs.db ├── res │ ├── dom-page.png │ ├── dom-tree.png │ ├── browser-joke-2.jpg │ ├── browser-joke-3.jpg │ └── browser-joke-1.jpeg ├── qq_link.html └── example.html ├── Day31-35 └── res │ ├── Stallman.jpg │ ├── Tanenbaum.jpg │ ├── Dennis-Ritchie.jpg │ ├── Ken-Thompson.png │ ├── Linus-Torvalds.jpg │ ├── history-of-os.png │ ├── history-of-unix.png │ └── linux-network-config.png ├── Day36-40 ├── res │ ├── IMG_0358.PNG │ ├── IMG_0360.png │ ├── IMG_0361.png │ ├── IMG_0362.png │ ├── IMG_0363.png │ ├── IMG_0364.png │ ├── IMG_0365.png │ ├── IMG_0366.png │ └── redis-data-type.png ├── NoSQL入门.md └── 关系型数据库MySQL.md └── PEP 8风格指南.md /Day01-15/Day03/.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day01-15/Day11/.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day56-65/数据库操作.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day56-65/模板的使用.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day56-65/表单的处理.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day76-90/机器学习.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day01-15/Day08/test.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day41-55/Django2项目实战.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day56-65/Flask安装和入门.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day56-65/Flask项目实战.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day76-90/数据处理和可视化.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day91-100/团队项目开发.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day56-65/使用Flask进行项目开发.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day41-55/car/search/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day41-55/shop/cart/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day01-15/Day05/总结和练习.md: -------------------------------------------------------------------------------- 1 | ## 总结和练习 2 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/cart/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day41-55/car/search/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day41-55/shop/cart/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day66-75/code/douban/douban/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day66-75/code/image360/image360/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day16-20/Python语言进阶.md: -------------------------------------------------------------------------------- 1 | ## Python进阶知识 2 | 3 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/cart/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Day01-15/Day11/teacher.csv: -------------------------------------------------------------------------------- 1 | 骆昊,38,叫兽 2 | 狄仁杰,25,砖家 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | venv 2 | .idea 3 | *.pyc 4 | __pycache__ 5 | 6 | -------------------------------------------------------------------------------- /Day41-55/Django2实战04.md: -------------------------------------------------------------------------------- 1 | ## Django 2.x实战(04) - 表单的应用 2 | 3 | -------------------------------------------------------------------------------- /Day41-55/Django2实战03.md: -------------------------------------------------------------------------------- 1 | ## Django 2.x实战(03) - 视图、模板和URL 2 | 3 | -------------------------------------------------------------------------------- /Day41-55/Django2实战06.md: -------------------------------------------------------------------------------- 1 | ## Django 2.x实战(06) - 日志和缓存 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Day41-55/Django2实战05.md: -------------------------------------------------------------------------------- 1 | ## Django 2.x实战(05) - Cookie和会话 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Day41-55/Django2实战07.md: -------------------------------------------------------------------------------- 1 | ## Django 2.x实战(07) - 文件上传和通用视图 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Day41-55/Django2实战08.md: -------------------------------------------------------------------------------- 1 | ## Django 2.x实战(08) - 用户/角色/权限和中间件 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Day41-55/Django2实战09.md: -------------------------------------------------------------------------------- 1 | ## Django 2.x实战(09) - RESTful架构和应用(上) 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Day41-55/Django2实战10.md: -------------------------------------------------------------------------------- 1 | ## Django 2.x实战(10) - RESTful架构和应用(下) 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Day41-55/car/car/__init__.py: -------------------------------------------------------------------------------- 1 | import pymysql 2 | 3 | pymysql.install_as_MySQLdb() -------------------------------------------------------------------------------- /Day41-55/oa/oa/__init__.py: -------------------------------------------------------------------------------- 1 | import pymysql 2 | 3 | pymysql.install_as_MySQLdb() 4 | -------------------------------------------------------------------------------- /Day41-55/shop/shop/__init__.py: -------------------------------------------------------------------------------- 1 | import pymysql 2 | 3 | pymysql.install_as_MySQLdb() 4 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/shop/__init__.py: -------------------------------------------------------------------------------- 1 | import pymysql 2 | 3 | pymysql.install_as_MySQLdb() -------------------------------------------------------------------------------- /Day41-55/oa/hrs/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /res/modularity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/modularity.png -------------------------------------------------------------------------------- /Day01-15/Day11/mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day11/mm.jpg -------------------------------------------------------------------------------- /Day01-15/Day11/致橡树.txt: -------------------------------------------------------------------------------- 1 | 我如果爱你 2 | 绝不学攀援的凌霄花 3 | 借你的高枝炫耀自己 4 | 5 | 我如果爱你 6 | 绝不学痴情的鸟儿 7 | 为绿荫重复单调的歌曲 8 | -------------------------------------------------------------------------------- /Day21-30/img/a1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/img/a1.jpg -------------------------------------------------------------------------------- /Day21-30/img/a2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/img/a2.jpg -------------------------------------------------------------------------------- /Day21-30/img/a3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/img/a3.jpg -------------------------------------------------------------------------------- /Day41-55/car/search/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Day41-55/res/mvc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/mvc.png -------------------------------------------------------------------------------- /Day41-55/shop/cart/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /res/concurrency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/concurrency.png -------------------------------------------------------------------------------- /res/encapsulation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/encapsulation.png -------------------------------------------------------------------------------- /res/object-roles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/object-roles.png -------------------------------------------------------------------------------- /res/python-salary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-salary.png -------------------------------------------------------------------------------- /res/python-top-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-top-10.png -------------------------------------------------------------------------------- /res/result-of-dis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/result-of-dis.png -------------------------------------------------------------------------------- /res/zen-of-python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/zen-of-python.png -------------------------------------------------------------------------------- /Day21-30/img/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/img/Thumbs.db -------------------------------------------------------------------------------- /Day41-55/shop_origin/cart/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Day66-75/code/guido.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/code/guido.jpg -------------------------------------------------------------------------------- /res/pycharm-plugins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/pycharm-plugins.png -------------------------------------------------------------------------------- /res/pycharm-welcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/pycharm-welcome.png -------------------------------------------------------------------------------- /res/python-job-all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-job-all.png -------------------------------------------------------------------------------- /Day01-15/Day14/guido.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/guido.jpg -------------------------------------------------------------------------------- /Day21-30/res/dom-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/res/dom-page.png -------------------------------------------------------------------------------- /Day21-30/res/dom-tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/res/dom-tree.png -------------------------------------------------------------------------------- /Day31-35/res/Stallman.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day31-35/res/Stallman.jpg -------------------------------------------------------------------------------- /Day31-35/res/Tanenbaum.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day31-35/res/Tanenbaum.jpg -------------------------------------------------------------------------------- /Day36-40/res/IMG_0358.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/IMG_0358.PNG -------------------------------------------------------------------------------- /Day36-40/res/IMG_0360.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/IMG_0360.png -------------------------------------------------------------------------------- /Day36-40/res/IMG_0361.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/IMG_0361.png -------------------------------------------------------------------------------- /Day36-40/res/IMG_0362.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/IMG_0362.png -------------------------------------------------------------------------------- /Day36-40/res/IMG_0363.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/IMG_0363.png -------------------------------------------------------------------------------- /Day36-40/res/IMG_0364.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/IMG_0364.png -------------------------------------------------------------------------------- /Day36-40/res/IMG_0365.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/IMG_0365.png -------------------------------------------------------------------------------- /Day36-40/res/IMG_0366.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/IMG_0366.png -------------------------------------------------------------------------------- /Day41-55/res/er-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/er-graph.png -------------------------------------------------------------------------------- /Day41-55/res/runserver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/runserver.png -------------------------------------------------------------------------------- /Day66-75/res/postman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/postman.png -------------------------------------------------------------------------------- /Day66-75/res/redis-aof.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-aof.png -------------------------------------------------------------------------------- /Day66-75/res/redis-rdb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-rdb.png -------------------------------------------------------------------------------- /Day66-75/res/tesseract.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/tesseract.gif -------------------------------------------------------------------------------- /res/abstraction-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/abstraction-view.png -------------------------------------------------------------------------------- /res/class-and-object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/class-and-object.png -------------------------------------------------------------------------------- /res/int-is-comparation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/int-is-comparation.png -------------------------------------------------------------------------------- /res/multi-inheritance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/multi-inheritance.png -------------------------------------------------------------------------------- /res/objects-lifetime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/objects-lifetime.png -------------------------------------------------------------------------------- /res/pycharm-activate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/pycharm-activate.png -------------------------------------------------------------------------------- /res/pycharm-workspace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/pycharm-workspace.png -------------------------------------------------------------------------------- /res/python-bj-salary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-bj-salary.png -------------------------------------------------------------------------------- /res/python-cd-salary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-cd-salary.png -------------------------------------------------------------------------------- /res/python-job-chengdu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-job-chengdu.png -------------------------------------------------------------------------------- /Day01-15/Day10/res/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day10/res/ball.png -------------------------------------------------------------------------------- /Day41-55/res/admin-login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-login.png -------------------------------------------------------------------------------- /Day41-55/res/admin-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-model.png -------------------------------------------------------------------------------- /Day66-75/05.解析动态内容.md: -------------------------------------------------------------------------------- 1 | ## 解析动态内容 2 | 3 | ### JavaScript逆向工程 4 | 5 | 6 | 7 | ### 使用Selenium 8 | 9 | 10 | -------------------------------------------------------------------------------- /Day66-75/code/tesseract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/code/tesseract.png -------------------------------------------------------------------------------- /Day66-75/res/redis-bind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-bind.png -------------------------------------------------------------------------------- /Day66-75/res/redis-port.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-port.png -------------------------------------------------------------------------------- /Day66-75/res/redis-save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-save.png -------------------------------------------------------------------------------- /res/objects-collaborate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/objects-collaborate.png -------------------------------------------------------------------------------- /res/pycharm-new-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/pycharm-new-project.png -------------------------------------------------------------------------------- /res/pycharm-set-ui-theme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/pycharm-set-ui-theme.png -------------------------------------------------------------------------------- /Day01-15/Day14/res/arpanet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/arpanet.png -------------------------------------------------------------------------------- /Day01-15/Day14/res/browers.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/browers.jpg -------------------------------------------------------------------------------- /Day01-15/Day14/res/osi_rm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/osi_rm.gif -------------------------------------------------------------------------------- /Day01-15/Day14/res/osimodel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/osimodel.png -------------------------------------------------------------------------------- /Day01-15/Day14/res/telnet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/telnet.png -------------------------------------------------------------------------------- /Day21-30/res/browser-joke-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/res/browser-joke-2.jpg -------------------------------------------------------------------------------- /Day21-30/res/browser-joke-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/res/browser-joke-3.jpg -------------------------------------------------------------------------------- /Day31-35/res/Dennis-Ritchie.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day31-35/res/Dennis-Ritchie.jpg -------------------------------------------------------------------------------- /Day31-35/res/Ken-Thompson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day31-35/res/Ken-Thompson.png -------------------------------------------------------------------------------- /Day31-35/res/Linus-Torvalds.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day31-35/res/Linus-Torvalds.jpg -------------------------------------------------------------------------------- /Day31-35/res/history-of-os.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day31-35/res/history-of-os.png -------------------------------------------------------------------------------- /Day41-55/res/admin-welcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-welcome.png -------------------------------------------------------------------------------- /Day41-55/res/django-index-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/django-index-1.png -------------------------------------------------------------------------------- /Day41-55/res/django-index-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/django-index-2.png -------------------------------------------------------------------------------- /Day41-55/res/http-request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/http-request.png -------------------------------------------------------------------------------- /Day41-55/res/http-response.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/http-response.png -------------------------------------------------------------------------------- /Day66-75/res/douban-xpath.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/douban-xpath.png -------------------------------------------------------------------------------- /Day66-75/res/http-request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/http-request.png -------------------------------------------------------------------------------- /Day66-75/res/http-response.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/http-response.png -------------------------------------------------------------------------------- /Day66-75/res/redis-database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-database.png -------------------------------------------------------------------------------- /Day66-75/res/redis-security.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-security.png -------------------------------------------------------------------------------- /Day66-75/res/redis-slow-log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-slow-log.png -------------------------------------------------------------------------------- /res/pycharm-import-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/pycharm-import-settings.png -------------------------------------------------------------------------------- /res/python-salary-beijing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-salary-beijing.png -------------------------------------------------------------------------------- /res/python-salary-chengdu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-salary-chengdu.png -------------------------------------------------------------------------------- /res/python-salary-hangzhou.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-salary-hangzhou.png -------------------------------------------------------------------------------- /res/python-salary-shanghai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-salary-shanghai.png -------------------------------------------------------------------------------- /res/python-salary-shenzhen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-salary-shenzhen.png -------------------------------------------------------------------------------- /res/python-tutor-visualize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-tutor-visualize.png -------------------------------------------------------------------------------- /res/python-tutor-visualize2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-tutor-visualize2.png -------------------------------------------------------------------------------- /Day01-15/Day07/res/python-set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day07/res/python-set.png -------------------------------------------------------------------------------- /Day01-15/Day08/res/oop-zhihu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day08/res/oop-zhihu.png -------------------------------------------------------------------------------- /Day01-15/Day10/res/ball-game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day10/res/ball-game.png -------------------------------------------------------------------------------- /Day21-30/res/browser-joke-1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day21-30/res/browser-joke-1.jpeg -------------------------------------------------------------------------------- /Day31-35/res/history-of-unix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day31-35/res/history-of-unix.png -------------------------------------------------------------------------------- /Day36-40/res/redis-data-type.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day36-40/res/redis-data-type.png -------------------------------------------------------------------------------- /Day41-55/oa/hrs/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HrsConfig(AppConfig): 5 | name = 'hrs' 6 | -------------------------------------------------------------------------------- /Day41-55/oa/static/images/mm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/oa/static/images/mm.jpg -------------------------------------------------------------------------------- /Day41-55/res/admin-model-emps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-model-emps.png -------------------------------------------------------------------------------- /Day41-55/res/admin-model-read.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-model-read.png -------------------------------------------------------------------------------- /Day41-55/res/web-application.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/web-application.png -------------------------------------------------------------------------------- /Day66-75/res/crawler-workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/crawler-workflow.png -------------------------------------------------------------------------------- /res/python-built-in-functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/python-built-in-functions.png -------------------------------------------------------------------------------- /Day01-15/Day01/res/python-idle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day01/res/python-idle.png -------------------------------------------------------------------------------- /Day01-15/Day09/res/uml-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day09/res/uml-example.png -------------------------------------------------------------------------------- /Day01-15/Day13/res/macos-monitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day13/res/macos-monitor.png -------------------------------------------------------------------------------- /Day01-15/Day14/res/TCP-IP-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/TCP-IP-model.png -------------------------------------------------------------------------------- /Day01-15/Day14/res/after-browser.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/after-browser.jpg -------------------------------------------------------------------------------- /Day41-55/res/admin-model-create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-model-create.png -------------------------------------------------------------------------------- /Day41-55/res/admin-model-depts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-model-depts.png -------------------------------------------------------------------------------- /Day41-55/shop/cart/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CartConfig(AppConfig): 5 | name = 'cart' 6 | -------------------------------------------------------------------------------- /Day41-55/shop/static/images/lay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop/static/images/lay.jpg -------------------------------------------------------------------------------- /Day41-55/shop/static/images/oil.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop/static/images/oil.jpg -------------------------------------------------------------------------------- /Day41-55/shop/static/images/wang.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop/static/images/wang.jpg -------------------------------------------------------------------------------- /Day41-55/shop/static/images/wine.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop/static/images/wine.jpg -------------------------------------------------------------------------------- /Day66-75/res/baidu-search-taobao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/baidu-search-taobao.png -------------------------------------------------------------------------------- /Day66-75/res/redis-replication.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/redis-replication.png -------------------------------------------------------------------------------- /Day66-75/res/scrapy-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/scrapy-architecture.png -------------------------------------------------------------------------------- /Day01-15/Day01/res/python-ipython.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day01/res/python-ipython.png -------------------------------------------------------------------------------- /Day01-15/Day01/res/python-pycharm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day01/res/python-pycharm.png -------------------------------------------------------------------------------- /Day01-15/Day01/res/python-sublime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day01/res/python-sublime.png -------------------------------------------------------------------------------- /Day01-15/Day07/res/ipython-timeit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day07/res/ipython-timeit.png -------------------------------------------------------------------------------- /Day01-15/Day08/res/object-feature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day08/res/object-feature.png -------------------------------------------------------------------------------- /Day01-15/Day09/res/uml-components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day09/res/uml-components.png -------------------------------------------------------------------------------- /Day01-15/Day11/res/file-open-mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day11/res/file-open-mode.png -------------------------------------------------------------------------------- /Day01-15/Day14/res/before-browser.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/before-browser.jpg -------------------------------------------------------------------------------- /Day01-15/Day14/res/tcpipprotocols.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/tcpipprotocols.png -------------------------------------------------------------------------------- /Day31-35/res/linux-network-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day31-35/res/linux-network-config.png -------------------------------------------------------------------------------- /Day41-55/car/search/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class SearchConfig(AppConfig): 5 | name = 'search' 6 | -------------------------------------------------------------------------------- /Day41-55/shop/static/images/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop/static/images/Thumbs.db -------------------------------------------------------------------------------- /Day41-55/shop/static/images/dolbee.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop/static/images/dolbee.jpg -------------------------------------------------------------------------------- /Day41-55/shop/static/images/noodle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop/static/images/noodle.jpg -------------------------------------------------------------------------------- /Day41-55/shop_origin/cart/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CartConfig(AppConfig): 5 | name = 'cart' 6 | -------------------------------------------------------------------------------- /res/pycharm-create-launcher-script.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/res/pycharm-create-launcher-script.png -------------------------------------------------------------------------------- /Day01-15/Day01/res/python-jupyter-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day01/res/python-jupyter-1.png -------------------------------------------------------------------------------- /Day01-15/Day01/res/python-jupyter-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day01/res/python-jupyter-2.png -------------------------------------------------------------------------------- /Day01-15/Day07/res/fibonacci-blocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day07/res/fibonacci-blocks.png -------------------------------------------------------------------------------- /Day01-15/Day12/res/tel-start-number.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day12/res/tel-start-number.png -------------------------------------------------------------------------------- /Day66-75/res/chrome-developer-tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day66-75/res/chrome-developer-tools.png -------------------------------------------------------------------------------- /Day41-55/res/admin-model-emps-modified.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-model-emps-modified.png -------------------------------------------------------------------------------- /Day41-55/shop_origin/static/images/lay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop_origin/static/images/lay.jpg -------------------------------------------------------------------------------- /Day41-55/shop_origin/static/images/oil.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop_origin/static/images/oil.jpg -------------------------------------------------------------------------------- /Day41-55/shop_origin/static/images/wang.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop_origin/static/images/wang.jpg -------------------------------------------------------------------------------- /Day41-55/shop_origin/static/images/wine.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop_origin/static/images/wine.jpg -------------------------------------------------------------------------------- /Day01-15/Day14/res/browser-market-place.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/browser-market-place.jpeg -------------------------------------------------------------------------------- /Day01-15/Day14/res/how-data-is-processed.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day01-15/Day14/res/how-data-is-processed.jpg -------------------------------------------------------------------------------- /Day41-55/res/admin-model-delete-and-update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/res/admin-model-delete-and-update.png -------------------------------------------------------------------------------- /Day41-55/shop_origin/static/images/dolbee.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop_origin/static/images/dolbee.jpg -------------------------------------------------------------------------------- /Day41-55/shop_origin/static/images/noodle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HUSTERche/Python-100-Days/HEAD/Day41-55/shop_origin/static/images/noodle.jpg -------------------------------------------------------------------------------- /Day01-15/Day04/for2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 用for循环实现1~100之间的偶数求和 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-01 8 | 9 | """ 10 | 11 | sum = 0 12 | for x in range(2, 101, 2): 13 | sum += x 14 | print(sum) 15 | -------------------------------------------------------------------------------- /Day36-40/NoSQL入门.md: -------------------------------------------------------------------------------- 1 | ## NoSQL入门 2 | 3 | ### NoSQL概述 4 | 5 | 6 | 7 | ### 主流NoSQL数据库 8 | 9 | 10 | 11 | ### Redis概述 12 | 13 | 14 | 15 | ### MongoDB概述 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Day66-75/code/douban/douban/spiders/__init__.py: -------------------------------------------------------------------------------- 1 | # This package will contain the spiders of your Scrapy project 2 | # 3 | # Please refer to the documentation for information on how to create and manage 4 | # your spiders. 5 | -------------------------------------------------------------------------------- /Day66-75/code/image360/image360/spiders/__init__.py: -------------------------------------------------------------------------------- 1 | # This package will contain the spiders of your Scrapy project 2 | # 3 | # Please refer to the documentation for information on how to create and manage 4 | # your spiders. 5 | -------------------------------------------------------------------------------- /Day01-15/Day04/for1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 用for循环实现1~100求和 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-01 8 | 9 | """ 10 | 11 | sum = 0 12 | for x in range(1, 101): 13 | if x % 2 == 0: 14 | sum += x 15 | print(sum) 16 | -------------------------------------------------------------------------------- /Day01-15/Day11/example.csv: -------------------------------------------------------------------------------- 1 | 4/5/2014 13:34,Apples,73 2 | 4/5/2014 3:41,Cherries,85 3 | 4/6/2014 12:46,Pears,14 4 | 4/8/2014 8:59,Oranges,52 5 | 4/10/2014 2:07,Apples,152 6 | 4/10/2014 18:10,Bananas,23 7 | 4/10/2014 2:40,Strawberries,98 8 | -------------------------------------------------------------------------------- /Day01-15/Day04/while1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 用while循环实现1~100求和 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-01 8 | 9 | """ 10 | 11 | sum = 0 12 | num = 1 13 | while num <= 100: 14 | sum += num 15 | num += 1 16 | print(sum) 17 | -------------------------------------------------------------------------------- /Day01-15/Day04/while2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 用while循环实现1~100之间的偶数求和 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-01 8 | 9 | """ 10 | 11 | sum = 0 12 | num = 2 13 | while num <= 100: 14 | sum += num 15 | num += 2 16 | print(sum) 17 | -------------------------------------------------------------------------------- /Day01-15/Day02/centigrade.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 将华氏温度转换为摄氏温度 4 | F = 1.8C + 32 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-02-27 9 | 10 | """ 11 | 12 | f = float(input('请输入华氏温度: ')) 13 | c = (f - 32) / 1.8 14 | print('%.1f华氏度 = %.1f摄氏度' % (f, c)) 15 | -------------------------------------------------------------------------------- /Day01-15/Day04/for3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输入非负整数n计算n! 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-01 8 | 9 | """ 10 | 11 | n = int(input('n = ')) 12 | result = 1 13 | for x in range(1, n + 1): 14 | result *= x 15 | print('%d! = %d' % (n, result)) 16 | -------------------------------------------------------------------------------- /Day01-15/Day05/table.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输出乘法口诀表(九九表) 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-02 8 | 9 | """ 10 | 11 | for i in range(1, 10): 12 | for j in range(1, i + 1): 13 | print('%d*%d=%d' % (i, j, i * j), end='\t') 14 | print() 15 | -------------------------------------------------------------------------------- /Day01-15/Day05/fibonacci.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输出斐波那契数列的前20个数 4 | 1 1 2 3 5 8 13 21 ... 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-03-02 9 | 10 | """ 11 | 12 | a = 0 13 | b = 1 14 | for _ in range(20): 15 | (a, b) = (b, a + b) 16 | print(a, end=' ') 17 | -------------------------------------------------------------------------------- /Day66-75/code/myutils.py: -------------------------------------------------------------------------------- 1 | from functools import wraps 2 | 3 | 4 | def coroutine(fn): 5 | 6 | @wraps(fn) 7 | def wrapper(*args, **kwargs): 8 | gen = fn(*args, **kwargs) 9 | next(gen) 10 | return gen 11 | 12 | return wrapper 13 | -------------------------------------------------------------------------------- /Day01-15/Day11/ex4.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 引发异常和异常栈 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | 12 | def f1(): 13 | raise AssertionError('发生异常') 14 | 15 | 16 | def f2(): 17 | f1() 18 | 19 | 20 | def f3(): 21 | f2() 22 | 23 | 24 | f3() 25 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/cart/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from cart.models import Goods 4 | 5 | 6 | class GoodsAdmin(admin.ModelAdmin): 7 | 8 | list_display = ('id', 'name', 'price', 'image') 9 | 10 | 11 | admin.site.register(Goods, GoodsAdmin) 12 | -------------------------------------------------------------------------------- /Day01-15/Day14/timeclient.py: -------------------------------------------------------------------------------- 1 | from socket import socket 2 | 3 | 4 | def main(): 5 | client = socket() 6 | client.connect(('10.7.152.69', 6789)) 7 | print(client.recv(1024).decode('utf-8')) 8 | client.close() 9 | 10 | 11 | if __name__ == '__main__': 12 | main() 13 | -------------------------------------------------------------------------------- /Day01-15/Day02/variable1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用变量保存数据并进行操作 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | a = 321 12 | b = 123 13 | print(a + b) 14 | print(a - b) 15 | print(a * b) 16 | print(a / b) 17 | print(a // b) 18 | print(a % b) 19 | print(a ** b) 20 | -------------------------------------------------------------------------------- /Day41-55/shop/cart/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from cart.models import Goods 4 | 5 | 6 | class GoodsAdmin(admin.ModelAdmin): 7 | 8 | list_display = ('id', 'name', 'price', 'image') 9 | search_fields = ('name', ) 10 | 11 | 12 | admin.site.register(Goods, GoodsAdmin) 13 | -------------------------------------------------------------------------------- /Day01-15/Day13/generator2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 生成器 - 使用yield关键字 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-21 8 | 9 | """ 10 | 11 | 12 | def fib(num): 13 | n, a, b = 0, 0, 1 14 | while n < num: 15 | yield b 16 | a, b = b, a + b 17 | n += 1 18 | 19 | 20 | for x in fib(20): 21 | print(x) 22 | -------------------------------------------------------------------------------- /Day01-15/Day02/leap.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输入年份 如果是闰年输出True 否则输出False 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | year = int(input('请输入年份: ')) 12 | # 如果代码太长写成一行不便于阅读 可以使用\或()折行 13 | is_leap = (year % 4 == 0 and year % 100 != 0 or 14 | year % 400 == 0) 15 | print(is_leap) 16 | -------------------------------------------------------------------------------- /Day01-15/Day12/test5.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def main(): 5 | sentence = '你丫是傻叉吗? 我操你大爷的. Fuck you.' 6 | purified = re.sub('[操肏艹草曹]|fuck|shit|傻[比屄逼叉缺吊屌]|煞笔', 7 | '*', sentence, flags=re.IGNORECASE) 8 | print(purified) 9 | 10 | 11 | if __name__ == '__main__': 12 | main() 13 | -------------------------------------------------------------------------------- /Day41-55/oa/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | {% load staticfiles %} 3 | 4 | 5 | 6 | 首页 7 | 8 | 9 |

{{ greeting }}

10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /Day01-15/Day02/variable2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 将input函数输入的数据保存在变量中并进行操作 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | a = int(input('a = ')) 12 | b = int(input('b = ')) 13 | print(a + b) 14 | print(a - b) 15 | print(a * b) 16 | print(a / b) 17 | print(a // b) 18 | print(a % b) 19 | print(a ** b) 20 | -------------------------------------------------------------------------------- /Day66-75/code/douban/scrapy.cfg: -------------------------------------------------------------------------------- 1 | # Automatically created by: scrapy startproject 2 | # 3 | # For more information about the [deploy] section see: 4 | # https://scrapyd.readthedocs.io/en/latest/deploy.html 5 | 6 | [settings] 7 | default = douban.settings 8 | 9 | [deploy] 10 | #url = http://localhost:6800/ 11 | project = douban 12 | -------------------------------------------------------------------------------- /Day01-15/Day02/circle.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输入半径计算圆的周长和面积 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | import math 12 | 13 | radius = float(input('请输入圆的半径: ')) 14 | perimeter = 2 * math.pi * radius 15 | area = math.pi * radius * radius 16 | print('周长: %.2f' % perimeter) 17 | print('面积: %.2f' % area) 18 | -------------------------------------------------------------------------------- /Day01-15/Day08/access.py: -------------------------------------------------------------------------------- 1 | class Test: 2 | 3 | def __init__(self, foo): 4 | self.__foo = foo 5 | 6 | def __bar(self): 7 | print(self.__foo) 8 | print('__bar') 9 | 10 | 11 | def main(): 12 | test = Test('hello') 13 | test._Test__bar() 14 | print(test._Test__foo) 15 | 16 | 17 | if __name__ == "__main__": 18 | main() 19 | -------------------------------------------------------------------------------- /Day21-30/qq_link.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 点我聊一聊 9 | 10 | -------------------------------------------------------------------------------- /Day66-75/code/image360/scrapy.cfg: -------------------------------------------------------------------------------- 1 | # Automatically created by: scrapy startproject 2 | # 3 | # For more information about the [deploy] section see: 4 | # https://scrapyd.readthedocs.io/en/latest/deploy.html 5 | 6 | [settings] 7 | default = image360.settings 8 | 9 | [deploy] 10 | #url = http://localhost:6800/ 11 | project = image360 12 | -------------------------------------------------------------------------------- /Day41-55/car/search/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from search.models import CarRecord 4 | 5 | 6 | class CarRecordAdmin(admin.ModelAdmin): 7 | 8 | list_display = ('carno', 'reason', 'date', 'punish', 'isdone') 9 | search_fields = ('carno', ) 10 | 11 | 12 | admin.site.register(CarRecord, CarRecordAdmin) 13 | -------------------------------------------------------------------------------- /Day66-75/code/example10.py: -------------------------------------------------------------------------------- 1 | import robobrowser 2 | 3 | 4 | def main(): 5 | b = robobrowser.RoboBrowser(parser='lxml') 6 | b.open('https://v.taobao.com/v/content/live?catetype=704&from=taonvlang') 7 | for img_tag in b.select('img[src]'): 8 | print(img_tag.attrs['src']) 9 | 10 | 11 | if __name__ == '__main__': 12 | main() 13 | -------------------------------------------------------------------------------- /Day01-15/Day06/function1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 函数的定义和使用 - 计算组合数C(7,3) 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-05 8 | 9 | """ 10 | 11 | 12 | # 将求阶乘的功能封装成一个函数 13 | def factorial(n): 14 | result = 1 15 | for num in range(1, n + 1): 16 | result *= num 17 | return result 18 | 19 | 20 | print(factorial(7) // factorial(3) // factorial(4)) 21 | -------------------------------------------------------------------------------- /Day36-40/关系型数据库MySQL.md: -------------------------------------------------------------------------------- 1 | ## 关系型数据入门 2 | 3 | ### 关系型数据概述 4 | 5 | 1. 数据持久化。 6 | 2. 数据库发展史。 7 | 3. 关系型数据库特点。 8 | 4. E-R图。 9 | 5. 关系型数据库产品。 10 | 11 | ### MySQL简介 12 | 13 | 1. 安装和配置。 14 | 2. 常用命令。 15 | 16 | ### SQL详解 17 | 18 | 1. DDL 19 | 2. DML 20 | 3. DQL 21 | 22 | ### Python数据库编程 23 | 24 | 1. MySQLdb 25 | 2. PyMySQL 26 | 27 | ### ORM概述 28 | 29 | 30 | -------------------------------------------------------------------------------- /Day01-15/Day05/lily.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 找出100~999之间的所有水仙花数 4 | 水仙花数是各位立方和等于这个数本身的数 5 | 如: 153 = 1**3 + 5**3 + 3**3 6 | 7 | Version: 0.1 8 | Author: 骆昊 9 | Date: 2018-03-02 10 | 11 | """ 12 | 13 | for num in range(100, 1000): 14 | low = num % 10 15 | mid = num // 10 % 10 16 | high = num // 100 17 | if num == low ** 3 + mid ** 3 + high ** 3: 18 | print(num) 19 | -------------------------------------------------------------------------------- /Day66-75/code/generator02.py: -------------------------------------------------------------------------------- 1 | from time import sleep 2 | 3 | 4 | def countdown(n): 5 | while n > 0: 6 | yield n 7 | n -= 1 8 | 9 | 10 | def main(): 11 | for num in countdown(5): 12 | print(f'Countdown: {num}') 13 | sleep(1) 14 | print('Countdown Over!') 15 | 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Day01-15/Day03/piecewise.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 分段函数求值 4 | 3x - 5 (x > 1) 5 | f(x) = x + 2 (-1 <= x <= 1) 6 | 5x + 3 (x < -1) 7 | 8 | Version: 0.1 9 | Author: 骆昊 10 | Date: 2018-02-28 11 | 12 | """ 13 | 14 | x = float(input('x = ')) 15 | if x > 1: 16 | y = 3 * x - 5 17 | elif x >= -1: 18 | y = x + 2 19 | else: 20 | y = 5 * x + 3 21 | print('f(%.2f) = %.2f' % (x, y)) 22 | -------------------------------------------------------------------------------- /Day01-15/Day05/prime.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输出2~99之间的素数 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-02 8 | 9 | """ 10 | 11 | import math 12 | 13 | for num in range(2, 100): 14 | is_prime = True 15 | for factor in range(2, int(math.sqrt(num)) + 1): 16 | if num % factor == 0: 17 | is_prime = False 18 | break 19 | if is_prime: 20 | print(num, end=' ') 21 | -------------------------------------------------------------------------------- /Day01-15/Day07/fibonacci.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 生成斐波拉切数列 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | 12 | def main(): 13 | f = [1 , 1] 14 | for i in range(2, 20): 15 | f += [f[i - 1] + f[i - 2]] 16 | # f.append(f[i - 1] + f[i - 2]) 17 | for val in f: 18 | print(val, end=' ') 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Day01-15/Day11/file2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 读取圆周率文件判断其中是否包含自己的生日 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | birth = input('请输入你的生日: ') 12 | with open('pi_million_digits.txt') as f: 13 | lines = f.readlines() 14 | pi_string = '' 15 | for line in lines: 16 | pi_string += line.strip() 17 | if birth in pi_string: 18 | print('Bingo!!!') 19 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from hrs import views 4 | 5 | urlpatterns = [ 6 | path('depts', views.depts, name='depts'), 7 | # url('depts/emps/(?P[0-9]+)', views.emps, name='empsindept'), 8 | path('depts/emps/', views.emps, name='empsindept'), 9 | path('deldept/', views.del_dept, name='ddel') 10 | ] 11 | -------------------------------------------------------------------------------- /Day01-15/Day14/socket3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 套接字 - 基于UDP协议Echo服务器 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-22 8 | 9 | """ 10 | 11 | from socket import * 12 | from time import * 13 | 14 | server = socket(AF_INET, SOCK_DGRAM) 15 | server.bind(('localhost', 6789)) 16 | while True: 17 | data, addr = server.recvfrom(1024) 18 | server.sendto(data, addr) 19 | server.close() 20 | -------------------------------------------------------------------------------- /Day01-15/Day05/chicken.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 求解《百钱百鸡》问题 4 | 1只公鸡5元 1只母鸡3元 3只小鸡1元 用100元买100只鸡 5 | 问公鸡 母鸡 小鸡各有多少只 6 | 7 | Version: 0.1 8 | Author: 骆昊 9 | Date: 2018-03-02 10 | 11 | """ 12 | 13 | for x in range(0, 20): 14 | for y in range(0, 33): 15 | z = 100 - x - y 16 | if 5 * x + 3 * y + z / 3 == 100: 17 | print('公鸡: %d只, 母鸡: %d只, 小鸡: %d只' % (x, y, z)) 18 | 19 | # 要理解程序背后的算法 - 穷举法 20 | -------------------------------------------------------------------------------- /Day01-15/Day14/socket2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 套接字 - 基于TCP协议创建时间客户端 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-22 8 | 9 | """ 10 | 11 | from socket import * 12 | 13 | client = socket(AF_INET, SOCK_STREAM) 14 | client.connect(('localhost', 6789)) 15 | while True: 16 | data = client.recv(1024) 17 | if not data: 18 | break 19 | print(data.decode('utf-8')) 20 | client.close() 21 | -------------------------------------------------------------------------------- /Day01-15/Day02/variable4.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 检查变量的类型 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | a = 100 12 | b = 1000000000000000000 13 | c = 12.345 14 | d = 1 + 5j 15 | e = 'A' 16 | f = 'hello, world' 17 | g = True 18 | print(type(a)) 19 | print(type(b)) 20 | print(type(c)) 21 | print(type(d)) 22 | print(type(e)) 23 | print(type(f)) 24 | print(type(g)) 25 | -------------------------------------------------------------------------------- /Day01-15/Day13/multiprocess4.py: -------------------------------------------------------------------------------- 1 | from time import time 2 | 3 | 4 | def main(): 5 | total = 0 6 | number_list = [x for x in range(1, 100000001)] 7 | start = time() 8 | for number in number_list: 9 | total += number 10 | print(total) 11 | end = time() 12 | print('Execution time: %.3fs' % (end - start)) 13 | 14 | 15 | if __name__ == '__main__': 16 | main() -------------------------------------------------------------------------------- /Day01-15/Day01/hello.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 第一个Python程序 - hello, world! 4 | 向伟大的Dennis M. Ritchie先生致敬 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-02-26 9 | 10 | 请将该文件命名为hello.py并在终端中通过下面的命令运行它 11 | python hello.py 12 | 13 | """ 14 | 15 | print('hello, world!') 16 | # print("你好,世界!") 17 | print('你好', '世界') 18 | print('hello', 'world', sep=', ', end='!') 19 | print('goodbye, world', end='!\n') 20 | -------------------------------------------------------------------------------- /Day01-15/Day11/ex2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 异常机制 - 处理程序在运行时可能发生的状态 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | input_again = True 12 | while input_again: 13 | try: 14 | a = int(input('a = ')) 15 | b = int(input('b = ')) 16 | print('%d / %d = %f' % (a, b, a / b)) 17 | input_again = False 18 | except (ValueError, ZeroDivisionError) as msg: 19 | print(msg) 20 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/shop_create_sql.sql: -------------------------------------------------------------------------------- 1 | insert into tb_goods values 2 | (default, '乐事(Lay’s)无限薯片', 8.2, 'images/lay.jpg'), 3 | (default, '旺旺 仙贝 加量装 540g', 18.5, 'images/wang.jpg'), 4 | (default, '多儿比(Dolbee)黄桃水果罐头', 6.8, 'images/dolbee.jpg'), 5 | (default, '王致和 精制料酒 500ml', 7.9, 'images/wine.jpg'), 6 | (default, '陈克明 面条 鸡蛋龙须挂面', 1.0, 'images/noodle.jpg'), 7 | (default, '鲁花 菜籽油 4L', 69.9, 'images/oil.jpg'); -------------------------------------------------------------------------------- /Day01-15/Day05/palindrome.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 判断输入的正整数是不是回文数 4 | 回文数是指将一个正整数从左往右排列和从右往左排列值一样的数 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-03-02 9 | 10 | """ 11 | 12 | num = int(input('请输入一个正整数: ')) 13 | temp = num 14 | num2 = 0 15 | while temp > 0: 16 | num2 *= 10 17 | num2 += temp % 10 18 | temp //= 10 19 | if num == num2: 20 | print('%d是回文数' % num) 21 | else: 22 | print('%d不是回文数' % num) 23 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/cart/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | from cart.models import Goods 4 | 5 | 6 | def index(request): 7 | goods_list = list(Goods.objects.all()) 8 | return render(request, 'goods.html', {'goods_list': goods_list}) 9 | 10 | 11 | def show_cart(request): 12 | return render(request, 'cart.html') 13 | 14 | 15 | def add_to_cart(request, no): 16 | pass 17 | -------------------------------------------------------------------------------- /Day01-15/Day03/convert.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 英制单位英寸和公制单位厘米互换 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-28 8 | 9 | """ 10 | 11 | value = float(input('请输入长度: ')) 12 | unit = input('请输入单位: ') 13 | if unit == 'in' or unit == '英寸': 14 | print('%f英寸 = %f厘米' % (value, value * 2.54)) 15 | elif unit == 'cm' or unit == '厘米': 16 | print('%f厘米 = %f英寸' % (value, value / 2.54)) 17 | else: 18 | print('请输入有效的单位') 19 | -------------------------------------------------------------------------------- /Day66-75/code/generator01.py: -------------------------------------------------------------------------------- 1 | def fib(): 2 | a, b = 0, 1 3 | while True: 4 | a, b = b, a + b 5 | yield a 6 | 7 | 8 | def even(gen): 9 | for val in gen: 10 | if val % 2 == 0: 11 | yield val 12 | 13 | 14 | def main(): 15 | gen = even(fib()) 16 | for _ in range(10): 17 | print(next(gen)) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /Day01-15/Day04/for5.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输入两个正整数计算最大公约数和最小公倍数 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-01 8 | 9 | """ 10 | 11 | x = int(input('x = ')) 12 | y = int(input('y = ')) 13 | if x > y: 14 | (x, y) = (y, x) 15 | for factor in range(x, 0, -1): 16 | if x % factor == 0 and y % factor == 0: 17 | print('%d和%d的最大公约数是%d' % (x, y, factor)) 18 | print('%d和%d的最小公倍数是%d' % (x, y, x * y // factor)) 19 | break 20 | -------------------------------------------------------------------------------- /Day01-15/Day11/file4.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 读写二进制文件 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | import base64 12 | 13 | with open('mm.jpg', 'rb') as f: 14 | data = f.read() 15 | # print(type(data)) 16 | # print(data) 17 | print('字节数:', len(data)) 18 | # 将图片处理成BASE-64编码 19 | print(base64.b64encode(data)) 20 | 21 | with open('girl.jpg', 'wb') as f: 22 | f.write(data) 23 | print('写入完成!') 24 | -------------------------------------------------------------------------------- /Day01-15/Day04/for4.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输入一个正整数判断它是不是素数 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-01 8 | 9 | """ 10 | 11 | from math import sqrt 12 | 13 | num = int(input('请输入一个正整数: ')) 14 | end = int(sqrt(num)) 15 | is_prime = True 16 | for x in range(2, end + 1): 17 | if num % x == 0: 18 | is_prime = False 19 | break 20 | if is_prime and num != 1: 21 | print('%d是素数' % num) 22 | else: 23 | print('%d不是素数' % num) 24 | -------------------------------------------------------------------------------- /Day01-15/Day11/csv1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 读取CSV文件 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | import csv 12 | 13 | filename = 'example.csv' 14 | 15 | try: 16 | with open(filename) as f: 17 | reader = csv.reader(f) 18 | data = list(reader) 19 | except FileNotFoundError: 20 | print('无法打开文件:', filename) 21 | else: 22 | for item in data: 23 | print('%-30s%-20s%-10s' % (item[0], item[1], item[2])) 24 | -------------------------------------------------------------------------------- /Day01-15/Day03/rolldice.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 掷骰子决定做什么事情 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-28 8 | 9 | """ 10 | 11 | from random import randint 12 | 13 | face = randint(1, 6) 14 | if face == 1: 15 | result = '唱首歌' 16 | elif face == 2: 17 | result = '跳个舞' 18 | elif face == 3: 19 | result = '学狗叫' 20 | elif face == 4: 21 | result = '做俯卧撑' 22 | elif face == 5: 23 | result = '念绕口令' 24 | else: 25 | result = '讲冷笑话' 26 | print(result) 27 | -------------------------------------------------------------------------------- /Day01-15/Day06/function2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 函数的定义和使用 - 求最大公约数和最小公倍数 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-05 8 | 9 | """ 10 | 11 | 12 | def gcd(x, y): 13 | if x > y: 14 | (x, y) = (y, x) 15 | for factor in range(x, 1, -1): 16 | if x % factor == 0 and y % factor == 0: 17 | return factor 18 | return 1 19 | 20 | 21 | def lcm(x, y): 22 | return x * y // gcd(x, y) 23 | 24 | 25 | print(gcd(15, 27)) 26 | print(lcm(15, 27)) 27 | -------------------------------------------------------------------------------- /Day01-15/Day03/verify.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 用户身份验证 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-28 8 | 9 | """ 10 | 11 | # import getpass 12 | # from getpass import getpass 13 | # from getpass import * 14 | 15 | username = input('请输入用户名: ') 16 | password = input('请输入口令: ') 17 | # 输入口令的时候终端中没有回显 18 | # password = getpass.getpass('请输入口令: ') 19 | if username == 'admin' and password == '123456': 20 | print('身份验证成功!') 21 | else: 22 | print('身份验证失败!') 23 | -------------------------------------------------------------------------------- /Day01-15/Day11/json2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 写入JSON文件 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | import json 12 | 13 | teacher_dict = {'name': '白元芳', 'age': 25, 'title': '讲师'} 14 | json_str = json.dumps(teacher_dict) 15 | print(json_str) 16 | print(type(json_str)) 17 | fruits_list = ['apple', 'orange', 'strawberry', 'banana', 'pitaya'] 18 | json_str = json.dumps(fruits_list) 19 | print(json_str) 20 | print(type(json_str)) 21 | -------------------------------------------------------------------------------- /Day01-15/Day13/generator1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 生成器 - 生成器语法 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-21 8 | 9 | """ 10 | 11 | seq = [x * x for x in range(10)] 12 | print(seq) 13 | 14 | gen = (x * x for x in range(10)) 15 | print(gen) 16 | for x in gen: 17 | print(x) 18 | 19 | num = 10 20 | gen = (x ** y for x, y in zip(range(1, num), range(num - 1, 0, -1))) 21 | print(gen) 22 | n = 1 23 | while n < num: 24 | print(next(gen)) 25 | n += 1 26 | -------------------------------------------------------------------------------- /Day01-15/Day07/marquee.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输入学生考试成绩计算平均分 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | import os 12 | import time 13 | 14 | 15 | def main(): 16 | str = 'Welcome to 1000 Phone Chengdu Campus ' 17 | while True: 18 | print(str) 19 | time.sleep(0.2) 20 | str = str[1:] + str[0:1] 21 | # for Windows use os.system('cls') instead 22 | os.system('clear') 23 | 24 | 25 | if __name__ == '__main__': 26 | main() 27 | -------------------------------------------------------------------------------- /Day41-55/car/car/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for car project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "car.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Day41-55/car/static/images/icon-yes.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Day41-55/oa/oa/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for oa project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "oa.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Day66-75/code/example09.py: -------------------------------------------------------------------------------- 1 | import robobrowser 2 | 3 | 4 | def main(): 5 | b = robobrowser.RoboBrowser(parser='lxml') 6 | b.open('https://github.com/login') 7 | f = b.get_form(action='/session') 8 | f['login'].value = 'jackfrued@gmail.com' 9 | f['password'].value = 'yourpassword' 10 | b.submit_form(f) 11 | for a_tag in b.select('a[href]'): 12 | print(a_tag.attrs['href']) 13 | 14 | 15 | if __name__ == '__main__': 16 | main() 17 | -------------------------------------------------------------------------------- /Day01-15/Day03/grade.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 百分制成绩转等级制成绩 4 | 90分以上 --> A 5 | 80分~89分 --> B 6 | 70分~79分 --> C 7 | 60分~69分 --> D 8 | 60分以下 --> E 9 | 10 | Version: 0.1 11 | Author: 骆昊 12 | Date: 2018-02-28 13 | 14 | """ 15 | 16 | score = float(input('请输入成绩: ')) 17 | if score >= 90: 18 | grade = 'A' 19 | elif score >= 80: 20 | grade = 'B' 21 | elif score >= 70: 22 | grade = 'C' 23 | elif score >= 60: 24 | grade = 'D' 25 | else: 26 | grade = 'E' 27 | print('对应的等级是:', grade) 28 | -------------------------------------------------------------------------------- /Day41-55/shop/shop/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for shop project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shop.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Day01-15/Day02/variable3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 格式化输出 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | a = int(input('a = ')) 12 | b = int(input('b = ')) 13 | print('%d + %d = %d' % (a, b, a + b)) 14 | print('%d - %d = %d' % (a, b, a - b)) 15 | print('%d * %d = %d' % (a, b, a * b)) 16 | print('%d / %d = %f' % (a, b, a / b)) 17 | print('%d // %d = %d' % (a, b, a // b)) 18 | print('%d %% %d = %d' % (a, b, a % b)) 19 | print('%d ** %d = %d' % (a, b, a ** b)) 20 | -------------------------------------------------------------------------------- /Day01-15/Day11/ex1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 异常机制 - 处理程序在运行时可能发生的状态 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | input_again = True 12 | while input_again: 13 | try: 14 | a = int(input('a = ')) 15 | b = int(input('b = ')) 16 | print('%d / %d = %f' % (a, b, a / b)) 17 | input_again = False 18 | except ValueError: 19 | print('请输入整数') 20 | except ZeroDivisionError: 21 | print('除数不能为0') 22 | # 处理异常让代码不因异常而崩溃是一方面 23 | # 更重要的是可以通过对异常的处理让代码从异常中恢复过来 24 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/shop/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for shop project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shop.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Day66-75/code/douban/douban/items.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Define here the models for your scraped items 4 | # 5 | # See documentation in: 6 | # https://doc.scrapy.org/en/latest/topics/items.html 7 | 8 | import scrapy 9 | 10 | 11 | class DoubanItem(scrapy.Item): 12 | 13 | name = scrapy.Field() 14 | year = scrapy.Field() 15 | score = scrapy.Field() 16 | director = scrapy.Field() 17 | classification = scrapy.Field() 18 | actor = scrapy.Field() 19 | -------------------------------------------------------------------------------- /Day01-15/Day10/turtle1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 用turtle模块绘图 4 | 这是一个非常有趣的模块 它模拟一只乌龟在窗口上爬行的方式来进行绘图 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-03-14 9 | 10 | """ 11 | 12 | import turtle 13 | 14 | turtle.pensize(3) 15 | turtle.penup() 16 | turtle.goto(-180, 150) 17 | turtle.pencolor('red') 18 | turtle.fillcolor('yellow') 19 | turtle.pendown() 20 | turtle.begin_fill() 21 | for _ in range(36): 22 | turtle.forward(200) 23 | turtle.right(170) 24 | turtle.end_fill() 25 | turtle.mainloop() 26 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/cart/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Goods(models.Model): 5 | 6 | id = models.AutoField(primary_key=True, db_column='gid') 7 | name = models.CharField(max_length=50, db_column='gname') 8 | price = models.DecimalField(max_digits=10, decimal_places=2, db_column='gprice') 9 | image = models.CharField(max_length=255, db_column='gimage') 10 | 11 | class Meta: 12 | db_table = 'tb_goods' 13 | ordering = ('id',) 14 | -------------------------------------------------------------------------------- /Day01-15/Day03/triangle.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 判断输入的边长能否构成三角形 4 | 如果能则计算出三角形的周长和面积 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-02-28 9 | 10 | """ 11 | 12 | import math 13 | 14 | a = float(input('a = ')) 15 | b = float(input('b = ')) 16 | c = float(input('c = ')) 17 | if a + b > c and a + c > b and b + c > a: 18 | print('周长: %f' % (a + b + c)) 19 | p = (a + b + c) / 2 20 | area = math.sqrt(p * (p - a) * (p - b) * (p - c)) 21 | print('面积: %f' % (area)) 22 | else: 23 | print('不能构成三角形') 24 | -------------------------------------------------------------------------------- /Day01-15/Day08/hack.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 另一种创建类的方式 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-08 8 | 9 | """ 10 | 11 | 12 | def bar(self, name): 13 | self._name = name 14 | 15 | 16 | def foo(self, course_name): 17 | print('%s正在学习%s.' % (self._name, course_name)) 18 | 19 | 20 | def main(): 21 | Student = type('Student', (object,), dict(__init__=bar, study=foo)) 22 | stu1 = Student('骆昊') 23 | stu1.study('Python程序设计') 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /Day01-15/Day14/socket4.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 套接字 - 基于UDP协议创建Echo客户端 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-22 8 | 9 | """ 10 | 11 | from socket import * 12 | 13 | client = socket(AF_INET, SOCK_DGRAM) 14 | while True: 15 | data_str = input('请输入: ') 16 | client.sendto(data_str.encode('utf-8'), ('localhost', 6789)) 17 | data, addr = client.recvfrom(1024) 18 | data_str = data.decode('utf-8') 19 | print('服务器回应:', data_str) 20 | if data_str == 'bye': 21 | break 22 | client.close() 23 | -------------------------------------------------------------------------------- /Day41-55/shop/cart/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Goods(models.Model): 5 | """商品模型类""" 6 | 7 | id = models.AutoField(primary_key=True, db_column='gid') 8 | name = models.CharField(max_length=50, db_column='gname') 9 | price = models.DecimalField(max_digits=10, decimal_places=2, db_column='gprice') 10 | image = models.CharField(max_length=255, db_column='gimage') 11 | 12 | class Meta: 13 | 14 | db_table = 'tb_goods' 15 | ordering = ('id', ) 16 | -------------------------------------------------------------------------------- /Day66-75/06.表单交互和验证码处理.md: -------------------------------------------------------------------------------- 1 | ## 表单交互和验证码处理 2 | 3 | ### 提交表单 4 | 5 | #### 手动提交 6 | 7 | 8 | 9 | #### 自动提交 10 | 11 | 12 | 13 | ### 验证码处理 14 | 15 | #### 加载验证码 16 | 17 | 18 | 19 | #### 光学字符识别 20 | 21 | 光学字符识别(OCR)是从图像中抽取文本的工具,可以应用于公安、电信、物流、金融等诸多行业,例如识别车牌,身份证扫描识别、名片信息提取等。在爬虫开发中,如果遭遇了有文字验证码的表单,就可以利用OCR来进行验证码处理。Tesseract-OCR引擎最初是由惠普公司开发的光学字符识别系统,目前发布在Github上,由Google赞助开发。 22 | 23 | ![](./res/tesseract.gif) 24 | 25 | #### 改善OCR 26 | 27 | 28 | 29 | #### 处理更复杂的验证码 30 | 31 | 32 | 33 | #### 验证码处理服务 34 | 35 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from hrs.models import Dept, Emp 4 | 5 | 6 | class DeptAdmin(admin.ModelAdmin): 7 | 8 | list_display = ('no', 'name', 'location') 9 | ordering = ('no', ) 10 | 11 | 12 | class EmpAdmin(admin.ModelAdmin): 13 | 14 | list_display = ('no', 'name', 'job', 'sal', 'dept') 15 | search_fields = ('name', 'job') 16 | ordering = ('dept', ) 17 | 18 | 19 | admin.site.register(Dept, DeptAdmin) 20 | admin.site.register(Emp, EmpAdmin) 21 | -------------------------------------------------------------------------------- /Day66-75/code/asyncio01.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | 3 | 4 | @asyncio.coroutine 5 | def countdown(name, num): 6 | while num > 0: 7 | print(f'Countdown[{name}]: {num}') 8 | yield from asyncio.sleep(1) 9 | num -= 1 10 | 11 | 12 | def main(): 13 | loop = asyncio.get_event_loop() 14 | tasks = [ 15 | countdown("A", 10), countdown("B", 5), 16 | ] 17 | loop.run_until_complete(asyncio.wait(tasks)) 18 | loop.close() 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Day01-15/Day11/file3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 写文本文件 4 | 将100以内的素数写入到文件中 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-03-13 9 | 10 | """ 11 | 12 | from math import sqrt 13 | 14 | 15 | def is_prime(n): 16 | for factor in range(2, int(sqrt(n)) + 1): 17 | if n % factor == 0: 18 | return False 19 | return True 20 | 21 | 22 | # 试一试有什么不一样 23 | # with open('prime.txt', 'a') as f: 24 | with open('prime.txt', 'w') as f: 25 | for num in range(2, 100): 26 | if is_prime(num): 27 | f.write(str(num) + '\n') 28 | print('写入完成!') 29 | -------------------------------------------------------------------------------- /Day01-15/Day06/function6.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 作用域问题 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-05 8 | 9 | """ 10 | 11 | 12 | # 局部作用域 13 | def foo1(): 14 | a = 5 15 | 16 | 17 | foo1() 18 | # print(a) # NameError 19 | 20 | # 全局作用域 21 | b = 10 22 | 23 | 24 | def foo2(): 25 | print(b) 26 | 27 | 28 | foo2() 29 | 30 | 31 | def foo3(): 32 | b = 100 # 局部变量 33 | print(b) 34 | 35 | 36 | foo3() 37 | print(b) 38 | 39 | 40 | def foo4(): 41 | global b 42 | b = 200 # 全局变量 43 | print(b) 44 | 45 | 46 | foo4() 47 | print(b) 48 | -------------------------------------------------------------------------------- /Day01-15/Day05/guess.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 猜数字游戏 4 | 计算机出一个1~100之间的随机数由人来猜 5 | 计算机根据人猜的数字分别给出提示大一点/小一点/猜对了 6 | 7 | Version: 0.1 8 | Author: 骆昊 9 | Date: 2018-03-02 10 | 11 | """ 12 | 13 | import random 14 | 15 | answer = random.randint(1, 100) 16 | counter = 0 17 | while True: 18 | counter += 1 19 | number = int(input('请输入: ')) 20 | if number < answer: 21 | print('大一点') 22 | elif number > answer: 23 | print('小一点') 24 | else: 25 | print('恭喜你猜对了!') 26 | break 27 | print('你总共猜了%d次' % counter) 28 | if counter > 7: 29 | print('你的智商余额明显不足') 30 | -------------------------------------------------------------------------------- /Day01-15/Day14/socket5.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用socketserver模块创建时间服务器 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-22 8 | 9 | """ 10 | 11 | from socketserver import TCPServer, StreamRequestHandler 12 | from time import * 13 | 14 | 15 | class EchoRequestHandler(StreamRequestHandler): 16 | 17 | def handle(self): 18 | currtime = localtime(time()) 19 | timestr = strftime('%Y-%m-%d %H:%M:%S', currtime) 20 | self.wfile.write(timestr.encode('utf-8')) 21 | 22 | 23 | server = TCPServer(('localhost', 6789), EchoRequestHandler) 24 | server.serve_forever() 25 | -------------------------------------------------------------------------------- /Day01-15/Day02/operator.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 运算符的使用 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | a = 5 12 | b = 10 13 | c = 3 14 | d = 4 15 | e = 5 16 | a += b 17 | a -= c 18 | a *= d 19 | a /= e 20 | print("a = ", a) 21 | 22 | flag1 = 3 > 2 23 | flag2 = 2 < 1 24 | flag3 = flag1 and flag2 25 | flag4 = flag1 or flag2 26 | flag5 = not flag1 27 | print("flag1 = ", flag1) 28 | print("flag2 = ", flag2) 29 | print("flag3 = ", flag3) 30 | print("flag4 = ", flag4) 31 | print("flag5 = ", flag5) 32 | print(flag1 is True) 33 | print(flag2 is not False) 34 | -------------------------------------------------------------------------------- /Day66-75/code/coroutine01.py: -------------------------------------------------------------------------------- 1 | from time import sleep 2 | 3 | 4 | def countdown_gen(n, consumer): 5 | consumer.send(None) 6 | while n > 0: 7 | consumer.send(n) 8 | n -= 1 9 | consumer.send(None) 10 | 11 | 12 | def countdown_con(): 13 | while True: 14 | n = yield 15 | if n: 16 | print(f'Countdown {n}') 17 | sleep(1) 18 | else: 19 | print('Countdown Over!') 20 | 21 | 22 | def main(): 23 | countdown_gen(5, countdown_con()) 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /Day01-15/Day11/ex3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 异常机制 - 处理程序在运行时可能发生的状态 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | import time 12 | import sys 13 | 14 | filename = input('请输入文件名: ') 15 | try: 16 | with open(filename) as f: 17 | lines = f.readlines() 18 | except FileNotFoundError as msg: 19 | print('无法打开文件:', filename) 20 | print(msg) 21 | except UnicodeDecodeError as msg: 22 | print('非文本文件无法解码') 23 | sys.exit() 24 | else: 25 | for line in lines: 26 | print(line.rstrip()) 27 | time.sleep(0.5) 28 | finally: 29 | # 此处最适合做善后工作 30 | print('不管发生什么我都会执行') 31 | -------------------------------------------------------------------------------- /Day66-75/code/image360/image360/items.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Define here the models for your scraped items 4 | # 5 | # See documentation in: 6 | # https://doc.scrapy.org/en/latest/topics/items.html 7 | 8 | import scrapy 9 | 10 | 11 | class GoodsItem(scrapy.Item): 12 | 13 | price = scrapy.Field() 14 | deal = scrapy.Field() 15 | title = scrapy.Field() 16 | 17 | 18 | class BeautyItem(scrapy.Item): 19 | 20 | title = scrapy.Field() 21 | tag = scrapy.Field() 22 | width = scrapy.Field() 23 | height = scrapy.Field() 24 | url = scrapy.Field() 25 | -------------------------------------------------------------------------------- /Day01-15/Day11/file1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 从文本文件中读取数据 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | import time 12 | 13 | 14 | def main(): 15 | # 一次性读取整个文件内容 16 | with open('致橡树.txt', 'r', encoding='utf-8') as f: 17 | print(f.read()) 18 | 19 | # 通过for-in循环逐行读取 20 | with open('致橡树.txt', mode='r') as f: 21 | for line in f: 22 | print(line, end='') 23 | time.sleep(0.5) 24 | print() 25 | 26 | # 读取文件按行读取到列表中 27 | with open('致橡树.txt') as f: 28 | lines = f.readlines() 29 | print(lines) 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /Day41-55/car/static/images/icon-no.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Day01-15/Day12/test3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 验证输入用户名和QQ号是否有效并给出对应的提示信息 4 | 5 | 要求: 6 | 用户名必须由字母、数字或下划线构成且长度在6~20个字符之间 7 | QQ号是5~12的数字且首位不能为0 8 | 9 | """ 10 | 11 | import re 12 | 13 | 14 | def main(): 15 | username = input('请输入用户名: ') 16 | qq = input('请输入QQ号: ') 17 | m1 = re.match(r'^[0-9a-zA-Z_]{6,20}$', username) 18 | if not m1: 19 | print('请输入有效的用户名.') 20 | m2 = re.match(r'^[1-9]\d{4,11}$', qq) 21 | if not m2: 22 | print('请输入有效的QQ号.') 23 | if m1 and m2: 24 | print('你输入的信息是有效的!') 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | 30 | -------------------------------------------------------------------------------- /Day01-15/Day13/multiprocess3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 创建进程调用其他程序 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | import subprocess 12 | import sys 13 | 14 | def main(): 15 | # 通过sys.argv获取命令行参数 16 | if len(sys.argv) > 1: 17 | # 第一个命令行参数是程序本身所以从第二个开始取 18 | for index in range(1, len(sys.argv)): 19 | try: 20 | # 通过subprocess模块的call函数启动子进程 21 | status = subprocess.call(sys.argv[index]) 22 | except FileNotFoundError: 23 | print('不能执行%s命令' % sys.argv[index]) 24 | else: 25 | print('请使用命令行参数指定要执行的进程') 26 | 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /Day01-15/Day14/socket1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 套接字 - 基于TCP协议创建时间服务器 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-22 8 | 9 | """ 10 | 11 | from socket import * 12 | from time import * 13 | 14 | server = socket(AF_INET, SOCK_STREAM) 15 | server.bind(('localhost', 6789)) 16 | server.listen() 17 | print('服务器已经启动正在监听客户端连接.') 18 | while True: 19 | client, addr = server.accept() 20 | print('客户端%s:%d连接成功.' % (addr[0], addr[1])) 21 | currtime = localtime(time()) 22 | timestr = strftime('%Y-%m-%d %H:%M:%S', currtime) 23 | client.send(timestr.encode('utf-8')) 24 | client.close() 25 | server.close() 26 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/migrations/0003_auto_20180524_1646.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-24 08:46 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('hrs', '0002_auto_20180523_0923'), 11 | ] 12 | 13 | operations = [ 14 | migrations.AlterField( 15 | model_name='emp', 16 | name='mgr', 17 | field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='hrs.Emp'), 18 | ), 19 | ] 20 | -------------------------------------------------------------------------------- /Day01-15/Day13/asyncio2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 异步I/O操作 - async和await 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-21 8 | 9 | """ 10 | 11 | import asyncio 12 | import threading 13 | 14 | 15 | # 通过async修饰的函数不再是普通函数而是一个协程 16 | # 注意async和await将在Python 3.7中作为关键字出现 17 | async def hello(): 18 | print('%s: hello, world!' % threading.current_thread()) 19 | await asyncio.sleep(2) 20 | print('%s: goodbye, world!' % threading.current_thread()) 21 | 22 | 23 | loop = asyncio.get_event_loop() 24 | tasks = [hello(), hello()] 25 | # 等待两个异步I/O操作执行结束 26 | loop.run_until_complete(asyncio.wait(tasks)) 27 | loop.close() 28 | -------------------------------------------------------------------------------- /Day41-55/car/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "car.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Day41-55/oa/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "oa.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Day41-55/shop/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shop.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shop.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /Day01-15/Day02/string.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 字符串常用操作 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | str1 = 'hello, world!' 12 | print('字符串的长度是:', len(str1)) 13 | print('单词首字母大写: ', str1.title()) 14 | print('字符串变大写: ', str1.upper()) 15 | # str1 = str1.upper() 16 | print('字符串是不是大写: ', str1.isupper()) 17 | print('字符串是不是以hello开头: ', str1.startswith('hello')) 18 | print('字符串是不是以hello结尾: ', str1.endswith('hello')) 19 | print('字符串是不是以感叹号开头: ', str1.startswith('!')) 20 | print('字符串是不是一感叹号结尾: ', str1.endswith('!')) 21 | str2 = '- \u9a86\u660a' 22 | str3 = str1.title() + ' ' + str2.lower() 23 | print(str3) 24 | -------------------------------------------------------------------------------- /Day01-15/Day07/dict2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 字典的常用操作 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | 12 | def main(): 13 | stu = {'name': '骆昊', 'age': 38, 'gender': True} 14 | print(stu) 15 | print(stu.keys()) 16 | print(stu.values()) 17 | print(stu.items()) 18 | for elem in stu.items(): 19 | print(elem) 20 | print(elem[0], elem[1]) 21 | if 'age' in stu: 22 | stu['age'] = 20 23 | print(stu) 24 | stu.setdefault('score', 60) 25 | print(stu) 26 | stu.setdefault('score', 100) 27 | print(stu) 28 | stu['score'] = 100 29 | print(stu) 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /Day01-15/Day05/perfect.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 找出1~9999之间的所有完美数 4 | 完美数是除自身外其他所有因子的和正好等于这个数本身的数 5 | 例如: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 + 14 6 | 7 | Version: 0.1 8 | Author: 骆昊 9 | Date: 2018-03-02 10 | 11 | """ 12 | import time 13 | import math 14 | 15 | start = time.clock() 16 | for num in range(1, 10000): 17 | sum = 0 18 | for factor in range(1, int(math.sqrt(num)) + 1): 19 | if num % factor == 0: 20 | sum += factor 21 | if factor > 1 and num / factor != factor: 22 | sum += num / factor 23 | if sum == num: 24 | print(num) 25 | end = time.clock() 26 | print("执行时间:", (end - start), "秒") 27 | 28 | # 通过比较上面两种不同的解决方案的执行时间 意识到优化程序的重要性 29 | -------------------------------------------------------------------------------- /Day66-75/code/example11.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | from selenium import webdriver 3 | from selenium.webdriver.common.keys import Keys 4 | 5 | 6 | def main(): 7 | driver = webdriver.Chrome() 8 | driver.get('https://v.taobao.com/v/content/live?catetype=704&from=taonvlang') 9 | elem = driver.find_element_by_css_selector('input[placeholder=输入关键词搜索]') 10 | elem.send_keys('运动') 11 | elem.send_keys(Keys.ENTER) 12 | soup = BeautifulSoup(driver.page_source, 'lxml') 13 | for img_tag in soup.body.select('img[src]'): 14 | print(img_tag.attrs['src']) 15 | 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Day01-15/Day09/diamond.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 多重继承 4 | - 菱形继承(钻石继承) 5 | - C3算法(替代DFS的算法) 6 | 7 | Version: 0.1 8 | Author: 骆昊 9 | Date: 2018-03-12 10 | 11 | """ 12 | 13 | 14 | class A(object): 15 | 16 | def foo(self): 17 | print('foo of A') 18 | 19 | 20 | class B(A): 21 | pass 22 | 23 | 24 | class C(A): 25 | 26 | def foo(self): 27 | print('foo fo C') 28 | 29 | 30 | class D(B, C): 31 | pass 32 | 33 | 34 | class E(D): 35 | 36 | def foo(self): 37 | print('foo in E') 38 | super().foo() 39 | super(B, self).foo() 40 | super(C, self).foo() 41 | 42 | 43 | if __name__ == '__main__': 44 | d = D() 45 | d.foo() 46 | e = E() 47 | e.foo() 48 | -------------------------------------------------------------------------------- /Day01-15/Day07/avgscore.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输入学生考试成绩计算平均分 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | 12 | def main(): 13 | number = int(input('请输入学生人数: ')) 14 | names = [None] * number 15 | scores = [None] * number 16 | for index in range(len(names)): 17 | names[index] = input('请输入第%d个学生的名字: ' % (index + 1)) 18 | scores[index] = float(input('请输入第%d个学生的成绩: ' % (index + 1))) 19 | total = 0 20 | for index in range(len(names)): 21 | print('%s: %.1f分' % (names[index], scores[index])) 22 | total += scores[index] 23 | print('平均成绩是: %.1f分' % (total / number)) 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /Day01-15/Day13/singlethread1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 不使用多线程的情况 - 模拟多个下载任务 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | from random import randint 12 | from time import time, sleep 13 | 14 | 15 | def download_task(filename): 16 | print('开始下载%s...' % filename) 17 | time_to_download = randint(5, 10) 18 | sleep(time_to_download) 19 | print('下载完成! 耗费了%d秒' % time_to_download) 20 | 21 | 22 | def main(): 23 | start = time() 24 | download_task('Python从入门到住院.pdf') 25 | download_task('Peking Hot.avi') 26 | end = time() 27 | print('总共耗费了%.2f秒.' % (end - start)) 28 | 29 | 30 | if __name__ == '__main__': 31 | main() 32 | -------------------------------------------------------------------------------- /Day01-15/Day07/findmax.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 找出列表中最大或最小的元素 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | 12 | def main(): 13 | fruits = ['grape', 'apple', 'strawberry', 'waxberry', 'pitaya'] 14 | # 直接使用内置的max和min函数找出列表中最大和最小元素 15 | # print(max(fruits)) 16 | # print(min(fruits)) 17 | max_value = min_value = fruits[0] 18 | for index in range(1, len(fruits)): 19 | if fruits[index] > max_value: 20 | max_value = fruits[index] 21 | elif fruits[index] < min_value: 22 | min_value = fruits[index] 23 | print('Max:', max_value) 24 | print('Min:', min_value) 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | # 想一想如果最大的元素有两个要找出第二大的又该怎么做 30 | -------------------------------------------------------------------------------- /Day01-15/Day09/pet.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | 4 | class Pet(object, metaclass=ABCMeta): 5 | 6 | def __init__(self, nickname): 7 | self._nickname = nickname 8 | 9 | @abstractmethod 10 | def make_voice(self): 11 | pass 12 | 13 | 14 | class Dog(Pet): 15 | 16 | def make_voice(self): 17 | print('%s: 汪汪汪...' % self._nickname) 18 | 19 | 20 | class Cat(Pet): 21 | 22 | def make_voice(self): 23 | print('%s: 喵...喵...' % self._nickname) 24 | 25 | 26 | def main(): 27 | pets = [Dog('旺财'), Cat('凯蒂'), Dog('大黄')] 28 | for pet in pets: 29 | pet.make_voice() 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /Day41-55/car/search/migrations/0002_auto_20180524_1420.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11 on 2018-05-24 06:20 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('search', '0001_initial'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AlterModelOptions( 16 | name='carrecord', 17 | options={'ordering': ('-date',)}, 18 | ), 19 | migrations.RenameField( 20 | model_name='carrecord', 21 | old_name='punlish', 22 | new_name='punish', 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /Day01-15/Day13/asyncio1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 异步I/O操作 - asyncio模块 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-21 8 | 9 | """ 10 | 11 | import asyncio 12 | import threading 13 | # import time 14 | 15 | 16 | @asyncio.coroutine 17 | def hello(): 18 | print('%s: hello, world!' % threading.current_thread()) 19 | # 休眠不会阻塞主线程因为使用了异步I/O操作 20 | # 注意有yield from才会等待休眠操作执行完成 21 | yield from asyncio.sleep(2) 22 | # asyncio.sleep(1) 23 | # time.sleep(1) 24 | print('%s: goodbye, world!' % threading.current_thread()) 25 | 26 | 27 | loop = asyncio.get_event_loop() 28 | tasks = [hello(), hello()] 29 | # 等待两个异步I/O操作执行结束 30 | loop.run_until_complete(asyncio.wait(tasks)) 31 | print('game over!') 32 | loop.close() 33 | -------------------------------------------------------------------------------- /Day01-15/Day02/variable5.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 类型转换 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-27 8 | 9 | """ 10 | 11 | a = 100 12 | b = str(a) 13 | c = 12.345 14 | d = str(c) 15 | e = '123' 16 | f = int(e) 17 | g = '123.456' 18 | h = float(g) 19 | i = False 20 | j = str(i) 21 | k = 'hello' 22 | m = bool(k) 23 | print(a) 24 | print(type(a)) 25 | print(b) 26 | print(type(b)) 27 | print(c) 28 | print(type(c)) 29 | print(d) 30 | print(type(d)) 31 | print(e) 32 | print(type(e)) 33 | print(f) 34 | print(type(f)) 35 | print(g) 36 | print(type(g)) 37 | print(h) 38 | print(type(h)) 39 | print(i) 40 | print(type(i)) 41 | print(j) 42 | print(type(j)) 43 | print(k) 44 | print(type(k)) 45 | print(m) 46 | print(type(m)) 47 | -------------------------------------------------------------------------------- /Day01-15/Day13/multiprocess2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 实现进程间的通信 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | import multiprocessing 12 | import os 13 | 14 | 15 | def sub_task(queue): 16 | print('子进程进程号:', os.getpid()) 17 | counter = 0 18 | while counter < 1000: 19 | queue.put('Pong') 20 | counter += 1 21 | 22 | 23 | if __name__ == '__main__': 24 | print('当前进程号:', os.getpid()) 25 | queue = multiprocessing.Queue() 26 | p = multiprocessing.Process(target=sub_task, args=(queue,)) 27 | p.start() 28 | counter = 0 29 | while counter < 1000: 30 | queue.put('Ping') 31 | counter += 1 32 | p.join() 33 | print('子任务已经完成.') 34 | for _ in range(2000): 35 | print(queue.get(), end='') 36 | -------------------------------------------------------------------------------- /Day01-15/Day07/dict1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 定义和使用字典 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | 12 | def main(): 13 | scores = {'骆昊': 95, '白元芳': 78, '狄仁杰': 82} 14 | print(scores['骆昊']) 15 | print(scores['狄仁杰']) 16 | for elem in scores: 17 | print('%s\t--->\t%d' % (elem, scores[elem])) 18 | scores['白元芳'] = 65 19 | scores['诸葛王朗'] = 71 20 | scores.update(冷面=67, 方启鹤=85) 21 | print(scores) 22 | if '武则天' in scores: 23 | print(scores['武则天']) 24 | print(scores.get('武则天')) 25 | print(scores.get('武则天', 60)) 26 | print(scores.popitem()) 27 | print(scores.popitem()) 28 | print(scores.pop('骆昊', 100)) 29 | scores.clear() 30 | print(scores) 31 | 32 | 33 | if __name__ == '__main__': 34 | main() 35 | -------------------------------------------------------------------------------- /Day01-15/Day07/list2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 列表常用操作 4 | - 列表连接 5 | - 获取长度 6 | - 遍历列表 7 | - 列表切片 8 | - 列表排序 9 | - 列表反转 10 | - 查找元素 11 | 12 | Version: 0.1 13 | Author: 骆昊 14 | Date: 2018-03-06 15 | 16 | """ 17 | 18 | 19 | def main(): 20 | fruits = ['grape', 'apple', 'strawberry', 'waxberry'] 21 | fruits += ['pitaya', 'pear', 'mango'] 22 | # 循环遍历列表元素 23 | for fruit in fruits: 24 | print(fruit.title(), end=' ') 25 | print() 26 | # 列表切片 27 | fruits2 = fruits[1:4] 28 | print(fruits2) 29 | # fruit3 = fruits # 没有复制列表只创建了新的引用 30 | fruits3 = fruits[:] 31 | print(fruits3) 32 | fruits4 = fruits[-3:-1] 33 | print(fruits4) 34 | fruits5 = fruits[::-1] 35 | print(fruits5) 36 | 37 | 38 | if __name__ == '__main__': 39 | main() 40 | -------------------------------------------------------------------------------- /Day01-15/Day07/yanghui.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输出10行的杨辉三角 - 二项式的n次方展开系数 4 | 1 5 | 1 1 6 | 1 2 1 7 | 1 3 3 1 8 | 1 4 6 4 1 9 | ... ... ... 10 | 11 | 12 | Version: 0.1 13 | Author: 骆昊 14 | Date: 2018-03-06 15 | 16 | """ 17 | 18 | 19 | def main(): 20 | num = int(input('Number of rows: ')) 21 | yh = [[]] * num 22 | for row in range(len(yh)): 23 | yh[row] = [None] * (row + 1) 24 | for col in range(len(yh[row])): 25 | if col == 0 or col == row: 26 | yh[row][col] = 1 27 | else: 28 | yh[row][col] = yh[row - 1][col] + yh[row - 1][col - 1] 29 | print(yh[row][col], end='\t') 30 | print() 31 | 32 | 33 | if __name__ == '__main__': 34 | main() 35 | -------------------------------------------------------------------------------- /Day01-15/Day07/scoretable.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 学生考试成绩表 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | 12 | def main(): 13 | names = ['关羽', '张飞', '赵云', '马超', '黄忠'] 14 | subjs = ['语文', '数学', '英语'] 15 | scores = [[0] * 3] * 5 16 | for row, name in enumerate(names): 17 | print('请输入%s的成绩' % name) 18 | for col, subj in enumerate(subjs): 19 | scores[row][col] = float(input(subj + ': ')) 20 | print(scores) 21 | # for row, name in enumerate(names): 22 | # print('请输入%s的成绩' % name) 23 | # scores[row] = [None] * len(subjs) 24 | # for col, subj in enumerate(subjs): 25 | # score = float(input(subj + ': ')) 26 | # scores[row][col] = score 27 | # print(scores) 28 | 29 | if __name__ == '__main__': 30 | main() 31 | -------------------------------------------------------------------------------- /Day01-15/Day07/list1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 定义和使用列表 4 | - 用下标访问元素 5 | - 添加元素 6 | - 删除元素 7 | 8 | Version: 0.1 9 | Author: 骆昊 10 | Date: 2018-03-06 11 | 12 | """ 13 | 14 | 15 | def main(): 16 | fruits = ['grape', '@pple', 'strawberry', 'waxberry'] 17 | print(fruits) 18 | # 通过下标访问元素 19 | print(fruits[0]) 20 | print(fruits[1]) 21 | print(fruits[-1]) 22 | print(fruits[-2]) 23 | # print(fruits[-5]) # IndexError 24 | # print(fruits[4]) # IndexError 25 | fruits[1] = 'apple' 26 | print(fruits) 27 | # 添加元素 28 | fruits.append('pitaya') 29 | fruits.insert(0, 'banana') 30 | print(fruits) 31 | # 删除元素 32 | del fruits[1] 33 | fruits.pop() 34 | fruits.pop(0) 35 | fruits.remove('apple') 36 | print(fruits) 37 | 38 | 39 | if __name__ == '__main__': 40 | main() 41 | -------------------------------------------------------------------------------- /Day66-75/Scrapy爬虫框架分布式实现.md: -------------------------------------------------------------------------------- 1 | ## Scrapy爬虫框架分布式实现 2 | 3 | ### 分布式爬虫原理 4 | 5 | 6 | 7 | ### Scrapy分布式实现 8 | 9 | 1. 安装Scrapy-Redis。 10 | 2. 配置Redis服务器。 11 | 3. 修改配置文件。 12 | - SCHEDULER = 'scrapy_redis.scheduler.Scheduler' 13 | - DUPEFILTER_CLASS = 'scrapy_redis.dupefilter.RFPDupeFilter' 14 | - REDIS_HOST = '1.2.3.4' 15 | - REDIS_PORT = 6379 16 | - REDIS_PASSWORD = '1qaz2wsx' 17 | - SCHEDULER_QUEUE_CLASS = 'scrapy_redis.queue.FifoQueue' 18 | - SCHEDULER_PERSIST = True(通过持久化支持接续爬取) 19 | - SCHEDULER_FLUSH_ON_START = True(每次启动时重新爬取) 20 | 21 | ### Scrapyd分布式部署 22 | 23 | 1. 安装Scrapyd 24 | 2. 修改配置文件 25 | - mkdir /etc/scrapyd 26 | - vim /etc/scrapyd/scrapyd.conf 27 | 3. 安装Scrapyd-Client 28 | - 将项目打包成Egg文件。 29 | - 将打包的Egg文件通过addversion.json接口部署到Scrapyd上。 30 | 31 | -------------------------------------------------------------------------------- /Day01-15/Day13/multiprocess1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用Process类创建多个进程 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | # 通过下面程序的执行结果可以证实 父进程在创建子进程时复制了进程及其数据结构 12 | # 每个进程都有自己独立的内存空间 所以进程之间共享数据只能通过IPC的方式 13 | 14 | 15 | from multiprocessing import Process, Queue 16 | from time import sleep 17 | 18 | 19 | def sub_task(string, q): 20 | number = q.get() 21 | while number: 22 | print('%d: %s' % (number, string)) 23 | sleep(0.001) 24 | number = q.get() 25 | 26 | 27 | def main(): 28 | q = Queue(10) 29 | for number in range(1, 11): 30 | q.put(number) 31 | Process(target=sub_task, args=('Ping', q)).start() 32 | Process(target=sub_task, args=('Pong', q)).start() 33 | 34 | 35 | if __name__ == '__main__': 36 | main() 37 | -------------------------------------------------------------------------------- /Day01-15/Day07/set1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 定义和使用集合 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | 12 | def main(): 13 | set1 = {1, 2, 3, 3, 3, 2} 14 | print(set1) 15 | print('Length =', len(set1)) 16 | set2 = set(range(1, 10)) 17 | print(set2) 18 | set1.add(4) 19 | set1.add(5) 20 | set2.update([11, 12]) 21 | print(set1) 22 | print(set2) 23 | set2.discard(5) 24 | # remove的元素如果不存在会引发KeyError 25 | if 4 in set2: 26 | set2.remove(4) 27 | print(set2) 28 | # 遍历集合容器 29 | for elem in set2: 30 | print(elem ** 2, end=' ') 31 | print() 32 | # 将元组转换成集合 33 | set3 = set((1, 2, 3, 3, 2, 1)) 34 | print(set3.pop()) 35 | print(set3) 36 | 37 | 38 | if __name__ == '__main__': 39 | main() 40 | -------------------------------------------------------------------------------- /Day01-15/Day07/tuple.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 元组的定义和使用 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | 12 | def main(): 13 | # 定义元组 14 | t = ('骆昊', 38, True, '四川成都') 15 | print(t) 16 | # 获取元组中的元素 17 | print(t[0]) 18 | print(t[1]) 19 | print(t[2]) 20 | print(t[3]) 21 | # 遍历元组中的值 22 | for member in t: 23 | print(member) 24 | # 重新给元组赋值 25 | # t[0] = '王大锤' # TypeError 26 | # 变量t重新引用了新的元组 原来的元组被垃圾回收 27 | t = ('王大锤', 20, True, '云南昆明') 28 | print(t) 29 | # 元组和列表的转换 30 | person = list(t) 31 | print(person) 32 | person[0] = '李小龙' 33 | person[1] = 25 34 | print(person) 35 | fruits_list = ['apple', 'banana', 'orange'] 36 | fruits_tuple = tuple(fruits_list) 37 | print(fruits_tuple) 38 | print(fruits_tuple[1]) 39 | 40 | 41 | if __name__ == '__main__': 42 | main() -------------------------------------------------------------------------------- /Day01-15/Day06/function3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Python的内置函数 4 | - 数学相关: abs / divmod / pow / round / min / max / sum 5 | - 序列相关: len / range / next / filter / map / sorted / slice / reversed 6 | - 类型转换: chr / ord / str / bool / int / float / complex / bin / oct / hex 7 | - 数据结构: dict / list / set / tuple 8 | - 其他函数: all / any / id / input / open / print / type 9 | 10 | Version: 0.1 11 | Author: 骆昊 12 | Date: 2018-03-05 13 | 14 | """ 15 | 16 | 17 | def myfilter(mystr): 18 | return len(mystr) == 6 19 | 20 | 21 | # help() 22 | print(chr(0x9a86)) 23 | print(hex(ord('骆'))) 24 | print(abs(-1.2345)) 25 | print(round(-1.2345)) 26 | print(pow(1.2345, 5)) 27 | fruits = ['orange', 'peach', 'durian', 'watermelon'] 28 | print(fruits[slice(1, 3)]) 29 | fruits2 = list(filter(myfilter, fruits)) 30 | print(fruits) 31 | print(fruits2) 32 | -------------------------------------------------------------------------------- /Day41-55/car/search/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class CarRecord(models.Model): 5 | carno = models.CharField(max_length=7) 6 | reason = models.CharField(max_length=50) 7 | date = models.DateTimeField(db_column='happen_date', auto_now_add=True) 8 | punish = models.CharField(max_length=50) 9 | isdone = models.BooleanField(default=False) 10 | 11 | @property 12 | def happen_date(self): 13 | return self.date.strftime('%Y-%m-%d %H:%M:%S') 14 | """ 15 | return '%d年%02d月%02d日 %02d:%02d:%02d' % \ 16 | (self.date.year, self.date.month, self.date.day, 17 | self.date.hour, self.date.minute, self.date.second) 18 | """ 19 | 20 | class Meta: 21 | db_table = 'tb_car_record' 22 | ordering = ('-date', ) 23 | -------------------------------------------------------------------------------- /Day01-15/Day04/for6.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 打印各种三角形图案 4 | 5 | * 6 | ** 7 | *** 8 | **** 9 | ***** 10 | 11 | * 12 | ** 13 | *** 14 | **** 15 | ***** 16 | 17 | * 18 | *** 19 | ***** 20 | ******* 21 | ********* 22 | 23 | Version: 0.1 24 | Author: 骆昊 25 | Date: 2018-03-01 26 | 27 | """ 28 | 29 | row = int(input('请输入行数: ')) 30 | for i in range(row): 31 | for _ in range(i + 1): 32 | print('*', end='') 33 | print() 34 | 35 | for i in range(row): 36 | for j in range(row): 37 | if j < row - i - 1: 38 | print(' ', end='') 39 | else: 40 | print('*', end='') 41 | print() 42 | 43 | for i in range(row): 44 | for _ in range(row - i - 1): 45 | print(' ', end='') 46 | for _ in range(2 * i + 1): 47 | print('*', end='') 48 | print() 49 | -------------------------------------------------------------------------------- /Day01-15/Day13/multithread2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用多线程的情况 - 模拟多个下载任务 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | from random import randint 12 | from threading import Thread 13 | from time import time, sleep 14 | 15 | 16 | def download_task(filename): 17 | print('开始下载%s...' % filename) 18 | time_to_download = randint(5, 10) 19 | sleep(time_to_download) 20 | print('%s下载完成! 耗费了%d秒' % (filename, time_to_download)) 21 | 22 | 23 | def main(): 24 | start = time() 25 | thread1 = Thread(target=download_task, args=('Python从入门到住院.pdf',)) 26 | thread1.start() 27 | thread2 = Thread(target=download_task, args=('Peking Hot.avi',)) 28 | thread2.start() 29 | thread1.join() 30 | thread2.join() 31 | end = time() 32 | print('总共耗费了%.3f秒' % (end - start)) 33 | 34 | 35 | if __name__ == '__main__': 36 | main() 37 | -------------------------------------------------------------------------------- /Day66-75/code/asyncio02.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import aiohttp 3 | 4 | 5 | async def download(url): 6 | print('Fetch:', url) 7 | async with aiohttp.ClientSession() as session: 8 | async with session.get(url) as resp: 9 | print(url, '--->', resp.status) 10 | print(url, '--->', resp.cookies) 11 | print('\n\n', await resp.text()) 12 | 13 | 14 | def main(): 15 | loop = asyncio.get_event_loop() 16 | urls = [ 17 | 'https://www.baidu.com', 18 | 'http://www.sohu.com/', 19 | 'http://www.sina.com.cn/', 20 | 'https://www.taobao.com/', 21 | 'https://www.jd.com/' 22 | ] 23 | tasks = [download(url) for url in urls] 24 | loop.run_until_complete(asyncio.wait(tasks)) 25 | loop.close() 26 | 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /Day01-15/Day03/tax.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 输入月收入和五险一金计算个人所得税 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-02-28 8 | 9 | """ 10 | 11 | salary = float(input('本月收入: ')) 12 | insurance = float(input('五险一金: ')) 13 | diff = salary - insurance - 3500 14 | if diff <= 0: 15 | rate = 0 16 | deduction = 0 17 | elif diff < 1500: 18 | rate = 0.03 19 | deduction = 0 20 | elif diff < 4500: 21 | rate = 0.1 22 | deduction = 105 23 | elif diff < 9000: 24 | rate = 0.2 25 | deduction = 555 26 | elif diff < 35000: 27 | rate = 0.25 28 | deduction = 1005 29 | elif diff < 55000: 30 | rate = 0.3 31 | deduction = 2755 32 | elif diff < 80000: 33 | rate = 0.35 34 | deduction = 5505 35 | else: 36 | rate = 0.45 37 | deduction = 13505 38 | tax = abs(diff * rate - deduction) 39 | print('个人所得税: ¥%.2f元' % tax) 40 | print('实际到手收入: ¥%.2f元' % (diff + 3500 - tax)) 41 | -------------------------------------------------------------------------------- /Day01-15/Day10/gui3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用tkinter创建GUI 4 | - 在窗口上制作动画 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-03-14 9 | 10 | """ 11 | 12 | import tkinter 13 | import time 14 | 15 | 16 | # 播放动画效果的函数 17 | def play_animation(): 18 | canvas.move(oval, 2, 2) 19 | canvas.update() 20 | top.after(50, play_animation) 21 | 22 | 23 | x = 10 24 | y = 10 25 | top = tkinter.Tk() 26 | top.geometry('600x600') 27 | top.title('动画效果') 28 | top.resizable(False, False) 29 | top.wm_attributes('-topmost', 1) 30 | canvas = tkinter.Canvas(top, width=600, height=600, bd=0, highlightthickness=0) 31 | canvas.create_rectangle(0, 0, 600, 600, fill='gray') 32 | oval = canvas.create_oval(10, 10, 60, 60, fill='red') 33 | canvas.pack() 34 | top.update() 35 | play_animation() 36 | tkinter.mainloop() 37 | 38 | # 请思考如何让小球碰到屏幕的边界就弹回 39 | # 请思考如何用面向对象的编程思想对上面的代码进行封装 40 | -------------------------------------------------------------------------------- /Day01-15/Day12/test4.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def main(): 5 | # 创建正则表达式对象 使用了前瞻和回顾来保证手机号前后不应该出现数字 6 | pattern = re.compile(r'(?<=\D)(1[38]\d{9}|14[57]\d{8}|15[0-35-9]\d{8}|17[678]\d{8})(?=\D)') 7 | sentence = ''' 8 | 重要的事情说8130123456789遍,我的手机号是13512346789这个靓号, 9 | 不是15600998765,也是110或119,王大锤的手机号才是15600998765。 10 | ''' 11 | # 查找所有匹配并保存到一个列表中 12 | mylist = re.findall(pattern, sentence) 13 | print(mylist) 14 | print('--------华丽的分隔线--------') 15 | # 通过迭代器取出匹配对象并获得匹配的内容 16 | for temp in pattern.finditer(sentence): 17 | print(temp.group()) 18 | print('--------华丽的分隔线--------') 19 | # 通过search函数指定搜索位置找出所有匹配 20 | m = pattern.search(sentence) 21 | while m: 22 | print(m.group()) 23 | m = pattern.search(sentence, m.end()) 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /Day01-15/Day07/set2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 集合的常用操作 4 | - 交集 5 | - 并集 6 | - 差集 7 | - 子集 8 | - 超集 9 | 10 | Version: 0.1 11 | Author: 骆昊 12 | Date: 2018-03-06 13 | 14 | """ 15 | 16 | 17 | def main(): 18 | set1 = set(range(1, 7)) 19 | print(set1) 20 | set2 = set(range(2, 11, 2)) 21 | print(set2) 22 | set3 = set(range(1, 5)) 23 | print(set1 & set2) 24 | # print(set1.intersection(set2)) 25 | print(set1 | set2) 26 | # print(set1.union(set2)) 27 | print(set1 - set2) 28 | # print(set1.difference(set2)) 29 | print(set1 ^ set2) 30 | # print(set1.symmetric_difference(set2)) 31 | print(set2 <= set1) 32 | # print(set2.issubset(set1)) 33 | print(set3 <= set1) 34 | # print(set3.issubset(set1)) 35 | print(set1 >= set2) 36 | # print(set1.issuperset(set2)) 37 | print(set1 >= set3) 38 | # print(set1.issuperset(set3)) 39 | 40 | 41 | if __name__ == '__main__': 42 | main() 43 | -------------------------------------------------------------------------------- /Day01-15/Day14/fileclient.py: -------------------------------------------------------------------------------- 1 | from socket import socket 2 | from json import loads 3 | from base64 import b64decode 4 | 5 | 6 | def main(): 7 | client = socket() 8 | client.connect(('192.168.1.2', 5566)) 9 | # 定义一个保存二进制数据的对象 10 | in_data = bytes() 11 | # 由于不知道服务器发送的数据有多大每次接收1024字节 12 | data = client.recv(1024) 13 | while data: 14 | # 将收到的数据拼接起来 15 | in_data += data 16 | data = client.recv(1024) 17 | # 将收到的二进制数据解码成JSON字符串并转换成字典 18 | # loads函数的作用就是将JSON字符串转成字典对象 19 | my_dict = loads(in_data.decode('utf-8')) 20 | filename = my_dict['filename'] 21 | filedata = my_dict['filedata'].encode('utf-8') 22 | with open('/Users/Hao/' + filename, 'wb') as f: 23 | # 将base64格式的数据解码成二进制数据并写入文件 24 | f.write(b64decode(filedata)) 25 | print('图片已保存.') 26 | 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /Day66-75/code/example03.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | 3 | import requests 4 | 5 | import re 6 | 7 | 8 | def main(): 9 | # 通过requests第三方库的get方法获取页面 10 | resp = requests.get('http://sports.sohu.com/nba_a.shtml') 11 | # 对响应的字节串(bytes)进行解码操作(搜狐的部分页面使用了GBK编码) 12 | html = resp.content.decode('gbk') 13 | # 创建BeautifulSoup对象来解析页面(相当于JavaScript的DOM) 14 | bs = BeautifulSoup(html, 'lxml') 15 | # 通过CSS选择器语法查找元素并通过循环进行处理 16 | # for elem in bs.find_all(lambda x: 'test' in x.attrs): 17 | for elem in bs.select('a[test]'): 18 | # 通过attrs属性(字典)获取元素的属性值 19 | link_url = elem.attrs['href'] 20 | resp = requests.get(link_url) 21 | bs_sub = BeautifulSoup(resp.text, 'lxml') 22 | # 使用正则表达式对获取的数据做进一步的处理 23 | print(re.sub(r'[\r\n]', '', bs_sub.find('h1').text)) 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /Day01-15/Day07/list3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 生成列表 4 | - 用range创建数字列表 5 | - 生成表达式 6 | - 生成器 7 | 8 | Version: 0.1 9 | Author: 骆昊 10 | Date: 2018-03-06 11 | 12 | """ 13 | 14 | 15 | # 生成Fibonacci序列的生成器 16 | def fib(n): 17 | a, b = 0, 1 18 | for _ in range(n): 19 | a, b = b, a + b 20 | yield a 21 | 22 | 23 | def main(): 24 | # 用range创建数值列表 25 | list1 = list(range(1, 11)) 26 | print(list1) 27 | # 生成表达式 28 | list2 = [x * x for x in range(1, 11)] 29 | print(list2) 30 | list3 = [m + n for m in 'ABCDEFG' for n in '12345'] 31 | print(list3) 32 | print(len(list3)) 33 | # 生成器(节省空间但生成下一个元素时需要花费时间) 34 | gen = (m + n for m in 'ABCDEFG' for n in '12345') 35 | print(gen) 36 | for elem in gen: 37 | print(elem, end=' ') 38 | print() 39 | gen = fib(20) 40 | print(gen) 41 | for elem in gen: 42 | print(elem, end=' ') 43 | print() 44 | 45 | 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /Day01-15/Day08/rect.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 定义和使用矩形类 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-08 8 | 9 | """ 10 | 11 | 12 | class Rect(object): 13 | """矩形类""" 14 | 15 | def __init__(self, width=0, height=0): 16 | """构造器""" 17 | self.__width = width 18 | self.__height = height 19 | 20 | def perimeter(self): 21 | """计算周长""" 22 | return (self.__width + self.__height) * 2 23 | 24 | def area(self): 25 | """计算面积""" 26 | return self.__width * self.__height 27 | 28 | def __str__(self): 29 | """矩形对象的字符串表达式""" 30 | return '矩形[%f,%f]' % (self.__width, self.__height) 31 | 32 | def __del__(self): 33 | """析构器""" 34 | print('销毁矩形对象') 35 | 36 | 37 | if __name__ == '__main__': 38 | rect1 = Rect() 39 | print(rect1) 40 | print(rect1.perimeter()) 41 | print(rect1.area()) 42 | rect2 = Rect(3.5, 4.5) 43 | print(rect2) 44 | print(rect2.perimeter()) 45 | print(rect2.area()) 46 | -------------------------------------------------------------------------------- /Day01-15/Day13/coroutine1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用协程 - 模拟快递中心派发快递 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-21 8 | 9 | """ 10 | 11 | from time import sleep 12 | from random import random 13 | 14 | 15 | def build_deliver_man(man_id): 16 | total = 0 17 | while True: 18 | total += 1 19 | print('%d号快递员准备接今天的第%d单.' % (man_id, total)) 20 | pkg = yield 21 | print('%d号快递员收到编号为%s的包裹.' % (man_id, pkg)) 22 | sleep(random() * 3) 23 | 24 | 25 | def package_center(deliver_man, max_per_day): 26 | num = 1 27 | deliver_man.send(None) 28 | # next(deliver_man) 29 | while num <= max_per_day: 30 | package_id = 'PKG-%d' % num 31 | deliver_man.send(package_id) 32 | num += 1 33 | sleep(0.1) 34 | deliver_man.close() 35 | print('今天的包裹派送完毕!') 36 | 37 | 38 | dm = build_deliver_man(1) 39 | package_center(dm, 10) 40 | 41 | # 两个函数虽然没有调用关系但是创建快递员的函数作为一个协程协助了快递中心函数完成任务 42 | # 想一想如果有多个快递员的时候应该如何处理 43 | -------------------------------------------------------------------------------- /Day01-15/Day11/csv2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 写入CSV文件 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | import csv 12 | 13 | 14 | class Teacher(object): 15 | 16 | def __init__(self, name, age, title): 17 | self.__name = name 18 | self.__age = age 19 | self.__title = title 20 | self.__index = -1 21 | 22 | @property 23 | def name(self): 24 | return self.__name 25 | 26 | @property 27 | def age(self): 28 | return self.__age 29 | 30 | @property 31 | def title(self): 32 | return self.__title 33 | 34 | 35 | filename = 'teacher.csv' 36 | teachers = [Teacher('骆昊', 38, '叫兽'), Teacher('狄仁杰', 25, '砖家')] 37 | 38 | try: 39 | with open(filename, 'w') as f: 40 | writer = csv.writer(f) 41 | for teacher in teachers: 42 | writer.writerow([teacher.name, teacher.age, teacher.title]) 43 | except BaseException as e: 44 | print('无法写入文件:', filename) 45 | else: 46 | print('保存数据完成!') 47 | -------------------------------------------------------------------------------- /Day01-15/Day08/student.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 定义和使用学生类 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-08 8 | 9 | """ 10 | 11 | 12 | def _foo(): 13 | print('test') 14 | 15 | 16 | class Student(object): 17 | 18 | # __init__是一个特殊方法用于在创建对象时进行初始化操作 19 | # 通过这个方法我们可以为学生对象绑定name和age两个属性 20 | def __init__(self, name, age): 21 | self.name = name 22 | self.age = age 23 | 24 | def study(self, course_name): 25 | print('%s正在学习%s.' % (self.name, course_name)) 26 | 27 | # PEP 8要求标识符的名字用全小写多个单词用下划线连接 28 | # 但是很多程序员和公司更倾向于使用驼峰命名法(驼峰标识) 29 | def watch_av(self): 30 | if self.age < 18: 31 | print('%s只能观看《熊出没》.' % self.name) 32 | else: 33 | print('%s正在观看岛国爱情动作片.' % self.name) 34 | 35 | 36 | def main(): 37 | stu1 = Student('骆昊', 38) 38 | stu1.study('Python程序设计') 39 | stu1.watch_av() 40 | stu2 = Student('王大锤', 15) 41 | stu2.study('思想品德') 42 | stu2.watch_av() 43 | 44 | 45 | if __name__ == '__main__': 46 | main() -------------------------------------------------------------------------------- /Day41-55/car/templates/add.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 添加 6 | 12 | 13 | 14 |

添加违章记录

15 |
16 |

17 | {% for hint in hints %} 18 |

{{ hint }}
19 | {% endfor %} 20 |

21 |
22 | {% for field in f.visible_fields %} 23 |
24 | {{ field.label }} 25 | {{ field }} 26 | {% for error in field.errors %} 27 | {{ error }} 28 | {% endfor %} 29 |
30 | {% endfor %} 31 | {% csrf_token %} 32 | 33 |
34 | 35 | -------------------------------------------------------------------------------- /Day41-55/shop/cart/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-25 06:28 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Goods', 16 | fields=[ 17 | ('id', models.AutoField(db_column='gid', primary_key=True, serialize=False)), 18 | ('name', models.CharField(db_column='gname', max_length=50)), 19 | ('price', models.DecimalField(db_column='gprice', decimal_places=2, max_digits=10)), 20 | ('image', models.CharField(db_column='gimage', max_length=255)), 21 | ], 22 | options={ 23 | 'db_table': 'tb_goods', 24 | 'ordering': ('id',), 25 | }, 26 | ), 27 | ] 28 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/cart/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-25 05:11 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Goods', 16 | fields=[ 17 | ('id', models.AutoField(db_column='gid', primary_key=True, serialize=False)), 18 | ('name', models.CharField(db_column='gname', max_length=50)), 19 | ('price', models.DecimalField(db_column='gprice', decimal_places=2, max_digits=10)), 20 | ('image', models.CharField(db_column='gimage', max_length=255)), 21 | ], 22 | options={ 23 | 'db_table': 'tb_goods', 24 | 'ordering': ('id',), 25 | }, 26 | ), 27 | ] 28 | -------------------------------------------------------------------------------- /Day66-75/code/example08.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from bs4 import BeautifulSoup 3 | 4 | 5 | def main(): 6 | resp = requests.get('https://github.com/login') 7 | if resp.status_code != 200: 8 | return 9 | cookies = resp.cookies.get_dict() 10 | print(cookies) 11 | soup = BeautifulSoup(resp.text, 'lxml') 12 | utf8_value = \ 13 | soup.select_one('form input[name=utf8]').attrs['value'] 14 | authenticity_token_value = \ 15 | soup.select_one('form input[name=authenticity_token]').attrs['value'] 16 | data = { 17 | 'utf8': utf8_value, 18 | 'authenticity_token': authenticity_token_value, 19 | 'login': 'jackfrued@gmail.com', 20 | 'password': 'yourpassword' 21 | } 22 | resp = requests.post('https://github.com/session', 23 | data=data, cookies=cookies) 24 | print(resp.text) 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | -------------------------------------------------------------------------------- /Day66-75/Scrapy爬虫框架高级应用.md: -------------------------------------------------------------------------------- 1 | ## Scrapy爬虫框架高级应用 2 | 3 | ### Spider的用法 4 | 5 | 在Scrapy框架中,我们自定义的蜘蛛都继承自scrapy.spiders.Spider,这个类有一系列的属性和方法,具体如下所示: 6 | 7 | 1. name:爬虫的名字。 8 | 2. allowed_domains:允许爬取的域名,不在此范围的链接不会被跟进爬取。 9 | 3. start_urls:起始URL列表,当我们没有重写start_requests()方法时,就会从这个列表开始爬取。 10 | 4. custom_settings:用来存放蜘蛛专属配置的字典,这里的设置会覆盖全局的设置。 11 | 5. crawler:由from_crawler()方法设置的和蜘蛛对应的Crawler对象,Crawler对象包含了很多项目组件,利用它我们可以获取项目的配置信息,如调用crawler.settings.get()方法。 12 | 6. settings:用来获取爬虫全局设置的变量。 13 | 7. start_requests():此方法用于生成初始请求,它返回一个可迭代对象。该方法默认是使用GET请求访问起始URL,如果起始URL需要使用POST请求来访问就必须重写这个方法。 14 | 8. parse():当Response没有指定回调函数时,该方法就会被调用,它负责处理Response对象并返回结果,从中提取出需要的数据和后续的请求,该方法需要返回类型为Request或Item的可迭代对象(生成器当前也包含在其中,因此根据实际需要可以用return或yield来产生返回值)。 15 | 9. closed():当蜘蛛关闭时,该方法会被调用,通常用来做一些释放资源的善后操作。 16 | 17 | ### 中间件的应用 18 | 19 | #### 下载中间件 20 | 21 | 22 | 23 | #### 蜘蛛中间件 24 | 25 | 26 | 27 | ### Scrapy对接Selenium 28 | 29 | 30 | 31 | ### Scrapy部署到Docker 32 | 33 | -------------------------------------------------------------------------------- /Day01-15/Day14/mmdownloader.py: -------------------------------------------------------------------------------- 1 | from time import time 2 | from threading import Thread 3 | 4 | import requests 5 | 6 | 7 | class DownloadHanlder(Thread): 8 | 9 | def __init__(self, url): 10 | super().__init__() 11 | self.url = url 12 | 13 | def run(self): 14 | filename = self.url[self.url.rfind('/') + 1:] 15 | resp = requests.get(self.url) 16 | with open('/Users/Hao/Downloads/' + filename, 'wb') as f: 17 | f.write(resp.content) 18 | 19 | 20 | def main(): 21 | # 通过requests模块的get函数获取网络资源 22 | resp = requests.get( 23 | 'http://api.tianapi.com/meinv/?key=772a81a51ae5c780251b1f98ea431b84&num=10') 24 | # 将服务器返回的JSON格式的数据解析为字典 25 | data_model = resp.json() 26 | for mm_dict in data_model['newslist']: 27 | url = mm_dict['picUrl'] 28 | # 通过多线程的方式实现图片下载 29 | DownloadHanlder(url).start() 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /Day01-15/Day12/str1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 字符串常用操作 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-19 8 | 9 | """ 10 | 11 | import pyperclip 12 | 13 | # 转义字符 14 | print('My brother\'s name is \'007\'') 15 | # 原始字符串 16 | print(r'My brother\'s name is \'007\'') 17 | 18 | str = 'hello123world' 19 | print('he' in str) 20 | print('her' in str) 21 | # 字符串是否只包含字母 22 | print(str.isalpha()) 23 | # 字符串是否只包含字母和数字 24 | print(str.isalnum()) 25 | # 字符串是否只包含数字 26 | print(str.isdecimal()) 27 | 28 | print(str[0:5].isalpha()) 29 | print(str[5:8].isdecimal()) 30 | 31 | list = ['床前明月光', '疑是地上霜', '举头望明月', '低头思故乡'] 32 | print('-'.join(list)) 33 | sentence = 'You go your way I will go mine' 34 | words_list = sentence.split() 35 | print(words_list) 36 | email = ' jackfrued@126.com ' 37 | print(email) 38 | print(email.strip()) 39 | print(email.lstrip()) 40 | 41 | # 将文本放入系统剪切板中 42 | pyperclip.copy('老虎不发猫你当我病危呀') 43 | # 从系统剪切板获得文本 44 | # print(pyperclip.paste()) 45 | -------------------------------------------------------------------------------- /Day01-15/Day13/multithread6.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 多个线程共享数据 - 有锁的情况 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | import time 12 | import threading 13 | 14 | 15 | class Account(object): 16 | 17 | def __init__(self): 18 | self._balance = 0 19 | self._lock = threading.Lock() 20 | 21 | def deposit(self, money): 22 | # 获得锁后代码才能继续执行 23 | self._lock.acquire() 24 | try: 25 | new_balance = self._balance + money 26 | time.sleep(0.01) 27 | self._balance = new_balance 28 | finally: 29 | # 操作完成后一定要记着释放锁 30 | self._lock.release() 31 | 32 | @property 33 | def balance(self): 34 | return self._balance 35 | 36 | 37 | if __name__ == '__main__': 38 | account = Account() 39 | # 创建100个存款的线程向同一个账户中存钱 40 | for _ in range(100): 41 | threading.Thread(target=account.deposit, args=(1,)).start() 42 | # 等所有存款的线程都执行完毕 43 | time.sleep(2) 44 | print('账户余额为: ¥%d元' % account.balance) 45 | 46 | # 想一想结果为什么不是我们期望的100元 47 | -------------------------------------------------------------------------------- /Day41-55/oa/oa/urls.py: -------------------------------------------------------------------------------- 1 | """oa URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | 19 | from hrs import views 20 | 21 | urlpatterns = [ 22 | path('', views.index), 23 | path('admin/', admin.site.urls), 24 | path('hrs/', include('hrs.urls')), 25 | ] 26 | -------------------------------------------------------------------------------- /Day01-15/Day06/function5.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 函数的参数 4 | - 默认参数 5 | - 可变参数 6 | - 关键字参数 7 | - 命名关键字参数 8 | 9 | Version: 0.1 10 | Author: 骆昊 11 | Date: 2018-03-05 12 | 13 | """ 14 | 15 | 16 | # 参数默认值 17 | def f1(a, b=5, c=10): 18 | return a + b * 2 + c * 3 19 | 20 | 21 | print(f1(1, 2, 3)) 22 | print(f1(100, 200)) 23 | print(f1(100)) 24 | print(f1(c=2, b=3, a=1)) 25 | 26 | 27 | # 可变参数 28 | def f2(*args): 29 | sum = 0 30 | for num in args: 31 | sum += num 32 | return sum 33 | 34 | 35 | print(f2(1, 2, 3)) 36 | print(f2(1, 2, 3, 4, 5)) 37 | print(f2()) 38 | 39 | 40 | # 关键字参数 41 | def f3(**kw): 42 | if 'name' in kw: 43 | print('欢迎你%s!' % kw['name']) 44 | elif 'tel' in kw: 45 | print('你的联系电话是: %s!' % kw['tel']) 46 | else: 47 | print('没找到你的个人信息!') 48 | 49 | 50 | param = {'name': '骆昊', 'age': 38} 51 | f3(**param) 52 | f3(name='骆昊', age=38, tel='13866778899') 53 | f3(user='骆昊', age=38, tel='13866778899') 54 | f3(user='骆昊', age=38, mobile='13866778899') 55 | -------------------------------------------------------------------------------- /Day01-15/Day08/circle.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 练习 4 | 修一个游泳池 半径(以米为单位)在程序运行时输入 游泳池外修一条3米宽的过道 5 | 过道的外侧修一圈围墙 已知过道的造价为25元每平米 围墙的造价为32.5元每米 6 | 输出围墙和过道的总造价分别是多少钱(精确到小数点后2位) 7 | 8 | Version: 0.1 9 | Author: 骆昊 10 | Date: 2018-03-08 11 | 12 | """ 13 | 14 | import math 15 | 16 | 17 | class Circle(object): 18 | 19 | def __init__(self, radius): 20 | self._radius = radius 21 | 22 | @property 23 | def radius(self): 24 | return self._radius 25 | 26 | @radius.setter 27 | def radius(self, radius): 28 | self._radius = radius if radius > 0 else 0 29 | 30 | @property 31 | def perimeter(self): 32 | return 2 * math.pi * self._radius 33 | 34 | @property 35 | def area(self): 36 | return math.pi * self._radius * self._radius 37 | 38 | 39 | if __name__ == '__main__': 40 | radius = float(input('请输入游泳池的半径: ')) 41 | small = Circle(radius) 42 | big = Circle(radius + 3) 43 | print('围墙的造价为: ¥%.1f元' % (big.perimeter * 115)) 44 | print('过道的造价为: ¥%.1f元' % ((big.area - small.area) * 65)) 45 | -------------------------------------------------------------------------------- /Day01-15/Day13/asyncio3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 异步I/O操作 - asyncio模块 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-21 8 | 9 | """ 10 | 11 | import asyncio 12 | 13 | 14 | async def wget(host): 15 | print('wget %s...' % host) 16 | connect = asyncio.open_connection(host, 80) 17 | # 异步方式等待连接结果 18 | reader, writer = await connect 19 | header = 'GET / HTTP/1.0\r\nHost: %s\r\n\r\n' % host 20 | writer.write(header.encode('utf-8')) 21 | # 异步I/O方式执行写操作 22 | await writer.drain() 23 | while True: 24 | # 异步I/O方式执行读操作 25 | line = await reader.readline() 26 | if line == b'\r\n': 27 | break 28 | print('%s header > %s' % (host, line.decode('utf-8').rstrip())) 29 | writer.close() 30 | 31 | 32 | loop = asyncio.get_event_loop() 33 | # 通过生成式语法创建一个装了三个协程的列表 34 | hosts_list = ['www.sina.com.cn', 'www.sohu.com', 'www.163.com'] 35 | tasks = [wget(host) for host in hosts_list] 36 | # 下面的方法将异步I/O操作放入EventLoop直到执行完毕 37 | loop.run_until_complete(asyncio.wait(tasks)) 38 | loop.close() 39 | -------------------------------------------------------------------------------- /Day66-75/code/example04.py: -------------------------------------------------------------------------------- 1 | from urllib.parse import urljoin 2 | 3 | import re 4 | import requests 5 | 6 | from bs4 import BeautifulSoup 7 | 8 | 9 | def main(): 10 | headers = {'user-agent': 'Baiduspider'} 11 | proxies = { 12 | 'http': 'http://122.114.31.177:808' 13 | } 14 | base_url = 'https://www.zhihu.com/' 15 | seed_url = urljoin(base_url, 'explore') 16 | resp = requests.get(seed_url, 17 | headers=headers, 18 | proxies=proxies) 19 | soup = BeautifulSoup(resp.text, 'lxml') 20 | href_regex = re.compile(r'^/question') 21 | link_set = set() 22 | for a_tag in soup.find_all('a', {'href': href_regex}): 23 | if 'href' in a_tag.attrs: 24 | href = a_tag.attrs['href'] 25 | full_url = urljoin(base_url, href) 26 | link_set.add(full_url) 27 | print('Total %d question pages found.' % len(link_set)) 28 | 29 | 30 | if __name__ == '__main__': 31 | main() 32 | -------------------------------------------------------------------------------- /Day66-75/code/example12.py: -------------------------------------------------------------------------------- 1 | import base64 2 | 3 | from PIL import Image, ImageFilter 4 | from pytesseract import image_to_string 5 | 6 | import requests 7 | from io import BytesIO 8 | 9 | 10 | def main(): 11 | guido_img = Image.open(open('guido.jpg', 'rb')) 12 | guido2_img = guido_img.filter(ImageFilter.GaussianBlur) 13 | guido2_img.save(open('guido2.jpg', 'wb')) 14 | 15 | img1 = Image.open(open('tesseract.png', 'rb')) 16 | img2 = img1.point(lambda x: 0 if x < 128 else 255) 17 | img2.save(open('tesseract2.png', 'wb')) 18 | 19 | print(image_to_string(img2)) 20 | 21 | resp = requests.get('https://pin2.aliyun.com/get_img?type=150_40&identity=mailsso.mxhichina.com&sessionid=k0xHyBxU3K3dGXb59mP9cdeTXxL9gLHSTKhRZCryHxpOoyk4lAVuJhgw==') 22 | img3 = Image.open(BytesIO(resp.content)) 23 | img3.save('captcha.jpg') 24 | print(image_to_string(img3)) 25 | print(base64.b64encode(resp.content)) 26 | 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /Day01-15/Day14/chatclient.py: -------------------------------------------------------------------------------- 1 | from socket import socket 2 | from threading import Thread 3 | 4 | 5 | def main(): 6 | 7 | class RefreshScreenThread(Thread): 8 | 9 | def __init__(self, client): 10 | super().__init__() 11 | self._client = client 12 | 13 | def run(self): 14 | while running: 15 | data = self._client.recv(1024) 16 | print(data.decode('utf-8')) 17 | 18 | nickname = input('请输入你的昵称: ') 19 | myclient = socket() 20 | myclient.connect(('10.7.189.118', 12345)) 21 | running = True 22 | RefreshScreenThread(myclient).start() 23 | while running: 24 | content = input('请发言: ') 25 | if content == 'byebye': 26 | myclient.send(content.encode('utf-8')) 27 | running = False 28 | else: 29 | msg = nickname + ': ' + content 30 | myclient.send(msg.encode('utf-8')) 31 | 32 | 33 | if __name__ == '__main__': 34 | main() 35 | -------------------------------------------------------------------------------- /Day41-55/car/car/urls.py: -------------------------------------------------------------------------------- 1 | """car URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.conf.urls import url 18 | 19 | from search import views 20 | 21 | urlpatterns = [ 22 | url(r'^search$', views.search), 23 | url(r'^search2$', views.ajax_search), 24 | url(r'^add', views.add), 25 | url(r'^admin/', admin.site.urls), 26 | ] 27 | -------------------------------------------------------------------------------- /Day41-55/shop/shop/urls.py: -------------------------------------------------------------------------------- 1 | """shop URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | from cart import views 20 | 21 | urlpatterns = [ 22 | path('', views.index), 23 | path('add_to_cart/', views.add_to_cart), 24 | path('show_cart', views.show_cart), 25 | path('admin/', admin.site.urls), 26 | ] 27 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/shop/urls.py: -------------------------------------------------------------------------------- 1 | """shop URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | from cart import views 20 | 21 | urlpatterns = [ 22 | path('', views.index), 23 | path('show_cart', views.show_cart), 24 | path('add_to_cart/', views.add_to_cart), 25 | path('admin/', admin.site.urls), 26 | ] 27 | -------------------------------------------------------------------------------- /Day01-15/Day13/coroutine2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用协程 - 查看协程的状态 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-21 8 | 9 | """ 10 | 11 | from time import sleep 12 | from inspect import getgeneratorstate 13 | 14 | 15 | def build_deliver_man(man_id): 16 | total = 0 17 | while True: 18 | total += 1 19 | print('%d号快递员准备接今天的第%d单.' % (man_id, total)) 20 | pkg = yield 21 | print('%d号快递员收到编号为%s的包裹.' % (man_id, pkg)) 22 | sleep(0.5) 23 | 24 | 25 | def package_center(deliver_man, max_per_day): 26 | num = 1 27 | # 创建状态(GEN_CREATED) - 等待开始执行 28 | print(getgeneratorstate(deliver_man)) 29 | deliver_man.send(None) 30 | # 挂起状态(GEN_SUSPENDED) - 在yield表达式处暂停 31 | print(getgeneratorstate(deliver_man)) 32 | # next(deliver_man) 33 | while num <= max_per_day: 34 | package_id = 'PKG-%d' % num 35 | deliver_man.send(package_id) 36 | num += 1 37 | deliver_man.close() 38 | # 结束状态(GEN_CLOSED) - 执行完毕 39 | print(getgeneratorstate(deliver_man)) 40 | print('今天的包裹派送完毕!') 41 | 42 | 43 | dm = build_deliver_man(1) 44 | package_center(dm, 10) 45 | -------------------------------------------------------------------------------- /Day01-15/Day14/timeserver.py: -------------------------------------------------------------------------------- 1 | from socket import socket, SOCK_STREAM, AF_INET 2 | from datetime import datetime 3 | 4 | 5 | def main(): 6 | # 1.创建套接字对象并指定使用哪种传输服务 7 | # family=AF_INET - IPv4地址 8 | # family=AF_INET6 - IPv6地址 9 | # type=SOCK_STREAM - TCP套接字 10 | # type=SOCK_DGRAM - UDP套接字 11 | # type=SOCK_RAW - 原始套接字 12 | server = socket(family=AF_INET, type=SOCK_STREAM) 13 | # 2.绑定IP地址和端口(区分不同的服务) 14 | server.bind(('192.168.1.2', 6789)) 15 | # 3.开启监听 - 监听客户端连接到服务器 16 | server.listen(512) 17 | print('服务器启动开始监听...') 18 | # 4.通过循环接收客户端的连接并作出相应的处理(提供服务) 19 | while True: 20 | # accept方法是一个阻塞方法如果没有客户端连接到服务器 21 | # 这个方法就会阻塞代码不会向下执行 22 | # accept方法返回元组其中的第一个元素是客户端对象 23 | # 第二个元素是客户端的地址(由IP和端口两部分构成) 24 | client, addr = server.accept() 25 | print(str(addr) + '连接到了服务器.') 26 | # 5.发送数据 27 | client.send(str(datetime.now()).encode('utf-8')) 28 | # 6.断开连接 29 | client.close() 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /Day01-15/Day07/lottery.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 双色球随机选号程序 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | from random import randrange, randint, sample 12 | 13 | 14 | def display(balls): 15 | """ 16 | 输出列表中的双色球号码 17 | """ 18 | for index, ball in enumerate(balls): 19 | if index == len(balls) - 1: 20 | print('|', end=' ') 21 | print('%02d' % ball, end=' ') 22 | print() 23 | 24 | 25 | def random_select(): 26 | """ 27 | 随机选择一组号码 28 | """ 29 | red_balls = [x for x in range(1, 34)] 30 | selected_balls = [] 31 | for _ in range(6): 32 | index = randrange(len(red_balls)) 33 | selected_balls.append(red_balls[index]) 34 | del red_balls[index] 35 | # 上面的for循环也可以写成下面这行代码 36 | # sample函数是random模块下的函数 37 | # selected_balls = sample(red_balls, 6) 38 | selected_balls.sort() 39 | selected_balls.append(randint(1, 16)) 40 | return selected_balls 41 | 42 | 43 | def main(): 44 | n = int(input('机选几注: ')) 45 | for _ in range(n): 46 | display(random_select()) 47 | 48 | 49 | if __name__ == '__main__': 50 | main() 51 | -------------------------------------------------------------------------------- /Day01-15/Day13/multithread3.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用多线程的情况 - 模拟多个下载任务 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | from random import randint 12 | from time import time, sleep 13 | import threading 14 | 15 | 16 | class DownloadTask(threading.Thread): 17 | 18 | def __init__(self, filename): 19 | super().__init__() 20 | self._filename = filename 21 | 22 | def run(self): 23 | print('开始下载%s...' % self._filename) 24 | time_to_download = randint(5, 10) 25 | print('剩余时间%d秒.' % time_to_download) 26 | sleep(time_to_download) 27 | print('%s下载完成!' % self._filename) 28 | 29 | 30 | def main(): 31 | start = time() 32 | # 将多个下载任务放到多个线程中执行 33 | # 通过自定义的线程类创建线程对象 线程启动后会回调执行run方法 34 | thread1 = DownloadTask('Python从入门到住院.pdf') 35 | thread1.start() 36 | thread2 = DownloadTask('Peking Hot.avi') 37 | thread2.start() 38 | thread1.join() 39 | thread2.join() 40 | end = time() 41 | print('总共耗费了%.3f秒' % (end - start)) 42 | 43 | 44 | if __name__ == '__main__': 45 | main() 46 | 47 | # 请注意通过threading.Thread创建的线程默认是非守护线程 48 | -------------------------------------------------------------------------------- /Day41-55/car/search/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11 on 2018-05-24 01:16 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='CarRecord', 18 | fields=[ 19 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 20 | ('carno', models.CharField(max_length=7)), 21 | ('reason', models.CharField(max_length=50)), 22 | ('date', models.DateTimeField(db_column='happen_date')), 23 | ('punlish', models.CharField(max_length=50)), 24 | ('isdone', models.BooleanField(default=False)), 25 | ], 26 | options={ 27 | 'db_table': 'tb_car_record', 28 | }, 29 | ), 30 | ] 31 | -------------------------------------------------------------------------------- /Day01-15/Day13/multithread1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用多线程的情况 - 模拟多个下载任务 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | from random import randint 12 | from time import time, sleep 13 | import atexit 14 | import _thread 15 | 16 | 17 | def download_task(filename): 18 | print('开始下载%s...' % filename) 19 | time_to_download = randint(5, 10) 20 | print('剩余时间%d秒.' % time_to_download) 21 | sleep(time_to_download) 22 | print('%s下载完成!' % filename) 23 | 24 | 25 | def shutdown_hook(start): 26 | end = time() 27 | print('总共耗费了%.3f秒.' % (end - start)) 28 | 29 | 30 | def main(): 31 | start = time() 32 | # 将多个下载任务放到多个线程中执行 33 | thread1 = _thread.start_new_thread(download_task, ('Python从入门到住院.pdf',)) 34 | thread2 = _thread.start_new_thread(download_task, ('Peking Hot.avi',)) 35 | # 注册关机钩子在程序执行结束前计算执行时间 36 | atexit.register(shutdown_hook, start) 37 | 38 | 39 | if __name__ == '__main__': 40 | main() 41 | 42 | # 执行这里的代码会引发致命错误(不要被这个词吓到) 因为主线程结束后下载线程再想执行就会出问题 43 | # 需要说明一下 由于_thread模块属于比较底层的线程操作而且不支持守护线程的概念 44 | # 在实际开发中会有诸多不便 因此我们推荐使用threading模块提供的高级操作进行多线程编程 45 | -------------------------------------------------------------------------------- /Day01-15/Day13/singlethread2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 不使用多线程的情况 - 耗时间的任务阻塞主事件循环 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | import time 12 | import tkinter 13 | import tkinter.messagebox 14 | 15 | 16 | def download(): 17 | # 模拟下载任务需要花费10秒钟时间 18 | time.sleep(10) 19 | tkinter.messagebox.showinfo('提示', '下载完成!') 20 | 21 | 22 | def show_about(): 23 | tkinter.messagebox.showinfo('关于', '作者: 骆昊(v1.0)') 24 | 25 | 26 | def main(): 27 | top = tkinter.Tk() 28 | top.title('单线程') 29 | top.geometry('200x150') 30 | top.wm_attributes('-topmost', True) 31 | 32 | panel = tkinter.Frame(top) 33 | button1 = tkinter.Button(panel, text='下载', command=download) 34 | button1.pack(side='left') 35 | button2 = tkinter.Button(panel, text='关于', command=show_about) 36 | button2.pack(side='right') 37 | panel.pack(side='bottom') 38 | 39 | tkinter.mainloop() 40 | 41 | 42 | if __name__ == '__main__': 43 | main() 44 | 45 | 46 | # 在不使用多线程的情况下 一旦点击下载按钮 由于该操作需要花费10秒中的时间 47 | # 整个主消息循环也会被阻塞10秒钟无法响应其他的事件 48 | # 事实上 对于没有因果关系的子任务 这种顺序执行的方式并不合理 49 | -------------------------------------------------------------------------------- /Day01-15/Day09/car2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 属性的使用 4 | - 使用已有方法定义访问器/修改器/删除器 5 | 6 | Version: 0.1 7 | Author: 骆昊 8 | Date: 2018-03-12 9 | 10 | """ 11 | 12 | 13 | class Car(object): 14 | 15 | def __init__(self, brand, max_speed): 16 | self.set_brand(brand) 17 | self.set_max_speed(max_speed) 18 | 19 | def get_brand(self): 20 | return self._brand 21 | 22 | def set_brand(self, brand): 23 | self._brand = brand 24 | 25 | def get_max_speed(self): 26 | return self._max_speed 27 | 28 | def set_max_speed(self, max_speed): 29 | if max_speed < 0: 30 | raise ValueError('Invalid max speed for car') 31 | self._max_speed = max_speed 32 | 33 | def __str__(self): 34 | return 'Car: [品牌=%s, 最高时速=%d]' % (self._brand, self._max_speed) 35 | 36 | # 用已有的修改器和访问器定义属性 37 | brand = property(get_brand, set_brand) 38 | max_speed = property(get_max_speed, set_max_speed) 39 | 40 | 41 | car = Car('QQ', 120) 42 | print(car) 43 | # ValueError 44 | # car.max_speed = -100 45 | car.max_speed = 320 46 | car.brand = "Benz" 47 | print(car) 48 | print(Car.brand) 49 | print(Car.brand.fget) 50 | print(Car.brand.fset) 51 | -------------------------------------------------------------------------------- /Day66-75/code/image360/image360/spiders/image.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from json import loads 3 | from urllib.parse import urlencode 4 | 5 | import scrapy 6 | 7 | from image360.items import BeautyItem 8 | 9 | 10 | class ImageSpider(scrapy.Spider): 11 | name = 'image' 12 | allowed_domains = ['image.so.com'] 13 | 14 | def start_requests(self): 15 | base_url = 'http://image.so.com/zj?' 16 | param = {'ch': 'beauty', 'listtype': 'new', 'temp': 1} 17 | for page in range(10): 18 | param['sn'] = page * 30 19 | full_url = base_url + urlencode(param) 20 | yield scrapy.Request(url=full_url) 21 | 22 | def parse(self, response): 23 | model_dict = loads(response.text) 24 | for elem in model_dict['list']: 25 | item = BeautyItem() 26 | item['title'] = elem['group_title'] 27 | item['tag'] = elem['tag'] 28 | item['width'] = elem['cover_width'] 29 | item['height'] = elem['cover_height'] 30 | item['url'] = elem['qhimg_url'] 31 | yield item 32 | -------------------------------------------------------------------------------- /Day01-15/Day05/craps.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Craps赌博游戏 4 | 玩家摇两颗色子 如果第一次摇出7点或11点 玩家胜 5 | 如果摇出2点 3点 12点 庄家胜 其他情况游戏继续 6 | 玩家再次要色子 如果摇出7点 庄家胜 7 | 如果摇出第一次摇的点数 玩家胜 8 | 否则游戏继续 玩家继续摇色子 9 | 玩家进入游戏时有1000元的赌注 全部输光游戏结束 10 | 11 | Version: 0.1 12 | Author: 骆昊 13 | Date: 2018-03-02 14 | 15 | """ 16 | 17 | from random import randint 18 | 19 | money = 1000 20 | while money > 0: 21 | print('你的总资产为:', money) 22 | needs_go_on = False 23 | while True: 24 | debt = int(input('请下注: ')) 25 | if debt > 0 and debt <= money: 26 | break 27 | first = randint(1, 6) + randint(1, 6) 28 | print('玩家摇出了%d点' % first) 29 | if first == 7 or first == 11: 30 | print('玩家胜!') 31 | money += debt 32 | elif first == 2 or first == 3 or first == 12: 33 | print('庄家胜!') 34 | money -= debt 35 | else: 36 | needs_go_on = True 37 | 38 | while needs_go_on: 39 | current = randint(1, 6) + randint(1, 6) 40 | print('玩家摇出了%d点' % current) 41 | if current == 7: 42 | print('庄家胜') 43 | money -= debt 44 | needs_go_on = False 45 | elif current == first: 46 | print('玩家胜') 47 | money += debt 48 | needs_go_on = False 49 | 50 | print('你破产了, 游戏结束!') 51 | -------------------------------------------------------------------------------- /Day66-75/code/coroutine02.py: -------------------------------------------------------------------------------- 1 | from time import sleep 2 | 3 | from myutils import coroutine 4 | 5 | 6 | @coroutine 7 | def create_delivery_man(name, capacity=1): 8 | buffer = [] 9 | while True: 10 | size = 0 11 | while size < capacity: 12 | pkg_name = yield 13 | if pkg_name: 14 | size += 1 15 | buffer.append(pkg_name) 16 | print('%s正在接受%s' % (name, pkg_name)) 17 | else: 18 | break 19 | print('=====%s正在派送%d件包裹=====' % (name, len(buffer))) 20 | sleep(3) 21 | buffer.clear() 22 | 23 | 24 | def create_package_center(consumer, max_packages): 25 | num = 0 26 | while num <= max_packages: 27 | print('快递中心准备派送%d号包裹' % num) 28 | consumer.send('包裹-%d' % num) 29 | num += 1 30 | if num % 10 == 0: 31 | sleep(5) 32 | consumer.send(None) 33 | 34 | 35 | def main(): 36 | print(create_delivery_man.__name__) 37 | dm = create_delivery_man('王大锤', 7) 38 | create_package_center(dm, 25) 39 | 40 | 41 | if __name__ == '__main__': 42 | main() 43 | -------------------------------------------------------------------------------- /Day01-15/Day09/clock.py: -------------------------------------------------------------------------------- 1 | from time import time, localtime, sleep 2 | 3 | 4 | class Clock(object): 5 | """数字时钟""" 6 | 7 | def __init__(self, hour=0, minute=0, second=0): 8 | self._hour = hour 9 | self._minute = minute 10 | self._second = second 11 | 12 | @classmethod 13 | def now(cls): 14 | ctime = localtime(time()) 15 | return cls(ctime.tm_hour, ctime.tm_min, ctime.tm_sec) 16 | 17 | def run(self): 18 | """走字""" 19 | self._second += 1 20 | if self._second == 60: 21 | self._second = 0 22 | self._minute += 1 23 | if self._minute == 60: 24 | self._minute = 0 25 | self._hour += 1 26 | if self._hour == 24: 27 | self._hour = 0 28 | 29 | def show(self): 30 | """显示时间""" 31 | return '%02d:%02d:%02d' % \ 32 | (self._hour, self._minute, self._second) 33 | 34 | 35 | def main(): 36 | clock = Clock.now() 37 | while True: 38 | print(clock.show()) 39 | sleep(1) 40 | clock.run() 41 | 42 | 43 | if __name__ == '__main__': 44 | main() 45 | -------------------------------------------------------------------------------- /Day01-15/Day10/gui2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用tkinter创建GUI 4 | - 使用画布绘图 5 | - 处理鼠标事件 6 | 7 | Version: 0.1 8 | Author: 骆昊 9 | Date: 2018-03-14 10 | 11 | """ 12 | 13 | import tkinter 14 | 15 | 16 | def mouse_evt_handler(evt=None): 17 | row = round((evt.y - 20) / 40) 18 | col = round((evt.x - 20) / 40) 19 | pos_x = 40 * col 20 | pos_y = 40 * row 21 | canvas.create_oval(pos_x, pos_y, 40 + pos_x, 40 + pos_y, fill='black') 22 | 23 | 24 | top = tkinter.Tk() 25 | # 设置窗口尺寸 26 | top.geometry('620x620') 27 | # 设置窗口标题 28 | top.title('五子棋') 29 | # 设置窗口大小不可改变 30 | top.resizable(False, False) 31 | # 设置窗口置顶 32 | top.wm_attributes('-topmost', 1) 33 | canvas = tkinter.Canvas(top, width=600, height=600, bd=0, highlightthickness=0) 34 | canvas.bind('', mouse_evt_handler) 35 | canvas.create_rectangle(0, 0, 600, 600, fill='yellow', outline='white') 36 | for index in range(15): 37 | canvas.create_line(20, 20 + 40 * index, 580, 20 + 40 * index, fill='black') 38 | canvas.create_line(20 + 40 * index, 20, 20 + 40 * index, 580, fill='black') 39 | canvas.create_rectangle(15, 15, 585, 585, outline='black', width=4) 40 | canvas.pack() 41 | tkinter.mainloop() 42 | 43 | # 请思考如何用面向对象的编程思想对上面的代码进行封装 44 | -------------------------------------------------------------------------------- /Day01-15/Day06/function4.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Python常用模块 4 | - 运行时服务相关模块: copy / pickle / sys / ... 5 | - 数学相关模块: decimal / math / random / ... 6 | - 字符串处理模块: codecs / re / ... 7 | - 文件处理相关模块: shutil / gzip / ... 8 | - 操作系统服务相关模块: datetime / os / time / logging / io / ... 9 | - 进程和线程相关模块: multiprocessing / threading / queue 10 | - 网络应用相关模块: ftplib / http / smtplib / urllib / ... 11 | - Web编程相关模块: cgi / webbrowser 12 | - 数据处理和编码模块: base64 / csv / html.parser / json / xml / ... 13 | 14 | Version: 0.1 15 | Author: 骆昊 16 | Date: 2018-03-05 17 | 18 | """ 19 | 20 | import time 21 | import shutil 22 | import os 23 | 24 | seconds = time.time() 25 | print(seconds) 26 | localtime = time.localtime(seconds) 27 | print(localtime) 28 | print(localtime.tm_year) 29 | print(localtime.tm_mon) 30 | print(localtime.tm_mday) 31 | asctime = time.asctime(localtime) 32 | print(asctime) 33 | strtime = time.strftime('%Y-%m-%d %H:%M:%S', localtime) 34 | print(strtime) 35 | mydate = time.strptime('2018-1-1', '%Y-%m-%d') 36 | print(mydate) 37 | 38 | shutil.copy('/Users/Hao/hello.py', '/Users/Hao/Desktop/first.py') 39 | os.system('ls -l') 40 | os.chdir('/Users/Hao') 41 | os.system('ls -l') 42 | os.mkdir('test') 43 | -------------------------------------------------------------------------------- /Day01-15/Day07/tic-tac-toe.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 井字棋游戏 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-06 8 | 9 | """ 10 | 11 | import os 12 | 13 | 14 | 15 | def print_board(board): 16 | print(board['TL'] + '|' + board['TM'] + '|' + board['TR']) 17 | print('-+-+-') 18 | print(board['ML'] + '|' + board['MM'] + '|' + board['MR']) 19 | print('-+-+-') 20 | print(board['BL'] + '|' + board['BM'] + '|' + board['BR']) 21 | 22 | 23 | def main(): 24 | init_board = { 25 | 'TL': ' ', 'TM': ' ', 'TR': ' ', 26 | 'ML': ' ', 'MM': ' ', 'MR': ' ', 27 | 'BL': ' ', 'BM': ' ', 'BR': ' ' 28 | } 29 | begin = True 30 | while begin: 31 | curr_board = init_board.copy() 32 | begin = False 33 | turn = 'x' 34 | counter = 0 35 | os.system('clear') 36 | print_board(curr_board) 37 | while counter < 9: 38 | move = input('轮到%s走棋, 请输入位置: ' % turn) 39 | if curr_board[move] == ' ': 40 | counter += 1 41 | curr_board[move] = turn 42 | if turn == 'x': 43 | turn = 'o' 44 | else: 45 | turn = 'x' 46 | os.system('clear') 47 | print_board(curr_board) 48 | choice = input('再玩一局?(yes|no)') 49 | begin = choice == 'yes' 50 | 51 | 52 | if __name__ == '__main__': 53 | main() 54 | -------------------------------------------------------------------------------- /Day01-15/Day08/guess.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 面向对象版本的猜数字游戏 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-08 8 | 9 | """ 10 | 11 | from random import randint 12 | 13 | 14 | class GuessMachine(object): 15 | 16 | def __init__(self): 17 | self._answer = None 18 | self._counter = None 19 | self._hint = None 20 | 21 | def reset(self): 22 | self._answer = randint(1, 100) 23 | self._counter = 0 24 | self._hint = None 25 | 26 | def guess(self, your_answer): 27 | self._counter += 1 28 | if your_answer > self._answer: 29 | self._hint = '小一点' 30 | elif your_answer < self._answer: 31 | self._hint = '大一点' 32 | else: 33 | self._hint = '恭喜你猜对了' 34 | return True 35 | return False 36 | 37 | @property 38 | def counter(self): 39 | return self._counter 40 | 41 | @property 42 | def hint(self): 43 | return self._hint 44 | 45 | 46 | if __name__ == '__main__': 47 | gm = GuessMachine() 48 | play_again = True 49 | while play_again: 50 | game_over = False 51 | gm.reset() 52 | while not game_over: 53 | your_answer = int(input('请输入: ')) 54 | game_over = gm.guess(your_answer) 55 | print(gm.hint) 56 | if gm.counter > 7: 57 | print('智商余额不足!') 58 | play_again = input('再玩一次?(yes|no)') == 'yes' 59 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # ORM - 对象关系映射 4 | # 对象模型 <---> 关系模型 5 | # 实体类 <---> 二维表 6 | # 属性 <---> 列 7 | # 对象 <---> 记录 8 | 9 | 10 | class Dept(models.Model): 11 | no = models.IntegerField(primary_key=True, verbose_name='部门编号') 12 | name = models.CharField(max_length=20, verbose_name='部门名称') 13 | location = models.CharField(max_length=10, verbose_name='部门所在地') 14 | excellent = models.BooleanField(default=0, verbose_name='是否优秀') 15 | 16 | def __str__(self): 17 | return self.name 18 | 19 | class Meta: 20 | db_table = 'tb_dept' 21 | 22 | 23 | class Emp(models.Model): 24 | no = models.IntegerField(primary_key=True) 25 | name = models.CharField(max_length=20) 26 | job = models.CharField(max_length=10) 27 | mgr = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL) 28 | # mgr = models.IntegerField(null=True, blank=True) 29 | sal = models.DecimalField(max_digits=7, decimal_places=2) 30 | comm = models.DecimalField(max_digits=7, decimal_places=2, null=True, blank=True) 31 | dept = models.ForeignKey(Dept, on_delete=models.PROTECT) 32 | 33 | class Meta: 34 | db_table = 'tb_emp' 35 | -------------------------------------------------------------------------------- /Day01-15/Day08/clock.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 定义和使用时钟类 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-08 8 | 9 | """ 10 | 11 | import time 12 | import os 13 | 14 | 15 | class Clock(object): 16 | 17 | # Python中的函数是没有重载的概念的 18 | # 因为Python中函数的参数没有类型而且支持缺省参数和可变参数 19 | # 用关键字参数让构造器可以传入任意多个参数来实现其他语言中的构造器重载 20 | def __init__(self, **kw): 21 | if 'hour' in kw and 'minute' in kw and 'second' in kw: 22 | self._hour = kw['hour'] 23 | self._minute = kw['minute'] 24 | self._second = kw['second'] 25 | else: 26 | tm = time.localtime(time.time()) 27 | self._hour = tm.tm_hour 28 | self._minute = tm.tm_min 29 | self._second = tm.tm_sec 30 | 31 | def run(self): 32 | self._second += 1 33 | if self._second == 60: 34 | self._second = 0 35 | self._minute += 1 36 | if self._minute == 60: 37 | self._minute = 0 38 | self._hour += 1 39 | if self._hour == 24: 40 | self._hour = 0 41 | 42 | def show(self): 43 | return '%02d:%02d:%02d' % (self._hour, self._minute, self._second) 44 | 45 | 46 | if __name__ == '__main__': 47 | # clock = Clock(hour=10, minute=5, second=58) 48 | clock = Clock() 49 | while True: 50 | os.system('clear') 51 | print(clock.show()) 52 | time.sleep(1) 53 | clock.run() 54 | -------------------------------------------------------------------------------- /Day01-15/Day09/triangle.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 实例方法和类方法的应用 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-12 8 | 9 | """ 10 | 11 | from math import sqrt 12 | 13 | 14 | class Triangle(object): 15 | 16 | def __init__(self, a, b, c): 17 | self._a = a 18 | self._b = b 19 | self._c = c 20 | 21 | # 静态方法 22 | @staticmethod 23 | def is_valid(a, b, c): 24 | return a + b > c and b + c > a and c + a > b 25 | 26 | # 实例方法 27 | def perimeter(self): 28 | return self._a + self._b + self._c 29 | 30 | # 实例方法 31 | def area(self): 32 | p = self.perimeter() / 2 33 | return sqrt(p * (p - self._a) * (p - self._b) * (p - self._c)) 34 | 35 | 36 | if __name__ == '__main__': 37 | # 用字符串的split方法将字符串拆分成一个列表 38 | # 再通过map函数对列表中的每个字符串进行映射处理成小数 39 | a, b, c = map(float, input('请输入三条边: ').split()) 40 | # 先判断给定长度的三条边能否构成三角形 41 | # 如果能才创建三角形对象 42 | if Triangle.is_valid(a, b, c): 43 | tri = Triangle(a, b, c) 44 | print('周长:', tri.perimeter()) 45 | print('面积:', tri.area()) 46 | # 如果传入对象作为方法参数也可以通过类调用实例方法 47 | # print('周长:', Triangle.perimeter(tri)) 48 | # print('面积:', Triangle.area(tri)) 49 | # 看看下面的代码就知道其实二者本质上是一致的 50 | # print(type(tri.perimeter)) 51 | # print(type(Triangle.perimeter)) 52 | else: 53 | print('不能构成三角形.') 54 | -------------------------------------------------------------------------------- /Day01-15/Day09/shape.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 继承的应用 4 | - 抽象类 5 | - 抽象方法 6 | - 方法重写 7 | - 多态 8 | 9 | Version: 0.1 10 | Author: 骆昊 11 | Date: 2018-03-12 12 | 13 | """ 14 | 15 | from abc import ABCMeta, abstractmethod 16 | from math import pi 17 | 18 | 19 | class Shape(object, metaclass=ABCMeta): 20 | 21 | @abstractmethod 22 | def perimeter(self): 23 | pass 24 | 25 | @abstractmethod 26 | def area(self): 27 | pass 28 | 29 | 30 | class Circle(Shape): 31 | 32 | def __init__(self, radius): 33 | self._radius = radius 34 | 35 | def perimeter(self): 36 | return 2 * pi * self._radius 37 | 38 | def area(self): 39 | return pi * self._radius ** 2 40 | 41 | def __str__(self): 42 | return '我是一个圆' 43 | 44 | 45 | class Rect(Shape): 46 | 47 | def __init__(self, width, height): 48 | self._width = width 49 | self._height = height 50 | 51 | def perimeter(self): 52 | return 2 * (self._width + self._height) 53 | 54 | def area(self): 55 | return self._width * self._height 56 | 57 | def __str__(self): 58 | return '我是一个矩形' 59 | 60 | 61 | if __name__ == '__main__': 62 | shapes = [Circle(5), Circle(3.2), Rect(3.2, 6.3)] 63 | for shape in shapes: 64 | print(shape) 65 | print('周长:', shape.perimeter()) 66 | print('面积:', shape.area()) 67 | -------------------------------------------------------------------------------- /Day01-15/Day10/gui1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用tkinter创建GUI 4 | - 顶层窗口 5 | - 控件 6 | - 布局 7 | - 事件回调 8 | 9 | Version: 0.1 10 | Author: 骆昊 11 | Date: 2018-03-14 12 | 13 | """ 14 | 15 | import tkinter 16 | import tkinter.messagebox 17 | 18 | 19 | def main(): 20 | flag = True 21 | 22 | # 修改标签上的文字 23 | def change_label_text(): 24 | nonlocal flag 25 | flag = not flag 26 | color, msg = ('red', 'Hello, world!')\ 27 | if flag else ('blue', 'Goodbye, world!') 28 | label.config(text=msg, fg=color) 29 | 30 | # 确认退出 31 | def confirm_to_quit(): 32 | if tkinter.messagebox.askokcancel('温馨提示', '确定要退出吗?'): 33 | top.quit() 34 | 35 | # 创建顶层窗口 36 | top = tkinter.Tk() 37 | # 设置窗口大小 38 | top.geometry('240x160') 39 | # 设置窗口标题 40 | top.title('小游戏') 41 | # 创建标签对象 42 | label = tkinter.Label(top, text='Hello, world!', font='Arial -32', fg='red') 43 | label.pack(expand=1) 44 | # 创建一个装按钮的容器 45 | panel = tkinter.Frame(top) 46 | # 创建按钮对象 47 | button1 = tkinter.Button(panel, text='修改', command=change_label_text) 48 | button1.pack(side='left') 49 | button2 = tkinter.Button(panel, text='退出', command=confirm_to_quit) 50 | button2.pack(side='right') 51 | panel.pack(side='bottom') 52 | # 开启主事件循环 53 | tkinter.mainloop() 54 | 55 | 56 | if __name__ == '__main__': 57 | main() 58 | -------------------------------------------------------------------------------- /Day01-15/Day09/multi.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 多重继承 4 | - 通过多重继承可以给一个类的对象具备多方面的能力 5 | - 这样在设计类的时候可以避免设计太多层次的复杂的继承关系 6 | 7 | Version: 0.1 8 | Author: 骆昊 9 | Date: 2018-03-12 10 | 11 | """ 12 | 13 | 14 | class Father(object): 15 | 16 | def __init__(self, name): 17 | self._name = name 18 | 19 | def gamble(self): 20 | print('%s在打麻将.' % self._name) 21 | 22 | def eat(self): 23 | print('%s在大吃大喝.' % self._name) 24 | 25 | 26 | class Monk(object): 27 | 28 | def __init__(self, name): 29 | self._name = name 30 | 31 | def eat(self): 32 | print('%s在吃斋.' % self._name) 33 | 34 | def chant(self): 35 | print('%s在念经.' % self._name) 36 | 37 | 38 | class Musician(object): 39 | 40 | def __init__(self, name): 41 | self._name = name 42 | 43 | def eat(self): 44 | print('%s在细嚼慢咽.' % self._name) 45 | 46 | def play_piano(self): 47 | print('%s在弹钢琴.' % self._name) 48 | 49 | 50 | # 试一试下面的代码看看有什么区别 51 | # class Son(Monk, Father, Musician): 52 | # class Son(Musician, Father, Monk): 53 | 54 | 55 | class Son(Father, Monk, Musician): 56 | 57 | def __init__(self, name): 58 | Father.__init__(self, name) 59 | Monk.__init__(self, name) 60 | Musician.__init__(self, name) 61 | 62 | 63 | son = Son('王大锤') 64 | son.gamble() 65 | # 调用继承自Father的eat方法 66 | son.eat() 67 | son.chant() 68 | son.play_piano() 69 | -------------------------------------------------------------------------------- /Day01-15/Day13/test2.py: -------------------------------------------------------------------------------- 1 | import time 2 | from threading import Thread, Lock 3 | 4 | 5 | class Account(object): 6 | 7 | def __init__(self, balance=0): 8 | self._balance = balance 9 | self._lock = Lock() 10 | 11 | @property 12 | def balance(self): 13 | return self._balance 14 | 15 | def deposit(self, money): 16 | # 当多个线程同时访问一个资源的时候 就有可能因为竞争资源导致资源的状态错误 17 | # 被多个线程访问的资源我们通常称之为临界资源 对临界资源的访问需要加上保护 18 | if money > 0: 19 | self._lock.acquire() 20 | try: 21 | new_balance = self._balance + money 22 | time.sleep(0.01) 23 | self._balance = new_balance 24 | finally: 25 | self._lock.release() 26 | 27 | 28 | class AddMoneyThread(Thread): 29 | 30 | def __init__(self, account): 31 | super().__init__() 32 | self._account = account 33 | 34 | def run(self): 35 | self._account.deposit(1) 36 | 37 | 38 | def main(): 39 | account = Account(1000) 40 | tlist = [] 41 | for _ in range(100): 42 | t = AddMoneyThread(account) 43 | tlist.append(t) 44 | t.start() 45 | for t in tlist: 46 | t.join() 47 | print('账户余额: %d元' % account.balance) 48 | 49 | 50 | if __name__ == '__main__': 51 | main() 52 | -------------------------------------------------------------------------------- /Day01-15/Day13/multithread4.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 使用多线程的情况 - 耗时间的任务在独立的线程中执行 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | import time 12 | import tkinter 13 | import tkinter.messagebox 14 | from threading import Thread 15 | 16 | 17 | def main(): 18 | 19 | class DownloadTaskHandler(Thread): 20 | 21 | def run(self): 22 | # 模拟下载任务需要花费10秒钟时间 23 | time.sleep(10) 24 | tkinter.messagebox.showinfo('提示', '下载完成!') 25 | # 启用下载按钮 26 | button1.config(state=tkinter.NORMAL) 27 | 28 | def download(): 29 | # 禁用下载按钮 30 | button1.config(state=tkinter.DISABLED) 31 | # 通过daemon参数将线程设置为守护线程(主程序退出就不再保留执行) 32 | DownloadTaskHandler(daemon=True).start() 33 | 34 | def show_about(): 35 | tkinter.messagebox.showinfo('关于', '作者: 骆昊(v1.0)') 36 | 37 | top = tkinter.Tk() 38 | top.title('单线程') 39 | top.geometry('200x150') 40 | top.wm_attributes('-topmost', 1) 41 | 42 | panel = tkinter.Frame(top) 43 | button1 = tkinter.Button(panel, text='下载', command=download) 44 | button1.pack(side='left') 45 | button2 = tkinter.Button(panel, text='关于', command=show_about) 46 | button2.pack(side='right') 47 | panel.pack(side='bottom') 48 | 49 | tkinter.mainloop() 50 | 51 | 52 | if __name__ == '__main__': 53 | main() 54 | -------------------------------------------------------------------------------- /Day66-75/code/example07.py: -------------------------------------------------------------------------------- 1 | import pymongo 2 | 3 | 4 | # BSON - Binary JSON - dict 5 | def main(): 6 | # client = pymongo.MongoClient('mongodb://120.77.222.217:27017') 7 | client = pymongo.MongoClient(host='120.77.222.217', port=27017) 8 | db = client.zhihu 9 | pages_cache = db.webpages 10 | """ 11 | pages_cache.insert_many([ 12 | {'_id': 1, 'url': 'http://www.baidu.com', 'content': 'shit'}, 13 | {'_id': 2, 'url': 'http://www.qq.com', 'content': 'another shit'}, 14 | {'_id': 3, 'url': 'http://www.qfedu.com', 'content': 'biggest shit'} 15 | ]) 16 | 17 | print(pages_cache.update({'_id': 5}, {'$set': {'content': 'hello, world!'}}, upsert=True)) 18 | # page_id = pages_cache.insert_one({'url': 'http://www.baidu.com', 'content': ''}) 19 | # print(page_id.inserted_id) 20 | # print(pages_cache.remove({'url': 'http://www.baidu.com'})) 21 | print(pages_cache.find().count()) 22 | for doc in pages_cache.find().sort('_id'): 23 | print(doc) 24 | """ 25 | pages_cache.insert_one({ 26 | 'url': 'http://www.baidu.com', 27 | 'content': 'bull shit!', 28 | 'owner': { 29 | 'name': 'Lee Yanhong', 30 | 'age': 50, 31 | 'idcard': '110220196804091203' 32 | } 33 | }) 34 | 35 | 36 | if __name__ == '__main__': 37 | main() 38 | -------------------------------------------------------------------------------- /Day01-15/Day09/car1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 属性的使用 4 | - 访问器/修改器/删除器 5 | - 使用__slots__对属性加以限制 6 | 7 | Version: 0.1 8 | Author: 骆昊 9 | Date: 2018-03-12 10 | 11 | """ 12 | 13 | 14 | class Car(object): 15 | 16 | __slots__ = ('_brand', '_max_speed') 17 | 18 | def __init__(self, brand, max_speed): 19 | self._brand = brand 20 | self._max_speed = max_speed 21 | 22 | @property 23 | def brand(self): 24 | return self._brand 25 | 26 | @brand.setter 27 | def brand(self, brand): 28 | self._brand = brand 29 | 30 | @brand.deleter 31 | def brand(self): 32 | del self._brand 33 | 34 | @property 35 | def max_speed(self): 36 | return self._max_speed 37 | 38 | @max_speed.setter 39 | def max_speed(self, max_speed): 40 | if max_speed < 0: 41 | raise ValueError('Invalid max speed for car') 42 | self._max_speed = max_speed 43 | 44 | def __str__(self): 45 | return 'Car: [品牌=%s, 最高时速=%d]' % (self._brand, self._max_speed) 46 | 47 | 48 | car = Car('QQ', 120) 49 | print(car) 50 | # ValueError 51 | # car.max_speed = -100 52 | car.max_speed = 320 53 | car.brand = "Benz" 54 | # 使用__slots__属性限制后下面的代码将产生异常 55 | # car.current_speed = 80 56 | print(car) 57 | # 如果提供了删除器可以执行下面的代码 58 | # del car.brand 59 | # 属性的实现 60 | print(Car.brand) 61 | print(Car.brand.fget) 62 | print(Car.brand.fset) 63 | print(Car.brand.fdel) 64 | # 通过上面的代码帮助学生理解之前提到的包装器的概念 65 | # Python中有很多类似的语法糖后面还会出现这样的东西 66 | -------------------------------------------------------------------------------- /Day41-55/shop/templates/goods.html: -------------------------------------------------------------------------------- 1 | 2 | {% load staticfiles %} 3 | 4 | 5 | 6 | 16 | 17 | 18 |
19 |

商品列表

20 |
21 |
22 |
23 | 查看购物车 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {% for goods in goods_list %} 33 | 34 | 35 | 36 | 39 | 42 | 43 | {% endfor %} 44 |
商品名称商品价格商品图片操作
{{ goods.name }}¥{{ goods.price }} 37 | {{ goods.name }} 38 | 40 | 加入购物车 41 |
45 | 46 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/templates/goods.html: -------------------------------------------------------------------------------- 1 | 2 | {% load staticfiles %} 3 | 4 | 5 | 6 | 16 | 17 | 18 |
19 |

商品列表

20 |
21 |
22 |
23 | 查看购物车 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | {% for goods in goods_list %} 33 | 34 | 35 | 36 | 39 | 42 | 43 | {% endfor %} 44 |
商品名称商品价格商品图片操作
{{ goods.name }}¥{{ goods.price }} 37 | {{ goods.name }} 38 | 40 | 加入购物车 41 |
45 | 46 | -------------------------------------------------------------------------------- /Day01-15/Day12/str2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 字符串常用操作 - 实现字符串倒转的方法 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-19 8 | 9 | """ 10 | 11 | from io import StringIO 12 | 13 | 14 | def reverse_str1(str): 15 | return str[::-1] 16 | 17 | 18 | def reverse_str2(str): 19 | if len(str) <= 1: 20 | return str 21 | return reverse_str2(str[1:]) + str[0:1] 22 | 23 | 24 | def reverse_str3(str): 25 | # StringIO对象是Python中的可变字符串 26 | # 不应该使用不变字符串做字符串连接操作 因为会产生很多无用字符串对象 27 | rstr = StringIO() 28 | str_len = len(str) 29 | for index in range(str_len - 1, -1, -1): 30 | rstr.write(str[index]) 31 | return rstr.getvalue() 32 | 33 | 34 | def reverse_str4(str): 35 | return ''.join(str[index] for index in range(len(str) - 1, -1, -1)) 36 | 37 | 38 | def reverse_str5(str): 39 | # 将字符串处理成列表 40 | str_list = list(str) 41 | str_len = len(str) 42 | # 使用zip函数将两个序列合并成一个产生元组的迭代器 43 | # 每次正好可以取到一前一后两个下标来实现元素的交换 44 | for i, j in zip(range(str_len // 2), range(str_len - 1, str_len // 2, -1)): 45 | str_list[i], str_list[j] = str_list[j], str_list[i] 46 | # 将列表元素连接成字符串 47 | return ''.join(str_list) 48 | 49 | 50 | if __name__ == '__main__': 51 | str = 'I love Python' 52 | print(reverse_str1(str)) 53 | print(str) 54 | print(reverse_str2(str)) 55 | print(str) 56 | print(reverse_str3(str)) 57 | print(str) 58 | print(reverse_str4(str)) 59 | print(str) 60 | print(reverse_str5(str)) 61 | print(str) 62 | # 提醒学生注意这是一个面试题: 写出你能想到的实现字符串倒转的代码 63 | -------------------------------------------------------------------------------- /Day01-15/Day14/chatserver.py: -------------------------------------------------------------------------------- 1 | from socket import socket 2 | from threading import Thread 3 | 4 | 5 | def main(): 6 | 7 | class ClientHandler(Thread): 8 | 9 | def __init__(self, client): 10 | super().__init__() 11 | self._client = client 12 | 13 | def run(self): 14 | try: 15 | while True: 16 | try: 17 | data = self._client.recv(1024) 18 | if data.decode('utf-8') == 'byebye': 19 | clients.remove(self._client) 20 | self._client.close() 21 | break 22 | else: 23 | for client in clients: 24 | client.send(data) 25 | except Exception as e: 26 | print(e) 27 | clients.remove(self._client) 28 | break 29 | except Exception as e: 30 | print(e) 31 | 32 | server = socket() 33 | server.bind(('10.7.189.118', 12345)) 34 | server.listen(512) 35 | clients = [] 36 | while True: 37 | curr_client, addr = server.accept() 38 | print(addr[0], '连接到服务器.') 39 | clients.append(curr_client) 40 | ClientHandler(curr_client).start() 41 | 42 | 43 | if __name__ == '__main__': 44 | main() 45 | -------------------------------------------------------------------------------- /Day01-15/Day14/fileserver.py: -------------------------------------------------------------------------------- 1 | from socket import socket, SOCK_STREAM, AF_INET 2 | from base64 import b64encode 3 | from json import dumps 4 | from threading import Thread 5 | 6 | 7 | def main(): 8 | 9 | # 自定义线程类 10 | class FileTransferHandler(Thread): 11 | 12 | def __init__(self, cclient): 13 | super().__init__() 14 | self.cclient = cclient 15 | 16 | def run(self): 17 | my_dict = {} 18 | my_dict['filename'] = 'guido.jpg' 19 | # JSON是纯文本不能携带二进制数据 20 | # 所以图片的二进制数据要处理成base64编码 21 | my_dict['filedata'] = data 22 | # 通过dumps函数将字典处理成JSON字符串 23 | json_str = dumps(my_dict) 24 | # 发送JSON字符串 25 | self.cclient.send(json_str.encode('utf-8')) 26 | self.cclient.close() 27 | 28 | # 1.创建套接字对象并指定使用哪种传输服务 29 | server = socket() 30 | # 2.绑定IP地址和端口(区分不同的服务) 31 | server.bind(('192.168.1.2', 5566)) 32 | # 3.开启监听 - 监听客户端连接到服务器 33 | server.listen(512) 34 | print('服务器启动开始监听...') 35 | with open('guido.jpg', 'rb') as f: 36 | # 将二进制数据处理成base64再解码成字符串 37 | data = b64encode(f.read()).decode('utf-8') 38 | while True: 39 | client, addr = server.accept() 40 | # 用一个字典(键值对)来保存要发送的各种数据 41 | # 待会可以将字典处理成JSON格式在网络上传递 42 | FileTransferHandler(client).start() 43 | 44 | 45 | if __name__ == '__main__': 46 | main() 47 | -------------------------------------------------------------------------------- /Day01-15/Day09/association.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 对象之间的关联关系 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-12 8 | 9 | """ 10 | 11 | from math import sqrt 12 | 13 | 14 | class Point(object): 15 | 16 | def __init__(self, x=0, y=0): 17 | self._x = x 18 | self._y = y 19 | 20 | def move_to(self, x, y): 21 | self._x = x 22 | self._y = y 23 | 24 | def move_by(self, dx, dy): 25 | self._x += dx 26 | self._y += dy 27 | 28 | def distance_to(self, other): 29 | dx = self._x - other._x 30 | dy = self._y - other._y 31 | return sqrt(dx ** 2 + dy ** 2) 32 | 33 | def __str__(self): 34 | return '(%s, %s)' % (str(self._x), str(self._y)) 35 | 36 | 37 | class Line(object): 38 | 39 | def __init__(self, start=Point(0, 0), end=Point(0, 0)): 40 | self._start = start 41 | self._end = end 42 | 43 | @property 44 | def start(self): 45 | return self._start 46 | 47 | @start.setter 48 | def start(self, start): 49 | self._start = start 50 | 51 | @property 52 | def end(self): 53 | return self.end 54 | 55 | @end.setter 56 | def end(self, end): 57 | self._end = end 58 | 59 | @property 60 | def length(self): 61 | return self._start.distance_to(self._end) 62 | 63 | 64 | if __name__ == '__main__': 65 | p1 = Point(3, 5) 66 | print(p1) 67 | p2 = Point(-2, -1.5) 68 | print(p2) 69 | line = Line(p1, p2) 70 | print(line.length) 71 | line.start.move_to(2, 1) 72 | line.end = Point(1, 2) 73 | print(line.length) 74 | -------------------------------------------------------------------------------- /Day01-15/Day13/multithread5.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 多个线程共享数据 - 没有锁的情况 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-20 8 | 9 | """ 10 | 11 | from time import sleep 12 | from threading import Thread, Lock 13 | 14 | 15 | class Account(object): 16 | 17 | def __init__(self): 18 | self._balance = 0 19 | self._lock = Lock() 20 | 21 | def deposit(self, money): 22 | # 先获取锁才能执行后续的代码 23 | self._lock.acquire() 24 | try: 25 | new_balance = self._balance + money 26 | sleep(0.01) 27 | self._balance = new_balance 28 | finally: 29 | # 这段代码放在finally中保证释放锁的操作一定要执行 30 | self._lock.release() 31 | 32 | @property 33 | def balance(self): 34 | return self._balance 35 | 36 | 37 | class AddMoneyThread(Thread): 38 | 39 | def __init__(self, account, money): 40 | super().__init__() 41 | self._account = account 42 | self._money = money 43 | 44 | def run(self): 45 | self._account.deposit(self._money) 46 | 47 | 48 | def main(): 49 | account = Account() 50 | threads = [] 51 | # 创建100个存款的线程向同一个账户中存钱 52 | for _ in range(100): 53 | t = AddMoneyThread(account, 1) 54 | threads.append(t) 55 | t.start() 56 | # 等所有存款的线程都执行完毕∫ 57 | for t in threads: 58 | t.join() 59 | print('账户余额为: ¥%d元' % account.balance) 60 | 61 | 62 | if __name__ == '__main__': 63 | main() 64 | -------------------------------------------------------------------------------- /Day66-75/code/image360/image360/spiders/taobao.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from io import StringIO 3 | from urllib.parse import urlencode 4 | import re 5 | 6 | import scrapy 7 | 8 | from image360.items import GoodsItem 9 | 10 | 11 | class TaobaoSpider(scrapy.Spider): 12 | name = 'taobao' 13 | allowed_domains = ['www.taobao.com'] 14 | 15 | def start_requests(self): 16 | base_url = 'https://s.taobao.com/search?' 17 | params = {} 18 | for keyword in ['ipad', 'iphone', '小米手机']: 19 | params['q'] = keyword 20 | for page in range(10): 21 | params['s'] = page * 44 22 | full_url = base_url + urlencode(params) 23 | yield scrapy.Request(url=full_url, callback=self.parse) 24 | 25 | def parse(self, response): 26 | goods_list = response.xpath('//*[@id="mainsrp-itemlist"]/div/div/div[1]') 27 | for goods in goods_list: 28 | item = GoodsItem() 29 | item['price'] = goods.xpath('div[5]/div[2]/div[1]/div[1]/strong/text()').extract_first() 30 | item['deal'] = goods.xpath('div[5]/div[2]/div[1]/div[2]/text()').extract_first() 31 | segments = goods.xpath('div[6]/div[2]/div[2]/a/text()').extract() 32 | title = StringIO() 33 | for segment in segments: 34 | title.write(re.sub('\s', '', segment)) 35 | item['title'] = title.getvalue() 36 | yield item 37 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/migrations/0002_auto_20180523_0923.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-23 01:23 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('hrs', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='dept', 15 | name='excellent', 16 | field=models.BooleanField(default=0, verbose_name='是否优秀'), 17 | ), 18 | migrations.AlterField( 19 | model_name='dept', 20 | name='location', 21 | field=models.CharField(max_length=10, verbose_name='部门所在地'), 22 | ), 23 | migrations.AlterField( 24 | model_name='dept', 25 | name='name', 26 | field=models.CharField(max_length=20, verbose_name='部门名称'), 27 | ), 28 | migrations.AlterField( 29 | model_name='dept', 30 | name='no', 31 | field=models.IntegerField(primary_key=True, serialize=False, verbose_name='部门编号'), 32 | ), 33 | migrations.AlterField( 34 | model_name='emp', 35 | name='comm', 36 | field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True), 37 | ), 38 | migrations.AlterField( 39 | model_name='emp', 40 | name='mgr', 41 | field=models.IntegerField(blank=True, null=True), 42 | ), 43 | ] 44 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.0.5 on 2018-05-22 03:07 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Dept', 17 | fields=[ 18 | ('no', models.IntegerField(primary_key=True, serialize=False)), 19 | ('name', models.CharField(max_length=20)), 20 | ('location', models.CharField(max_length=10)), 21 | ], 22 | options={ 23 | 'db_table': 'tb_dept', 24 | }, 25 | ), 26 | migrations.CreateModel( 27 | name='Emp', 28 | fields=[ 29 | ('no', models.IntegerField(primary_key=True, serialize=False)), 30 | ('name', models.CharField(max_length=20)), 31 | ('job', models.CharField(max_length=10)), 32 | ('mgr', models.IntegerField(null=True)), 33 | ('sal', models.DecimalField(decimal_places=2, max_digits=7)), 34 | ('comm', models.DecimalField(decimal_places=2, max_digits=7, null=True)), 35 | ('dept', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='hrs.Dept')), 36 | ], 37 | options={ 38 | 'db_table': 'tb_emp', 39 | }, 40 | ), 41 | ] 42 | -------------------------------------------------------------------------------- /Day21-30/example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 34 | 35 | 36 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Day66-75/code/douban/douban/spiders/movie.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import scrapy 3 | from scrapy.selector import Selector 4 | from scrapy.linkextractors import LinkExtractor 5 | from scrapy.spiders import CrawlSpider, Rule 6 | 7 | from douban.items import DoubanItem 8 | 9 | 10 | class MovieSpider(CrawlSpider): 11 | name = 'movie' 12 | allowed_domains = ['movie.douban.com'] 13 | start_urls = ['https://movie.douban.com/top250'] 14 | rules = ( 15 | Rule(LinkExtractor(allow=(r'https://movie.douban.com/top250\?start=\d+.*'))), 16 | Rule(LinkExtractor(allow=(r'https://movie.douban.com/subject/\d+')), callback='parse_item'), 17 | ) 18 | 19 | def parse_item(self, response): 20 | sel = Selector(response) 21 | item = DoubanItem() 22 | item['name']=sel.xpath('//*[@id="content"]/h1/span[1]/text()').extract() 23 | item['year']=sel.xpath('//*[@id="content"]/h1/span[2]/text()').re(r'\((\d+)\)') 24 | item['score']=sel.xpath('//*[@id="interest_sectl"]/div/p[1]/strong/text()').extract() 25 | item['director']=sel.xpath('//*[@id="info"]/span[1]/a/text()').extract() 26 | item['classification']= sel.xpath('//span[@property="v:genre"]/text()').extract() 27 | item['actor']= sel.xpath('//*[@id="info"]/span[3]/a[1]/text()').extract() 28 | #i['domain_id'] = response.xpath('//input[@id="sid"]/@value').extract() 29 | #i['name'] = response.xpath('//div[@id="name"]').extract() 30 | #i['description'] = response.xpath('//div[@id="description"]').extract() 31 | return item 32 | 33 | -------------------------------------------------------------------------------- /Day41-55/oa/hrs/views.py: -------------------------------------------------------------------------------- 1 | from django.http import HttpResponse 2 | from django.shortcuts import render, redirect 3 | from django.db.models import ObjectDoesNotExist 4 | 5 | from json import dumps 6 | 7 | from hrs.models import Dept, Emp 8 | 9 | 10 | def index(request): 11 | ctx = { 12 | 'greeting': '你好,世界!' 13 | } 14 | return render(request, 'index.html', context=ctx) 15 | 16 | 17 | def del_dept(request, no='0'): 18 | try: 19 | Dept.objects.get(pk=no).delete() 20 | ctx = {'code': 200} 21 | except (ObjectDoesNotExist, ValueError): 22 | ctx = {'code': 404} 23 | return HttpResponse( 24 | dumps(ctx), content_type='application/json; charset=utf-8') 25 | # 重定向 - 给浏览器一个URL, 让浏览器重新请求指定的页面 26 | # return redirect(reverse('depts')) 27 | # return depts(request) 28 | 29 | 30 | def emps(request, no='0'): 31 | # no = request.GET['no'] 32 | # dept = Dept.objects.get(no=no) 33 | # ForeignKey(Dept, on_delete=models.PROTECT, related_name='emps') 34 | # dept.emps.all() 35 | # emps_list = dept.emp_set.all() 36 | # all() / filter() ==> QuerySet 37 | # QuerySet使用了惰性查询 - 如果不是非得取到数据那么不会发出SQL语句 38 | # 这样做是为了节省服务器内存的开销 - 延迟加载 - 节省空间势必浪费时间 39 | emps_list = list(Emp.objects.filter(dept__no=no).select_related('dept')) 40 | ctx = {'emp_list': emps_list, 'dept_name': emps_list[0].dept.name} \ 41 | if len(emps_list) > 0 else {} 42 | return render(request, 'emp.html', context=ctx) 43 | 44 | 45 | def depts(request): 46 | ctx = {'dept_list': Dept.objects.all()} 47 | return render(request, 'dept.html', context=ctx) 48 | -------------------------------------------------------------------------------- /Day66-75/code/douban/douban/pipelines.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Define your item pipelines here 4 | # 5 | # Don't forget to add your pipeline to the ITEM_PIPELINES setting 6 | # See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html 7 | import pymongo 8 | 9 | from scrapy.exceptions import DropItem 10 | from scrapy.conf import settings 11 | from scrapy import log 12 | 13 | 14 | class DoubanPipeline(object): 15 | 16 | def __init__(self): 17 | connection = pymongo.MongoClient(settings['MONGODB_SERVER'], settings['MONGODB_PORT']) 18 | db = connection[settings['MONGODB_DB']] 19 | self.collection = db[settings['MONGODB_COLLECTION']] 20 | 21 | def process_item(self, item, spider): 22 | #Remove invalid data 23 | valid = True 24 | for data in item: 25 | if not data: 26 | valid = False 27 | raise DropItem("Missing %s of blogpost from %s" %(data, item['url'])) 28 | if valid: 29 | #Insert data into database 30 | new_moive=[{ 31 | "name":item['name'][0], 32 | "year":item['year'][0], 33 | "score":item['score'], 34 | "director":item['director'], 35 | "classification":item['classification'], 36 | "actor":item['actor'] 37 | }] 38 | self.collection.insert(new_moive) 39 | log.msg("Item wrote to MongoDB database %s/%s" % 40 | (settings['MONGODB_DB'], settings['MONGODB_COLLECTION']), 41 | level=log.DEBUG, spider=spider) 42 | return item 43 | 44 | -------------------------------------------------------------------------------- /Day41-55/shop/templates/cart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 17 | 18 | 19 |
20 |

购物车列表

21 |
22 |
23 |
24 | 返回 25 |
26 | {% if cart %} 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | {% for item in cart.cart_items %} 36 | 37 | 38 | 39 | 40 | 41 | 44 | 45 | {% endfor %} 46 | 47 | 48 | 49 |
商品名称商品单价商品数量商品总价操作
{{ item.goods.name }}¥{{ item.goods.price }}{{ item.amount }}¥{{ item.total }} 42 | 删除 43 |
¥{{ cart.total }}元
50 | 清空购物车 51 | {% else %} 52 |

购物车中暂时没有商品!

53 | {% endif %} 54 | 55 | -------------------------------------------------------------------------------- /Day66-75/code/image360/image360/pipelines.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Define your item pipelines here 4 | # 5 | # Don't forget to add your pipeline to the ITEM_PIPELINES setting 6 | # See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html 7 | import logging 8 | 9 | from pymongo import MongoClient 10 | from scrapy import Request 11 | from scrapy.exceptions import DropItem 12 | from scrapy.pipelines.images import ImagesPipeline 13 | 14 | 15 | logger = logging.getLogger('SaveImagePipeline') 16 | 17 | 18 | class SaveImagePipeline(ImagesPipeline): 19 | 20 | def get_media_requests(self, item, info): 21 | yield Request(url=item['url']) 22 | 23 | def item_completed(self, results, item, info): 24 | logger.debug('图片下载完成!') 25 | if not results[0][0]: 26 | raise DropItem('下载失败') 27 | return item 28 | 29 | def file_path(self, request, response=None, info=None): 30 | return request.url.split('/')[-1] 31 | 32 | 33 | class SaveToMongoPipeline(object): 34 | 35 | def __init__(self, mongo_url, db_name): 36 | self.mongo_url = mongo_url 37 | self.db_name = db_name 38 | self.client = None 39 | self.db = None 40 | 41 | def process_item(self, item, spider): 42 | return item 43 | 44 | def open_spider(self, spider): 45 | self.client = MongoClient(self.mongo_url) 46 | self.db = self.client[self.db_name] 47 | 48 | def close_spider(self, spider): 49 | self.client.close() 50 | 51 | @classmethod 52 | def from_crawler(cls, crawler): 53 | return cls(crawler.settings.get('MONGO_URL'), 54 | crawler.settings.get('MONGO_DB')) 55 | 56 | -------------------------------------------------------------------------------- /Day41-55/shop_origin/templates/cart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 17 | 18 | 19 |
20 |

购物车列表

21 |
22 |
23 |
24 | 返回 25 |
26 | {% if cart_items %} 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | {% for item in cart_items %} 36 | 37 | 38 | 39 | 40 | 41 | 44 | 45 | {% endfor %} 46 | 47 | 48 | 49 |
商品名称商品单价商品数量商品总价操作
{{ item.name }}¥{{ item.unit_price }}{{ item.amount }}¥{{ item.total_price }} 42 | 删除 43 |
¥{{ cart.total }}元
50 | 清空购物车 51 | {% else %} 52 |

购物车中暂时没有商品!

53 | {% endif %} 54 | 55 | -------------------------------------------------------------------------------- /Day01-15/Day09/employee.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 抽象类 / 方法重写 / 多态 4 | 实现一个工资结算系统 公司有三种类型的员工 5 | - 部门经理固定月薪12000元/月 6 | - 程序员按本月工作小时数每小时100元 7 | - 销售员1500元/月的底薪加上本月销售额5%的提成 8 | 输入员工的信息 输出每位员工的月薪信息 9 | 10 | Version: 0.1 11 | Author: 骆昊 12 | Date: 2018-03-12 13 | 14 | """ 15 | 16 | from abc import ABCMeta, abstractmethod 17 | 18 | 19 | class Employee(object, metaclass=ABCMeta): 20 | 21 | def __init__(self, name): 22 | self._name = name 23 | 24 | @property 25 | def name(self): 26 | return self._name 27 | 28 | @abstractmethod 29 | def get_salary(self): 30 | pass 31 | 32 | 33 | class Manager(Employee): 34 | 35 | # 想一想: 如果不定义构造方法会怎么样 36 | def __init__(self, name): 37 | # 想一想: 如果不调用父类构造器会怎么样 38 | super().__init__(name) 39 | 40 | def get_salary(self): 41 | return 12000 42 | 43 | 44 | class Programmer(Employee): 45 | 46 | def __init__(self, name): 47 | super().__init__(name) 48 | 49 | def set_working_hour(self, working_hour): 50 | self._working_hour = working_hour 51 | 52 | def get_salary(self): 53 | return 100 * self._working_hour 54 | 55 | 56 | class Salesman(Employee): 57 | 58 | def __init__(self, name): 59 | super().__init__(name) 60 | 61 | def set_sales(self, sales): 62 | self._sales = sales 63 | 64 | def get_salary(self): 65 | return 1500 + self._sales * 0.05 66 | 67 | 68 | if __name__ == '__main__': 69 | emps = [Manager('武则天'), Programmer('狄仁杰'), Salesman('白元芳')] 70 | for emp in emps: 71 | if isinstance(emp, Programmer): 72 | working_hour = int(input('请输入%s本月工作时间: ' % emp.name)) 73 | emp.set_working_hour(working_hour) 74 | elif isinstance(emp, Salesman): 75 | sales = float(input('请输入%s本月销售额: ' % emp.name)) 76 | emp.set_sales(sales) 77 | print('%s本月月薪为: ¥%.2f元' % (emp.name, emp.get_salary())) 78 | -------------------------------------------------------------------------------- /Day66-75/code/example06.py: -------------------------------------------------------------------------------- 1 | 2 | from hashlib import sha1 3 | from urllib.parse import urljoin 4 | 5 | import pickle 6 | import re 7 | import requests 8 | import zlib 9 | 10 | from bs4 import BeautifulSoup 11 | from redis import Redis 12 | 13 | 14 | def main(): 15 | # 指定种子页面 16 | base_url = 'https://www.zhihu.com/' 17 | seed_url = urljoin(base_url, 'explore') 18 | # 创建Redis客户端 19 | client = Redis(host='1.2.3.4', port=6379, password='1qaz2wsx') 20 | # 设置用户代理(否则访问会被拒绝) 21 | headers = {'user-agent': 'Baiduspider'} 22 | # 通过requests模块发送GET请求并指定用户代理 23 | resp = requests.get(seed_url, headers=headers) 24 | # 创建BeautifulSoup对象并指定使用lxml作为解析器 25 | soup = BeautifulSoup(resp.text, 'lxml') 26 | href_regex = re.compile(r'^/question') 27 | # 将URL处理成SHA1摘要(长度固定更简短) 28 | hasher_proto = sha1() 29 | # 查找所有href属性以/question打头的a标签 30 | for a_tag in soup.find_all('a', {'href': href_regex}): 31 | # 获取a标签的href属性值并组装完整的URL 32 | href = a_tag.attrs['href'] 33 | full_url = urljoin(base_url, href) 34 | # 传入URL生成SHA1摘要 35 | hasher = hasher_proto.copy() 36 | hasher.update(full_url.encode('utf-8')) 37 | field_key = hasher.hexdigest() 38 | # 如果Redis的键'zhihu'对应的hash数据类型中没有URL的摘要就访问页面并缓存 39 | if not client.hexists('zhihu', field_key): 40 | html_page = requests.get(full_url, headers=headers).text 41 | # 对页面进行序列化和压缩操作 42 | zipped_page = zlib.compress(pickle.dumps(html_page)) 43 | # 使用hash数据类型保存URL摘要及其对应的页面代码 44 | client.hset('zhihu', field_key, zipped_page) 45 | # 显示总共缓存了多少个页面 46 | print('Total %d question pages found.' % client.hlen('zhihu')) 47 | 48 | 49 | if __name__ == '__main__': 50 | main() 51 | 52 | -------------------------------------------------------------------------------- /Day01-15/Day11/json1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 读取JSON数据 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-13 8 | 9 | """ 10 | 11 | import json 12 | import csv2 13 | 14 | json_str = '{"name": "骆昊", "age": 38, "title": "叫兽"}' 15 | result = json.loads(json_str) 16 | print(result) 17 | print(type(result)) 18 | print(result['name']) 19 | print(result['age']) 20 | 21 | # 把转换得到的字典作为关键字参数传入Teacher的构造器 22 | teacher = csv2.Teacher(**result) 23 | print(teacher) 24 | print(teacher.name) 25 | print(teacher.age) 26 | print(teacher.title) 27 | 28 | # 请思考如何将下面JSON格式的天气数据转换成对象并获取我们需要的信息 29 | # 稍后我们会讲解如何通过网络API获取我们需要的JSON格式的数据 30 | """ 31 | { 32 | "wendu": "29", 33 | "ganmao": "各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。", 34 | "forecast": [ 35 | { 36 | "fengxiang": "南风", 37 | "fengli": "3-4级", 38 | "high": "高温 32℃", 39 | "type": "多云", 40 | "low": "低温 17℃", 41 | "date": "16日星期二" 42 | }, 43 | { 44 | "fengxiang": "南风", 45 | "fengli": "微风级", 46 | "high": "高温 34℃", 47 | "type": "晴", 48 | "low": "低温 19℃", 49 | "date": "17日星期三" 50 | }, 51 | { 52 | "fengxiang": "南风", 53 | "fengli": "微风级", 54 | "high": "高温 35℃", 55 | "type": "晴", 56 | "low": "低温 22℃", 57 | "date": "18日星期四" 58 | }, 59 | { 60 | "fengxiang": "南风", 61 | "fengli": "微风级", 62 | "high": "高温 35℃", 63 | "type": "多云", 64 | "low": "低温 22℃", 65 | "date": "19日星期五" 66 | }, 67 | { 68 | "fengxiang": "南风", 69 | "fengli": "3-4级", 70 | "high": "高温 34℃", 71 | "type": "晴", 72 | "low": "低温 21℃", 73 | "date": "20日星期六" 74 | } 75 | ], 76 | "yesterday": { 77 | "fl": "微风", 78 | "fx": "南风", 79 | "high": "高温 28℃", 80 | "type": "晴", 81 | "low": "低温 15℃", 82 | "date": "15日星期一" 83 | }, 84 | "aqi": "72", 85 | "city": "北京" 86 | } 87 | """ 88 | -------------------------------------------------------------------------------- /Day01-15/Day09/dependency.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | 对象之间的依赖关系和运算符重载 4 | 5 | Version: 0.1 6 | Author: 骆昊 7 | Date: 2018-03-12 8 | 9 | """ 10 | 11 | 12 | class Car(object): 13 | 14 | def __init__(self, brand, max_speed): 15 | self._brand = brand 16 | self._max_speed = max_speed 17 | self._current_speed = 0 18 | 19 | @property 20 | def brand(self): 21 | return self._brand 22 | 23 | def accelerate(self, delta): 24 | self._current_speed += delta 25 | if self._current_speed > self._max_speed: 26 | self._current_speed = self._max_speed 27 | 28 | def brake(self): 29 | self._current_speed = 0 30 | 31 | def __str__(self): 32 | return '%s当前时速%d' % (self._brand, self._current_speed) 33 | 34 | 35 | class Student(object): 36 | 37 | def __init__(self, name, age): 38 | self._name = name 39 | self._age = age 40 | 41 | @property 42 | def name(self): 43 | return self._name 44 | 45 | # 学生和车之间存在依赖关系 - 学生使用了汽车 46 | def drive(self, car): 47 | print('%s驾驶着%s欢快的行驶在去西天的路上' % (self._name, car._brand)) 48 | car.accelerate(30) 49 | print(car) 50 | car.accelerate(50) 51 | print(car) 52 | car.accelerate(50) 53 | print(car) 54 | 55 | def study(self, course_name): 56 | print('%s正在学习%s.' % (self._name, course_name)) 57 | 58 | def watch_av(self): 59 | if self._age < 18: 60 | print('%s只能观看《熊出没》.' % self._name) 61 | else: 62 | print('%s正在观看岛国爱情动作片.' % self._name) 63 | 64 | # 重载大于(>)运算符 65 | def __gt__(self, other): 66 | return self._age > other._age 67 | 68 | # 重载小于(<)运算符 69 | def __lt__(self, other): 70 | return self._age < other._age 71 | 72 | 73 | if __name__ == '__main__': 74 | stu1 = Student('骆昊', 38) 75 | stu1.study('Python程序设计') 76 | stu1.watch_av() 77 | stu2 = Student('王大锤', 15) 78 | stu2.study('思想品德') 79 | stu2.watch_av() 80 | car = Car('QQ', 120) 81 | stu2.drive(car) 82 | print(stu1 > stu2) 83 | print(stu1 < stu2) 84 | -------------------------------------------------------------------------------- /PEP 8风格指南.md: -------------------------------------------------------------------------------- 1 | ## PEP 8风格指南 2 | 3 | PEP是Python Enhancement Proposal的缩写,通常翻译为“Python增强提案”。每个PEP都是一份为Python社区提供的指导Python往更好的方向发展的技术文档,其中的第8号增提案即PEP 8是针对Python语言编订的代码风格指南。尽管我们可以在保证语法没有问题的前提下随意书写Python代码,但是在实际开发中,采用一致的风格书写出可读性强的代码是每个专业的程序员应该做到的事情,也是每个公司的编程规范中会提出的要求,这些在多人协作开发一个项目(团队开发)的时候显得尤为重要。我们可以从Python官方网站的[PEP 8链接](https://www.python.org/dev/peps/pep-0008/)中找到该文档,下面我们对该文档的关键部分做一个简单的总结。 4 | 5 | ### 空格的使用 6 | 7 | 1. **使用空格来表示缩进而不要用制表符(Tab)**。这一点对习惯了其他编程语言的人来说简直觉得不可理喻,因为绝大多数的程序员都会用Tab来表示缩进,但是要知道Python并没有像C/C++或Java那样的用花括号来构造一个代码块的语法,在Python中分支和循环结构都使用缩进来表示哪些代码属于同一个级别,鉴于此Python代码对缩进以及缩进宽度的依赖比其他很多语言都强得多。在不同的编辑器中,Tab的宽度可能是2、4或8个字符,甚至是其他更离谱的值,用Tab来表示缩进对Python代码来说可能是一场灾难。 8 | 2. **和语法相关的每一层缩进都用4个空格来表示。** 9 | 3. **每行的字符数不要超过79个字符,如果表达式因太长而占据了多行,除了首行之外的其余各行都应该在正常的缩进宽度上再加上4个空格。** 10 | 4. **函数和类的定义,代码前后都要用两个空行进行分隔。** 11 | 5. **在同一个类中,各个方法之间应该用一个空行进行分隔。** 12 | 6. **二元运算符的左右两侧应该保留一个空格,而且只要一个空格就好。** 13 | 14 | ### 标识符命名 15 | 16 | PEP 8倡导用不同的命名风格来命名Python中不同的标识符,以便在阅读代码时能够通过标识符的名称来确定该标识符在Python中扮演了怎样的角色(在这一点上,Python自己的内置模块以及某些第三方模块都做得并不是很好)。 17 | 18 | 1. **变量、函数和属性应该使用小写字母来拼写,如果有多个单词就使用下划线进行连接。** 19 | 2. **类中受保护的实例属性,应该以一个下划线开头。** 20 | 3. **类中私有的实例属性,应该以两个下划线开头。** 21 | 4. **类和异常的命名,应该每个单词首字母大写。** 22 | 5. **模块级别的常量,应该采用全大写字母,如果有多个单词就用下划线进行连接。** 23 | 6. **类的实例方法,应该把第一个参数命名为`self`以表示对象自身。** 24 | 7. **类的类方法,应该把第一个参数命名为`cls`以表示该类自身。** 25 | 26 | ### 表达式和语句 27 | 28 | 在Python之禅(可以使用`import this`查看)中有这么一句名言:“There should be one-- and preferably only one --obvious way to do it.”,翻译成中文是“做一件事应该有而且最好只有一种确切的做法”,这句话传达的思想在PEP 8中也是无处不在的。 29 | 30 | 1. **采用内联形式的否定词,而不要把否定词放在整个表达式的前面。**例如`if a is not b`就比`if not a is b`更容易让人理解。 31 | 2. **不要用检查长度的方式来判断字符串、列表等是否为`None`或者没有元素,应该用`if not x`这样的写法来检查它。** 32 | 3. **就算`if`分支、`for`循环、`except`异常捕获等中只有一行代码,也不要将代码和`if`、`for`、`except`等写在一起,分开写才会让代码更清晰。** 33 | 4. **`import`语句总是放在文件开头的地方**。 34 | 5. **引入模块的时候,`from math import sqrt`比`import math`更好。** 35 | 6. **如果有多个`import`语句,应该将其分为三部分,从上到下分别是Python标准模块、第三方模块和自定义模块,每个部分内部应该按照模块名称的字母表顺序来排列。** 36 | 37 | --------------------------------------------------------------------------------