├── web ├── web.md ├── linux.md ├── tornado.md ├── web │ ├── css.md │ ├── html.md │ └── javascript.md ├── flask │ ├── introduction.md │ ├── flaskview.md │ ├── flasktemplates.md │ ├── flaskmodel.md │ ├── flask-restful.md │ └── restful.md ├── django │ ├── djangoadmin.md │ ├── djangocelery.md │ ├── djangomodel.md │ ├── djangoviews.md │ ├── djangotemplates.md │ ├── djangouserpermission.md │ ├── mvc.md │ ├── django-rest-framework.md │ ├── introduction.md │ ├── djangologging.md │ └── djangocache.md ├── flask.md └── django.md ├── spider ├── daandai.md ├── urllib.md ├── request.md ├── selenium.md ├── request │ ├── urllib.md │ └── urllib │ │ ├── lxml.md │ │ └── beautifulsoup.md ├── scrapy.md ├── scrapy │ └── scrapy.md ├── spider.md └── zhua-bao.md ├── welfare ├── README.md └── ke-xue-shang-wang.md ├── daandai ├── da.md ├── da │ ├── numpy.md │ ├── pandas.md │ └── ipython.md └── ai.md ├── basic ├── basic.md └── basic │ └── ban-ben-kong-zhi.md ├── README.md ├── .gitignore └── SUMMARY.md /web/web.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spider/daandai.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spider/urllib.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /welfare/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/linux.md: -------------------------------------------------------------------------------- 1 | # Linux 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/tornado.md: -------------------------------------------------------------------------------- 1 | # Tornado 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/web/css.md: -------------------------------------------------------------------------------- 1 | # CSS 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/web/html.md: -------------------------------------------------------------------------------- 1 | # Html 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /daandai/da.md: -------------------------------------------------------------------------------- 1 | # Data-Analysis 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /daandai/da/numpy.md: -------------------------------------------------------------------------------- 1 | # Numpy 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /daandai/da/pandas.md: -------------------------------------------------------------------------------- 1 | # pandas 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /spider/request.md: -------------------------------------------------------------------------------- 1 | # request 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /spider/selenium.md: -------------------------------------------------------------------------------- 1 | # selenium 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /daandai/da/ipython.md: -------------------------------------------------------------------------------- 1 | # IPython 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /spider/request/urllib.md: -------------------------------------------------------------------------------- 1 | # pickup 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /spider/scrapy.md: -------------------------------------------------------------------------------- 1 | # SpiderFramework 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /spider/scrapy/scrapy.md: -------------------------------------------------------------------------------- 1 | # Scrapy 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /spider/spider.md: -------------------------------------------------------------------------------- 1 | # SpiderBasic 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/flask/introduction.md: -------------------------------------------------------------------------------- 1 | # Flask 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/web/javascript.md: -------------------------------------------------------------------------------- 1 | # JavaScript 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /daandai/ai.md: -------------------------------------------------------------------------------- 1 | # Artificial Intelligence 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /spider/request/urllib/lxml.md: -------------------------------------------------------------------------------- 1 | # lxml 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/django/djangoadmin.md: -------------------------------------------------------------------------------- 1 | # DjangoAdmin 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/flask/flaskview.md: -------------------------------------------------------------------------------- 1 | # FlaskViews 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/django/djangocelery.md: -------------------------------------------------------------------------------- 1 | # DjangoCelery 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/flask/flasktemplates.md: -------------------------------------------------------------------------------- 1 | # FlaskTemplates 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/django/djangomodel.md: -------------------------------------------------------------------------------- 1 | # DjangoModel 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /web/django/djangoviews.md: -------------------------------------------------------------------------------- 1 | # DjangoViews 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /web/flask/flaskmodel.md: -------------------------------------------------------------------------------- 1 | # FlaskModel 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /spider/request/urllib/beautifulsoup.md: -------------------------------------------------------------------------------- 1 | # BeautifulSoup 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /web/django/djangotemplates.md: -------------------------------------------------------------------------------- 1 | # DjangoTemplates 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /web/django/djangouserpermission.md: -------------------------------------------------------------------------------- 1 | # DjangoUserPermission 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /basic/basic.md: -------------------------------------------------------------------------------- 1 | # Python 2 | 3 | 1. [VersionControl](/basic/basic/ban-ben-kong-zhi.md "版本控制") 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /web/django/mvc.md: -------------------------------------------------------------------------------- 1 | # MVC 2 | 3 | 一种软件设计典范,用一种业务逻辑,数据,显示分离的方式组织代码,将业务逻辑聚集到一个部件里面,在改进和个性化定制界面及用户的交互时,不需要重新编写业务逻辑。 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /web/django/django-rest-framework.md: -------------------------------------------------------------------------------- 1 | # Django REST framework 2 | 3 | [http://www.django-rest-framework.org/](http://www.django-rest-framework.org/) 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /spider/zhua-bao.md: -------------------------------------------------------------------------------- 1 | # Packet Capture 2 | 3 | Packet Capture(抓包)就是讲网络传输发送与接收的数据包进行截获,重发,编辑,转存等操作,也用来检查网络安全,抓包也经常来进行数据截取。 4 | 5 | ### 常用抓包工具 6 | 7 | * Fiddler 8 | * Charles 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | ## Course 4 | 课程内容请移步 Python100天 5 | 6 | 7 | ## Welfare 8 | 9 | * [科学上网](welfare/ke-xue-shang-wang.md) 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /web/django/introduction.md: -------------------------------------------------------------------------------- 1 | # Django 2 | 3 | Django是一个基于Python开放源代码的Web应用框架。 4 | 5 | 框架采用了MTV的框架模式,即模型M,模板T和视图V。 6 | 7 | django官方文档[https://www.djangoproject.com/](https://www.djangoproject.com/ "官方网站") 8 | 9 | django中文文档[https://yiyibooks.cn/xx/Django\_1.11.6/index.html](https://yiyibooks.cn/xx/Django_1.11.6/index.html "1.11中文文档") 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /web/flask.md: -------------------------------------------------------------------------------- 1 | # Flask 2 | 3 | * [Flask-Introduction](/web/flask/introduction.md) 4 | 5 | * [FlaskModel](/web/flask/flaskmodel.md) 6 | 7 | * [FlaskTemplates](/web/flask/flasktemplates.md) 8 | 9 | * [FlaskViews](/web/flask/flaskview.md) 10 | 11 | * [RESTful](/web/flask/restful.md) 12 | 13 | * [Flask-RESTful](/web/flask/flask-restful.md "Flask-RESTful") 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node rules: 2 | ## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 3 | .grunt 4 | 5 | ## Dependency directory 6 | ## Commenting this out is preferred by some people, see 7 | ## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git 8 | node_modules 9 | 10 | # Book build output 11 | _book 12 | 13 | # eBook build output 14 | *.epub 15 | *.mobi 16 | *.pdf -------------------------------------------------------------------------------- /web/django/djangologging.md: -------------------------------------------------------------------------------- 1 | # Logging 2 | 3 | [https://docs.djangoproject.com/zh-hans/2.0/topics/logging/](https://docs.djangoproject.com/zh-hans/2.0/topics/logging/) 4 | 5 | Django使用了Python中内建的logging模型实现了Django系统的日志系统。 6 | 7 | 8 | 9 | ### 核心成员 10 | 11 | * Loggers 12 | * 日志系统的入口 13 | * 日志有级别,级别标识日志信息将被怎么处理 14 | * DEBUG 15 | * INFO 16 | * WARNING 17 | * ERROR 18 | * CRITICAL 19 | * Handlers 20 | * logger消息的处理者 21 | * 决定每条消息如何处理 22 | * Filters 23 | * 对于从logger传递handler的日志记录进行额外的过滤控制 24 | * Formatters 25 | * 对日志的格式进行格式化 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /web/django.md: -------------------------------------------------------------------------------- 1 | # Django 2 | 3 | * [Django-Introduction](/web/django/introduction.md) 4 | * [MVC](/web/django/mvc.md) 5 | * [DjangoModel](/web/django/djangomodel.md) 6 | * [DjangoTemplates](/web/django/djangotemplates.md) 7 | * [DjangoViews](/web/django/djangoviews.md) 8 | * [DjangoAdmin](/web/django/djangoadmin.md) 9 | * [DjangoUserPermission](/web/django/djangouserpermission.md) 10 | * [DjangoLogging](/web/django/djangologging.md) 11 | * [DjangoCache](/web/django/djangocache.md) 12 | * [DjangoCelery](/web/django/djangocelery.md) 13 | * [RESTful](/web/flask/restful.md) 14 | * [Django REST framework](/web/django/django-rest-framework.md) 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /web/flask/flask-restful.md: -------------------------------------------------------------------------------- 1 | # Flask-RESTful 2 | 3 | [https://flask-restful.readthedocs.io/en/latest/](https://flask-restful.readthedocs.io/en/latest/ "官网地址") 4 | 5 | #### 基本使用 6 | 7 | * 安装 8 | 9 | ``` 10 | # pip 安装 11 | pip install flask-restful 12 | 13 | # 源码安装 14 | git clone https://github.com/flask-restful/flask-restful.git 15 | python setup.py develop 16 | ``` 17 | 18 | * 创建Resource实现类 19 | 20 | ``` 21 | class HelloRESTful(Resource): 22 | def get(self): 23 | return {"data":"HelloREST"} 24 | ``` 25 | 26 | * 创建API对象,并注册路由 27 | 28 | ``` 29 | # ① 创建并初始化 30 | api = API(app) 31 | # ② 创建,之后初始化 32 | api = API() 33 | api.init_app(app) 34 | 35 | # 注册路由 36 | api.add_resource(HelloRESTFul,"/") 37 | ``` 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | ## Course 4 | 5 | * [Introduction](README.md) 6 | 7 | ## Basic 8 | 9 | * [Basic](basic/basic.md) 10 | * [VersionControl](basic/basic/ban-ben-kong-zhi.md) 11 | 12 | ## Web 13 | 14 | * [Web](web/web.md) 15 | * [HTML](web/web/html.md) 16 | * [CSS](web/web/css.md) 17 | * [JavaScript](web/web/javascript.md) 18 | * [Linux](web/linux.md) 19 | * [Django](web/django.md) 20 | * [Django-Introduction](web/django/introduction.md) 21 | * [RESTful](web/flask/restful.md) 22 | * [Django REST framework](web/django/django-rest-framework.md) 23 | * [MVC](web/django/mvc.md) 24 | * [DjangoModel](web/django/djangomodel.md) 25 | * [DjangoViews](web/django/djangoviews.md) 26 | * [DjangoTemplates](web/django/djangotemplates.md) 27 | * [DjangoAdmin](web/django/djangoadmin.md) 28 | * [DjangoUserPermission](web/django/djangouserpermission.md) 29 | * [DjangoLogging](web/django/djangologging.md) 30 | * [DjangoCache](web/django/djangocache.md) 31 | * [DjangoCelery](web/django/djangocelery.md) 32 | * [Flask](web/flask.md) 33 | * [Flask-Introduction](web/flask/introduction.md) 34 | * [Flask-RESTful](web/flask/flask-restful.md) 35 | * [FlaskModel](web/flask/flaskmodel.md) 36 | * [FlaskTemplates](web/flask/flasktemplates.md) 37 | * [FlaskViews](web/flask/flaskview.md) 38 | * [Tornado](web/tornado.md) 39 | 40 | ## Spider 41 | 42 | * [SpiderBasic](spider/spider.md) 43 | * [packet capture](spider/zhua-bao.md) 44 | * [urllib](spider/urllib.md) 45 | * [request](spider/request.md) 46 | * [selenium](spider/selenium.md) 47 | * [pickup](spider/request/urllib.md) 48 | * [lxml](spider/request/urllib/lxml.md) 49 | * [BeautifulSoup](spider/request/urllib/beautifulsoup.md) 50 | * [SpiderFramework](spider/scrapy.md) 51 | * [Scrapy](spider/scrapy/scrapy.md) 52 | 53 | ## DA&AI 54 | 55 | * [DA](daandai/da.md) 56 | * [IPython](daandai/da/ipython.md) 57 | * [Numpy](daandai/da/numpy.md) 58 | * [pandas](daandai/da/pandas.md) 59 | * [AI](daandai/ai.md) 60 | 61 | ## Welfare 62 | 63 | * [科学上网](welfare/ke-xue-shang-wang.md) 64 | 65 | -------------------------------------------------------------------------------- /basic/basic/ban-ben-kong-zhi.md: -------------------------------------------------------------------------------- 1 | # 版本控制 2 | 3 | 版本控制是一种软体工程技巧,藉以在开发的过程中,确保由不同人所编辑的统一档案都得到更新。 4 | 5 | 目前用到的最广泛的控制器就是SVN和Git。 6 | 7 | SVN(Subversion)是集中式管理的版本控制器,Git是分布式管理控制器,这是两者最本质的区别。 8 | 9 | 集中式: 10 | 11 | 分布式: 12 | 13 | #### svn 14 | 15 | 集中式管理的代表,版本库存放在中央服务器。 16 | 17 | [https://tortoisesvn.net/](https://tortoisesvn.net/ "TortoiseSVN") 18 | 19 | ###### 20 | 21 | #### git 22 | 23 | 分布式管理的代表,每个人都是一个版本库,通常我们会也有选择一个“中心仓库”。 24 | 25 | [https://git-scm.com/](https://git-scm.com/ "Git") 26 | 27 | ###### 常见托管平台 28 | 29 | * [http://code.taobao.org/](http://code.taobao.org/) 30 | * [https://www.oschina.net/](https://www.oschina.net/) 31 | 32 | ### Git基本使用 33 | 34 | 这里我们就根据开发需求,以操作为准去学习。 35 | 36 | * 软件安装 37 | 38 | ```bash 39 | add-apt-repository ppa:git-core/ppa 40 | apt update 41 | apt install git 42 | ``` 43 | 44 | * 注册github并激活 45 | 46 | [https://github.com/](https://github.com/) 47 | 48 | * 创建一个项目 49 | * 命令初体验,下载项目 50 | 51 | ``` 52 | git clone URL 53 | ``` 54 | 55 | * 配置用户信息 56 | 57 | ``` 58 | git config --global user.name "Rock" 59 | git config --global user.email "rockrong1204@aliyun.com" 60 | ``` 61 | 62 | * 用PyCharm打开项目并配置Git信息,Git忽略 63 | 64 | * 图形化更新代码 65 | 66 | * 图形化提交代码 67 | 68 | #### 重要概念 69 | 70 | * 工作区 71 | * 暂存区 72 | * 本地仓库 73 | * 远程仓库 74 | * 分支 75 | 76 | #### Git指令 77 | 78 | * git init 79 | * git status 80 | * git add 81 | * git commit 82 | * git commit -m "Message" 83 | * git log 84 | * git diff 85 | * git reset 86 | * git reset --hard version\_code 87 | * git rm 88 | * git rm -f FileName 89 | * git mv 90 | * git branch 91 | * git branch BranchName 92 | * git branch -d BranchName 93 | * git checkout 94 | * git checkout BranchName 95 | * git checkout -b BranchName 96 | * git checkout FileName 97 | * git merge 98 | * git tag 99 | * git tag "TAG\_name" 100 | * * git tag -a "TAG\_name" version\_code 101 | * git tag -d TAG\_name 102 | * git show 103 | * git show TagName 104 | * git stash 105 | * git stash drop 106 | * git stash pop 107 | * git stash apply 108 | * git remote 109 | * git rebase 110 | * git rebase BranchName 111 | * git rebase --continue 112 | * git rebase --abort 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /web/django/djangocache.md: -------------------------------------------------------------------------------- 1 | # Cache 2 | 3 | [https://docs.djangoproject.com/zh-hans/2.0/topics/cache/](https://docs.djangoproject.com/zh-hans/2.0/topics/cache/) 4 | 5 | 6 | 7 | ### 缓存框架的核心目标 8 | 9 | * 较少的代码 10 | * 缓存应该尽可能快 11 | * 因此围绕缓存后端的所有框架代码应该保持在绝对最小值,特别是对于获取操作 12 | * 一致性 13 | * 缓存API应该是提供跨越不同缓存后端的一致接口 14 | * 可扩展性 15 | * 基于开发人员的需求,缓存API应该可以在应用程序级别扩展 16 | 17 | 18 | 19 | ### 缓存 20 | 21 | * django内置了缓存框架,并提供了几种常用的缓存 22 | * 基于Memcached缓存 23 | * 使用数据库进行缓存 24 | * 使用文件系统进行缓存 25 | * 使用本地内存进行缓存 26 | * 提供缓存扩展接口 27 | 28 | 29 | 30 | #### 缓存配置 31 | 32 | 1. 创建缓存表 33 | ```py 34 | python manage.py createcachetable [table_name] 35 | ``` 36 | 2. 缓存配置 37 | ```py 38 | CACHES = { 39 | 'default': { 40 | 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 41 | 'LOCATION': 'my_cache_table', 42 | 'TIMEOUT': '60', 43 | 'OPTIONS': { 44 | 'MAX_ENTRIES': '300', 45 | }, 46 | 'KEY_PREFIX': 'rock', 47 | 'VERSION': '1', 48 | } 49 | } 50 | ``` 51 | 52 | 53 | 54 | #### 缓存使用 55 | 56 | * 在视图中使用(使用最多的场景) 57 | * @cache\_page\(\) 58 | * time 秒 60\*5 缓存五分钟 59 | * cache 缓存配置, 默认default, 60 | * key\_prefix 前置字符串 61 | 62 | 63 | 64 | #### 缓存底层 65 | 66 | * 获取cache 67 | * ```py 68 | from django.core.cache import caches 69 | cache = caches['cache_name'] 70 | ``` 71 | * 获取cache 72 | 73 | * ```py 74 | from django.core.cache import cache 75 | ``` 76 | 77 | * 缓存操作 78 | 79 | * cache.set 80 | 81 | * key 82 | 83 | * value 84 | 85 | * timeout 86 | 87 | * get 88 | 89 | * add 90 | 91 | * get\__or \_set_ 92 | 93 | * get\_many 94 | 95 | * set\_many 96 | 97 | * delete 98 | 99 | * delete\_many 100 | 101 | * clear 102 | 103 | * incr 增加 104 | 105 | * incr\(key, value\) key对应的值上添加 value 106 | 107 | * decr 减少 108 | 109 | * decr\(key, value\) key对应的值上减少value 110 | 111 | * 如果value不写,默认变更为1 112 | 113 | 114 | 115 | ### 使用Redis做缓存 116 | 117 | * 常见的有两个实现 118 | * django-redis 119 | * [http://django-redis-chs.readthedocs.io/zh\_CN/latest/\#django](http://django-redis-chs.readthedocs.io/zh_CN/latest/#django) 120 | * django-redis-cache 121 | * ·[https://pypi.python.org/pypi/django-redis-cache/](https://pypi.python.org/pypi/django-redis-cache/) 122 | * 配置和内置的缓存配置基本一致 123 | * ```py 124 | CACHES = { 125 | "default": { 126 | "BACKEND": "django_redis.cache.RedisCache", 127 | "LOCATION": "redis://127.0.0.1:6379/1", 128 | "OPTIONS": { 129 | "CLIENT_CLASS": "django_redis.client.DefaultClient", 130 | } 131 | } 132 | } 133 | ``` 134 | * 用法和内置缓存使用一样 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /welfare/ke-xue-shang-wang.md: -------------------------------------------------------------------------------- 1 | # 科学上网 2 | 3 | 一直有一个亚马逊的羊毛,不知道大家撸没撸过,没撸过就来看看吧,可以免费科学上网一年。 4 | 5 | 使用的是shadowsocket实现 6 | 7 | #### 第一步,注册 8 | 9 | 1. 撸亚马逊的羊毛,首先当然是注册亚马逊账号了,搜索AWS(Amazon Web Services),进入网址 [https://amazonaws-china.com/cn/free/](https://amazonaws-china.com/cn/free/) 10 | 2. 注册亚马逊账号,填写个人信息,需绑定一张信用卡 11 | 3. 免费云服务也是有限制的,每月750小时(24\*31😆),每月100w次请求... 12 | 4. 接下来会有一个验证码,会打电话过来,输入屏幕上的四个数字,之后输入 \* ,就可以成功激活了 13 | 14 | #### 第二步,创建实例 15 | 16 | 1. 登录aws主页,点击右上角我的账户 17 | 2. 右上角用户名边上有一个地区选择,根据自己的需求选择一个位置创建主机,如果只是上网用,建议东京 18 | 3. 点击启动实例,选择一个Linux系统,推荐使用Ubuntu Server 16.04 LTS\(HVM\),记得选择的时候选带有符合条件的免费套餐 19 | 4. 之后点击启动,会让你创建密钥,输入一个名字,之后下载存储秘钥 20 | 5. 启动实例,就可以再你的服务器中看到了,服务器名,dns,ip等,记录下来ip 21 | 22 | #### 第三步,连接实例 23 | 24 | 1. 点击启动实例后面的连接,里面会有多种连接方式,推荐大家使用ssh连接 25 | 2. 使用ssh连接需要使用先前生成的秘钥 26 | 3. 窗口出现ubuntu@x-x-x表示成功 27 | 28 | #### 第四步,安装软件 29 | 30 | 1. 提升权限,安装软件 31 | 2. sudo -s,进入root用户 32 | 3. apt update,更新软件源 33 | 4. apt install python-pip,安装python包管理工具 34 | 5. pip install shadowsocks,安装科学上网软件 35 | 6. 安装锐速(锐速不支持Openvz!)TCP加速(可选) 36 | - `` wget -N --no-check-certificate https://github.com/91yun/serverspeeder/raw/master/serverspeeder.sh && bash serverspeeder.sh`` 37 | 38 | #### 第五步,配置软件 39 | 40 | 1. 编写一个配置文件,在/etc/shadowsocks.json中编写配置(如果没有就创建) 41 | 42 | 2. ``` 43 | 单用户配置: 44 | { 45 | "server":"0.0.0.0", 46 | "server_port":"9229", 47 | "local_address":"127.0.0.1", 48 | "local_port":"1080", 49 | "password":"自己的密码", 50 | "timeout":500, 51 | "method":"aes-256-cfb", 52 | "fast_open":false 53 | } 54 | 55 | 多用户配置: 56 | { 57 | "server":"0.0.0.0", 58 | "server_port":"9229", 59 | "local_address":"127.0.0.1", 60 | "local_port":"1080", 61 | "port_password":{ 62 | "9229":"密码", 63 | "9230":"密码", 64 | "9231":"密码" 65 | } 66 | "timeout":500, 67 | "method":"aes-256-cfb", 68 | "fast_open":false 69 | } 70 | ``` 71 | 72 | 1. 建议其实单个用户的配置足够,一个账户也可以多个设备登录 73 | 74 | #### 第六步,启动服务器 75 | 76 | 1. 在终端中启动服务器ssserver -c /etc/shadowsocks.json -d start 77 | 2. 加入开机自启,编辑/etc/rc.local ,将启动指令粘贴到此 78 | 3. 去服务器配置中打开端口,到自己的实例上,到最右边找到安全组,进入安全组设置,点击左下角的入站,编辑,点击添加规则,在端口范围里填上我们设置的端口,来源下拉框中选择任何位置。 79 | 80 | #### 第七步,连接使用 81 | 82 | 1. 在Android手机上可以使用影梭进行连接 83 | 2. 在mac,linux,windows上可以使用shadowsocks客户端,都是开源的 84 | 85 | 3. windows版本[https://github.com/shadowsocks/shadowsocks-windows](https://github.com/shadowsocks/shadowsocks-windows) 86 | 87 | 4. linux,mac版本[https://github.com/shadowsocks/shadowsocks-qt5](https://github.com/shadowsocks/shadowsocks-qt5) 88 | 5. android版本[https://github.com/shadowsocks/shadowsocks-android](https://github.com/shadowsocks/shadowsocks-android) 89 | 90 | 91 | 92 | #### 你可能需要: 93 | * 如果你不知道你的机子到底是不是Openvz,请食用[《教程:一键检测VPS是Openvz还是KVM还是Xen》](http://www.91yun.org/archives/836) 94 | * 如果你的内核不对,是Centos的话请食用[《教程:CentOS更换内核,提供锐速可用的内核下载》](http://www.91yun.org/archives/795)。debian和ubuntu我不熟,暂时还没一键包,请自行百度google。。 95 | -------------------------------------------------------------------------------- /web/flask/restful.md: -------------------------------------------------------------------------------- 1 | # RESTful API 2 | 3 | --- 4 | 5 | ### 什么是REST 6 | 7 | 一种软件架构风格、设计风格、而不是标准,只是提供了一组设计原则和约束条件。它主要用户客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存机制等。 8 | 9 | REST全程是Representational State Transfer,表征性状态转移。首次在2000年Roy Thomas Fielding的博士论文中出现,Fielding是一个非常重要的人,他是HTTP协议(1.0版和1.1版)的主要设计者,Apache服务器软件的作者之一,Apache基金会的第一任主席。所以,他的这篇论文一经发表,就引起了广泛的关注。 10 | 11 | 论文: 12 | 13 | 本文研究计算机科学两大前沿----软件和网络----的交叉点。长期以来,软件研究主要关注软件设计的分类、设计方法的演化,很少客观地评估不同的设计选择对系统行为的影响。而相反地,网络研究主要关注系统之间通信行为的细节、如何改进特定通信机制的表现,常常忽视了一个事实,那就是改变应用程序的互动风格比改变互动协议,对整体表现有更大的影响。**我这篇文章的写作目的,就是想在符合架构原理的前提下,理解和评估以网络为基础的应用软件的架构设计,得到一个功能强、性能好、适宜通信的架构。** 14 | 15 | \(This dissertation explores a junction on the frontiers of two research disciplines in computer science: software and networking. Software research has long been concerned with the categorization of software designs and the development of design methodologies, but has rarely been able to objectively evaluate the impact of various design choices on system behavior. Networking research, in contrast, is focused on the details of generic communication behavior between systems and improving the performance of particular communication techniques, often ignoring the fact that changing the interaction style of an application can have more impact on performance than the communication protocols used for that interaction. My work is motivated by the desire to understand and evaluate the architectural design of network-based application software through principled use of architectural constraints, thereby obtaining the functional, performance, and social properties desired of an architecture. \) 16 | 17 | ### REST爆发 18 | 19 | 其实在REST架构推出的十几年间,它并没有一路高歌的发展,真正的大范围推广是在2013年之后,伴随着移动端的飞速发展,越来越多人的开始意识到,网站即软件,而且是一种新型的软件。 20 | 21 | 这种"互联网软件采用"客户端/服务器"模式,也就是我们常说的C/S模式,这一切建立在分布式体系上,通过互联网通信,具有高延时,高并发等特点。 22 | 23 | 网站开发,完全采用软件开发开发的模式。但传统上,软件和网络是两个不同的领域,很少有交集,软件开发主要针对单机环境,网络则主要研究系统之间的通信。我们需要考虑的是如何开发在互联网环境中使用软件。 24 | 25 | 26 | 27 | ### 理解RESTful 28 | 29 | 要理解RESTful架构,最好的就是去理解它的单词 Representational State Transfer 到底是什么意思,它的每一个词到底要表达什么。 30 | 31 | REST的释义,"表现层状态转化",其实这省略了主语。“表现层”其实指的是“资源\(Resource\)”的“表现层”。 32 | 33 | ##### 资源(Resource) 34 | 35 | 所谓“资源”,就是网络上的一个实体,或者说是网络上的一个具体信息。它可以是一段文本,一张图片,一首歌曲,一种服务,总之就是一个具体的实例。你可以使用一个URI(统一资源定位符)指向它,每种资源对应一个特定的URI。要获取这个资源,访问它的URI就可以了,因此URI就成了每一个资源的地址或独一无二的识别符。所谓“上网”就是与互联网上一系列的“资源”互动,调用它们的URI。 36 | 37 | ##### 表现层(Representation) 38 | 39 | “资源”是一种信息实体,它可以有多种外在表现形式。我们把“资源”具体呈现出来的形式,叫做它的”表现层“(Representation)。 40 | 41 | URI只代表资源的实体,不代表它的形式。严格地说,有些网站最后的”.html“后缀名是不必要的,因为这个后缀表示格式,属于”表现层“范畴,而URI应该只代表”资源“的位置。它的具体表现形式,应该在HTTP请求头的信息中使用Accept和Content-Type字段指定。 42 | 43 | ##### 状态转换(State Transfer) 44 | 45 | 访问一个网站,就代表客户端和服务端的一个互动过程。在这个过程中,势必涉及到数据和状态的变化。 46 | 47 | 互联网通信协议HTTP协议,是一个无状态协议。这意味着,所有的状态都保存在服务端。因此,如果客户端想要操作服务器,就必须通过某种手段,让服务器端发生”状态转换(State Transfer)“。而这种转换是建立在表现层之上的,所以就是”表现层状态转化“。 48 | 49 | 客户端用到的手段,只能是HTTP协议。具体来说,就是HTTP协议中,四个表示操作方式的动词:GET,POST,PUT,DELETE。它们分别对应四种基本操作:GET用来获取资源,POST用来新建资源(也可用于更新资源),PUT用来更新资源,DELETE用来删除资源 50 | 51 | 52 | 53 | #### 到底什么是RESTful架构 54 | 55 | 1. 每一个URI代表一种资源 56 | 2. 客户端和服务器之间,传递这种资源的某种表现层 57 | 3. 客户端通过四个HTTP动词,对服务端资源进行操作,实现”表现层状态转换“ 58 | 59 | 60 | 61 | ## RESTful API设计 62 | 63 | ###### 协议 64 | 65 | API与用户的通信协议,通常使用HTTP\(S\)协议。 66 | 67 | ###### 域名 68 | 69 | 应该尽量将API部署在专用域名之下。 70 | 71 | ``` 72 | http://api.rock.com 73 | ``` 74 | 75 | 如果确定API很简单,不会有大规模扩充,可以考虑放在主域名之下。 76 | 77 | ``` 78 | http://www.rock.com/api/ 79 | ``` 80 | 81 | ###### 版本 82 | 83 | 应该将API的版本号放入URL。 84 | 85 | ``` 86 | http://api.rock.com/v1/ 87 | ``` 88 | 89 | 也有做法是将版本号放在HTTP的头信息中,但不如放在URL中方便和直观。GITHUB是这么搞的。 90 | 91 | ###### 路径(Endpoint) 92 | 93 | 路径又称”终点“(endpoint),表示API的具体网址。 94 | 95 | 在RESTful架构中,每个网址代表一种资源(Resource),所以网址中不能有动词,只能有名词,而且所用的名词往往与数据库的表格名对应。一般来说,数据库中的表都是同种记录的”集合“(collection),所以API中的名词也应该使用复数。 96 | 97 | ###### HTTP动词 98 | 99 | 对于资源的具体操作类型,由HTTP动词表示。 100 | 101 | HTTP常用动词 102 | 103 | * GET(SELECT):从服务器取出资源 104 | * POST(CREATE or UPDATE):在服务器创建资源或更新资源 105 | * PUT(UPDATE):在服务器更新资源(客户端提供改变后的完整资源) 106 | * PATCH(UPDATE):在服务器更新资源(客户端提供改变的属性) 107 | * DELETE(DELETE):从服务器删除资源 108 | * HEAD:获取资源的元数据 109 | * OPTIONS:获取信息,关于资源的哪些属性是客户端可以改变的、 110 | 111 | 示例 112 | 113 | * GET /students:获取所有学生 114 | * POST /students:新建学生 115 | * GET /students/id:获取某一个学生 116 | * PUT /students/id :更新某个学生的信息(需要提供学生的全部信息) 117 | * PATCH /students/id:更新某个学生的信息(需要提供学生变更部分信息) 118 | * DELETE /students/id:删除某个学生 119 | 120 | ###### 过滤信息(Filtering) 121 | 122 | 如果记录数量过多,服务器不可能将它们返回给用户。API应该提供参数,过滤返回结果。 123 | 124 | * ?limit=10 125 | * ?offset=10 126 | * ?page=2&per\_page=20 127 | * ?sortby=name&order=desc 128 | * ?student\_id=id 129 | 130 | 参数的设计允许存在冗余,即允许API路径和URL参数偶尔有重复,比如 GET /students/id 和 ?student\_id=id 131 | 132 | ###### 状态码 133 | 134 | 服务器向用户返回的状态码和提示信息,常见的有以下一些地方 135 | 136 | * 200 OK - \[GET\]:服务器成功返回用户请求的数据 137 | * 201 CREATED -\[POST/PUT/PATCH\]:用户新建或修改数据成功 138 | * 202 Accepted - \[\*\] :表示一个请求已经进入后台排队(异步任务) 139 | * 204 NO CONTENT - \[DELETE\]:表示数据删除成功 140 | * 400 INVALID REQUEST - \[POST/PUT/PATCH\]:用户发出的请求有错误 141 | * 401 Unauthorized - \[\*\] :表示用户没有权限(令牌,用户名,密码错误) 142 | * 403 Forbidden - \[\*\]:表示用户得到授权,但是访问是被禁止的 143 | * 404 NOT FOUND - \[\*\]:用户发出的请求针对的是不存在的记录 144 | * 406 Not Acceptable - \[\*\]:用户请求格式不可得 145 | * 410 Gone - \[GET\] :用户请求的资源被永久移除,且不会再得到的 146 | * 422 Unprocesable entity -\[POST/PUT/PATCH\]:当创建一个对象时,发生一个验证错误 147 | * 500 INTERNAL SERVER EROR - \[\*\] :服务器内部发生错误 148 | 149 | ###### 错误处理 150 | 151 | 如果状态码是4xx,就应该向用户返回出错信息。一般来说,返回的信息中将error做为键名 152 | 153 | ###### 返回结果 154 | 155 | 针对不同操作,服务器想用户返回的结果应该符合以下规范 156 | 157 | * GET /collection:返回资源对象的列表(数组,集合) 158 | * GET /collection/id:返回单个资源对象 159 | * POST /collection:返回新生成的资源对象 160 | * PUT /collection/id:返回完整的资源对象 161 | * PATCH /collection/id:返回完整的资源对象 162 | * DELETE /collection/id:返回一个空文档 163 | 164 | ###### 使用链接关联资源 165 | 166 | RESTful API最好做到Hypermedia,即返回结果中提供链接,连向其他API方法,使得用户不查文档,也知道下一步应该做什么。 167 | 168 | ``` 169 | { 170 | "link": { 171 | "rel": "collection https://www.rock.com/zoostudents", 172 | "href": "https://api.rock.com/students", 173 | "title": "List of students", 174 | "type": "application/vnd.yourformat+json" 175 | } 176 | } 177 | ``` 178 | 179 | * rel:表示这个API与当前网址的关系 180 | * href:表示API的路径 181 | * title:表示API的标题 182 | * type:表示返回的类型 183 | 184 | ###### 其它 185 | 186 | * 服务器返回的数据格式,应该尽量使用JSON 187 | * API的身份认证应该使用OAuth2.0框架 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | --------------------------------------------------------------------------------