├── PythonDemo
├── wordcloud
│ ├── examples
│ │ ├── README.txt
│ │ ├── alice.png
│ │ ├── parrot.png
│ │ ├── a_new_hope.png
│ │ ├── alice_color.png
│ │ ├── alice_mask.png
│ │ ├── alice_colored.png
│ │ ├── constitution.png
│ │ ├── colored_by_group.png
│ │ ├── a_new_hope_bigrams.png
│ │ ├── stormtrooper_mask.png
│ │ ├── fonts
│ │ │ └── Symbola
│ │ │ │ ├── Symbola.pdf
│ │ │ │ ├── Symbola.ttf
│ │ │ │ └── README.md
│ │ ├── simple.py
│ │ ├── masked.py
│ │ ├── frequency.py
│ │ ├── colored.py
│ │ ├── a_new_hope.py
│ │ ├── emoji.py
│ │ ├── happy-emoji.txt
│ │ ├── colored_by_group.py
│ │ ├── alice_license.txt
│ │ └── constitution.txt
│ ├── simple.py
│ └── constitution.txt
├── readme.txt
├── weixin
│ ├── wxpy.pkl
│ ├── itchat.pkl
│ ├── signatures.jpg
│ ├── alice_color.png
│ ├── weixinchatRobotSingle.py
│ ├── weixinchatRobotGroup.py
│ ├── weixinlocation.py
│ ├── signatures.txt
│ ├── weixinItchatSexAs.py
│ ├── weixinQianming.py
│ └── weixin.py
├── PIL
│ ├── alice_color.png
│ ├── result
│ │ ├── python1.png
│ │ ├── python2.png
│ │ ├── python3.png
│ │ ├── python4.png
│ │ ├── python5.png
│ │ ├── python6.png
│ │ ├── python7.png
│ │ ├── python8.png
│ │ └── python9.png
│ ├── demo1加载图像.py
│ └── cutImage.py
├── .spyproject
│ ├── codestyle.ini
│ ├── encoding.ini
│ ├── vcs.ini
│ └── workspace.ini
├── saveToExcel
│ ├── xwltDemo2.py
│ └── xlwtDemo.py
├── test2.py
├── numpy
│ ├── broadcast.py
│ ├── arraysort.py
│ ├── arrayunique.py
│ ├── numpy简单介绍
│ ├── arrayboolean.py
│ ├── creatArray.py
│ ├── arraymethod2.py
│ └── arraymethod.py
├── Matplotlib
│ ├── demo.py
│ ├── demo11.py
│ ├── demo1.py
│ ├── demo13.py
│ ├── demo14.py
│ ├── demo8.py
│ ├── demo18.py
│ ├── demo16.py
│ ├── demo2.py
│ ├── demo10.py
│ ├── demo3.py
│ ├── demo12.py
│ ├── demo19.py
│ ├── demo5.py
│ ├── demo15.py
│ ├── demo7.py
│ ├── demo9.py
│ ├── demo17.py
│ ├── demo4.py
│ └── demo6.py
├── SnowNLP
│ ├── demo1.py
│ └── test.py
└── test.py
├── .gitattributes
├── PythonSpider
├── .spyproject
│ ├── codestyle.ini
│ ├── encoding.ini
│ ├── vcs.ini
│ └── workspace.ini
├── selenium
│ ├── firstDemo.py
│ ├── csdn.py
│ ├── zhihu.py
│ └── xiaomiShequ.py
├── spider
│ ├── requestsTuicool.py
│ ├── urllib.requestTuicool.py
│ ├── requestsTuicool2.py
│ ├── urllib.requestTuicool2.py
│ ├── urllib.requestDemo1.py
│ ├── bs4quickstart.py
│ ├── bs4WangYiYun.py
│ ├── bs4Meizitu.py
│ ├── bs4JokeToExcel.py
│ ├── bs4WangYiYunToExcel.py
│ └── bs4WangYiYunToExcel2.py
├── openvcDemo1.py
├── openvc_video.py
├── openvc_camera.py
├── openvc_video2.py
├── openvc_camera2.py
├── openvc_camera3.py
├── openvcDemo2.py
├── openvc_camera4.py
├── SimpleCrawler.py
├── openvc_camera5.py
└── weixin
│ └── crawler.py
├── README.md
└── .gitignore
/PythonDemo/wordcloud/examples/README.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
--------------------------------------------------------------------------------
/PythonDemo/readme.txt:
--------------------------------------------------------------------------------
1 | wordcloud词云 jieba分词 itchat wxpy微信相关
2 | Matplotlib第三库
3 | numpy第三库
--------------------------------------------------------------------------------
/PythonDemo/weixin/wxpy.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/weixin/wxpy.pkl
--------------------------------------------------------------------------------
/PythonDemo/PIL/alice_color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/alice_color.png
--------------------------------------------------------------------------------
/PythonDemo/weixin/itchat.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/weixin/itchat.pkl
--------------------------------------------------------------------------------
/PythonDemo/.spyproject/codestyle.ini:
--------------------------------------------------------------------------------
1 | [codestyle]
2 | indentation = True
3 |
4 | [main]
5 | version = 0.1.0
6 |
7 |
--------------------------------------------------------------------------------
/PythonDemo/.spyproject/encoding.ini:
--------------------------------------------------------------------------------
1 | [encoding]
2 | text_encoding = utf-8
3 |
4 | [main]
5 | version = 0.1.0
6 |
7 |
--------------------------------------------------------------------------------
/PythonDemo/weixin/signatures.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/weixin/signatures.jpg
--------------------------------------------------------------------------------
/PythonSpider/.spyproject/codestyle.ini:
--------------------------------------------------------------------------------
1 | [codestyle]
2 | indentation = True
3 |
4 | [main]
5 | version = 0.1.0
6 |
7 |
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python1.png
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python2.png
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python3.png
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python4.png
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python5.png
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python6.png
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python7.png
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python8.png
--------------------------------------------------------------------------------
/PythonDemo/PIL/result/python9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/PIL/result/python9.png
--------------------------------------------------------------------------------
/PythonDemo/weixin/alice_color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/weixin/alice_color.png
--------------------------------------------------------------------------------
/PythonSpider/.spyproject/encoding.ini:
--------------------------------------------------------------------------------
1 | [encoding]
2 | text_encoding = utf-8
3 |
4 | [main]
5 | version = 0.1.0
6 |
7 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/alice.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/alice.png
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/parrot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/parrot.png
--------------------------------------------------------------------------------
/PythonDemo/.spyproject/vcs.ini:
--------------------------------------------------------------------------------
1 | [vcs]
2 | use_version_control = False
3 | version_control_system =
4 |
5 | [main]
6 | version = 0.1.0
7 |
8 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/a_new_hope.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/a_new_hope.png
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/alice_color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/alice_color.png
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/alice_mask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/alice_mask.png
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/alice_colored.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/alice_colored.png
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/constitution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/constitution.png
--------------------------------------------------------------------------------
/PythonSpider/.spyproject/vcs.ini:
--------------------------------------------------------------------------------
1 | [vcs]
2 | use_version_control = False
3 | version_control_system =
4 |
5 | [main]
6 | version = 0.1.0
7 |
8 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/colored_by_group.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/colored_by_group.png
--------------------------------------------------------------------------------
/PythonDemo/saveToExcel/xwltDemo2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 15:39:00 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/a_new_hope_bigrams.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/a_new_hope_bigrams.png
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/stormtrooper_mask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/stormtrooper_mask.png
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/fonts/Symbola/Symbola.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/fonts/Symbola/Symbola.pdf
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/fonts/Symbola/Symbola.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Snailclimb/python/HEAD/PythonDemo/wordcloud/examples/fonts/Symbola/Symbola.ttf
--------------------------------------------------------------------------------
/PythonDemo/test2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | print("sss")
4 | import psutil
5 | print(psutil.cpu_count()) # CPU逻辑数量
6 | print(psutil.cpu_times()) #统计CPU的用户/系统/空闲时间:
--------------------------------------------------------------------------------
/PythonSpider/selenium/firstDemo.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 |
4 | ## 引入WebDriver的包
5 | from selenium import webdriver
6 |
7 | ## 创建浏览器对象
8 | browser = webdriver.Firefox()
9 |
10 | ## 打开百度网站
11 | browser.get('https://www.baidu.com/')
--------------------------------------------------------------------------------
/PythonDemo/numpy/broadcast.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 16:29:45 2018
4 |
5 | @author: Administrator
6 | """
7 | import numpy as np
8 | a=np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
9 | b=np.array([1, 2, 3])
10 | c=a+b
11 | print(c)
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed Mar 14 10:13:32 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 |
9 | import matplotlib.pyplot as plt
10 | from skimage import data
11 | img=data.astronaut()
12 | plt.imshow(img)
13 | plt.show()
14 |
15 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/fonts/Symbola/README.md:
--------------------------------------------------------------------------------
1 | The symbola font was downloaded from George Douros at http://users.teilar.gr/~g1951d/
2 |
3 | On that site (and inside the pdf), the license is described as follows:
4 | In lieu of a licence; fonts and documents in this site are free for any use; George Douros
--------------------------------------------------------------------------------
/PythonSpider/spider/requestsTuicool.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 不实用http请求头,一些网站可能无法爬取
4 | """
5 |
6 | # coding utf-8
7 | import requests
8 |
9 | def get_content():
10 | html = requests.get("https://www.tuicool.com/")
11 | return html.text
12 |
13 | print(get_content())
--------------------------------------------------------------------------------
/PythonSpider/spider/urllib.requestTuicool.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 不带Http请求头的访问方法
4 | """
5 |
6 | import urllib.request
7 | print("第一种方法:")
8 | response1=urllib.request.urlopen('https://www.tuicool.com/')
9 | html=response1.read().decode('utf-8')
10 | print("输出状态码:")
11 | print(response1.getcode())
--------------------------------------------------------------------------------
/PythonDemo/numpy/arraysort.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 16:01:13 2018
4 |
5 | @author: Administrator
6 | @description: numpy库中的数组排序(sort)函数
7 | """
8 | import numpy as np
9 | from numpy.matlib import randn
10 | arr = randn(8)
11 | print("排序前:")
12 | print(arr)
13 | print("排序后:")
14 | print(np.sort(arr))
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo11.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 绘制Image
4 | """
5 | import matplotlib.pyplot as plt
6 | import numpy as np
7 |
8 | # 定义图像数据
9 | a = np.linspace(0, 1, 9).reshape(3, 3)
10 | # 显示图像数据
11 | plt.imshow(a, interpolation = 'nearest', cmap = 'bone', origin = 'lower')
12 | # 添加颜色条
13 | plt.colorbar()
14 | # 去掉坐标轴
15 | plt.xticks(())
16 | plt.yticks(())
17 | plt.show()
18 |
--------------------------------------------------------------------------------
/PythonDemo/PIL/demo1加载图像.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 使用 Image 类
4 | """
5 |
6 | from PIL import Image
7 | im = Image.open("alice_color.png")
8 | #format 这个属性标识了图像来源
9 | #size属性是一个二元tuple,(600, 800):宽:600px,高:800px
10 | # mode 属性定义了图像bands的数量和名称,以及像素类型和深度。常见的modes 有 “L” (luminance) 表示灰度图像, “RGB” 表示真彩色图像, and “CMYK” 表示出版图像。
11 | print(im.format, im.size, im.mode)#PNG (600, 800) RGBA
12 | im.show()#显示图像
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo1.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 简单图形绘制
4 |
5 | """
6 |
7 | import matplotlib.pyplot as plt
8 | import numpy as np
9 |
10 | #从-1-----1之间等间隔采66个数.也就是说所画出来的图形是66个点连接得来的
11 | #注意:如果点数过小的话会导致画出来二次函数图像不平滑
12 | x = np.linspace(-1, 1,66)
13 | # 绘制y=2x+1函数的图像
14 | y = 2 * x + 1
15 | plt.plot(x, y)
16 | plt.show()
17 |
18 | # 绘制x^2函数的图像
19 | y = x**2
20 | plt.plot(x, y)
21 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/numpy/arrayunique.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 16:02:47 2018
4 |
5 | @author: Administrator
6 | @description: numpy库unique函数保证数组中的元素唯一(剔除重复元素)
7 | """
8 |
9 | import numpy as np
10 | names = np.array(['Bob', 'Joe', 'Will', 'Bob', 'Will', 'Joe', 'Joe'])
11 | print(np.unique(names))
12 | ints = np.array([3, 3, 3, 2, 2, 1, 1, 4, 4,5])
13 | print(np.unique(ints))
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo13.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | subplot绘制多图
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 |
8 | plt.figure()
9 |
10 | # 绘制第一个图
11 | plt.subplot(2, 2, 1)
12 | plt.plot([0, 1], [0, 1])
13 | # 绘制第二个图
14 | plt.subplot(2, 2, 2)
15 | plt.plot([0, 1], [0, 1])
16 | # 绘制第三个图
17 | plt.subplot(2, 2, 3)
18 | plt.plot([0, 1], [0, 1])
19 | # 绘制第四个图
20 | plt.subplot(2, 2, 4)
21 | plt.plot([0, 1], [0, 1])
22 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo14.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | subplot绘制多图
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 |
8 | plt.figure()
9 |
10 | # 绘制第一个图
11 | plt.subplot(2, 1, 1)
12 | plt.plot([0, 1], [0, 1])
13 | # 绘制第二个图
14 | plt.subplot(2, 3, 4)
15 | plt.plot([0, 1], [0, 1])
16 | # 绘制第三个图
17 | plt.subplot(2, 3, 5)
18 | plt.plot([0, 1], [0, 1])
19 | # 绘制第四个图
20 | plt.subplot(2, 3, 6)
21 | plt.plot([0, 1], [0, 1])
22 | plt.show()
--------------------------------------------------------------------------------
/PythonSpider/openvcDemo1.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue May 22 16:03:30 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | #导入cv模块
9 | import cv2 as cv
10 | #读取图像,支持 bmp、jpg、png、tiff 等常用格式
11 | img = cv.imread("D:\\picture\\VCG41475980712.jpg")
12 | #输出OpenCV的版本号
13 | print(cv.__version__)
14 | #创建窗口并显示图像
15 | cv.namedWindow("Image")
16 | cv.imshow("Image",img)
17 | cv.waitKey(0)
18 | #释放窗口
19 | cv.destroyAllWindows()
20 |
--------------------------------------------------------------------------------
/PythonSpider/spider/requestsTuicool2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 使用http请求头
4 | """
5 |
6 | # coding utf-8
7 | import requests
8 |
9 | def get_content():
10 | header = {
11 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
12 | }
13 | html = requests.get("https://www.tuicool.com/",headers=header)
14 | return html.text
15 |
16 | print(get_content())
--------------------------------------------------------------------------------
/PythonDemo/weixin/weixinchatRobotSingle.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 19:09:05 2018
4 |
5 | @author: Snailclimb
6 | @description使用图灵机器人自动与指定好友聊天
7 | """
8 |
9 | from wxpy import Bot,Tuling,embed,ensure_one
10 | bot = Bot()
11 | my_friend = ensure_one(bot.search('郑凯')) #想和机器人聊天的好友的备注
12 | tuling = Tuling(api_key='72bce33cb2b248a199d07175225a5264')
13 | @bot.register(my_friend) # 使用图灵机器人自动与指定好友聊天
14 | def reply_my_friend(msg):
15 | tuling.do_reply(msg)
16 | embed()
--------------------------------------------------------------------------------
/PythonDemo/weixin/weixinchatRobotGroup.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 18:55:04 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | from wxpy import Bot,Tuling,embed
9 | bot = Bot(cache_path=True)
10 | my_group = bot.groups().search('群聊名称')[0] # 记得把名字改成想用机器人的群
11 | tuling = Tuling(api_key='72bce33cb2b248a199d07175225a5264') # 一定要添加,不然实现不了
12 | @bot.register(my_group, except_self=False) # 使用图灵机器人自动在指定群聊天
13 | def reply_my_friend(msg):
14 | print(tuling.do_reply(msg))
15 | embed()
--------------------------------------------------------------------------------
/PythonSpider/spider/urllib.requestTuicool2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 带http请求头的访问方法
4 | """
5 | import urllib.request
6 | print("第二种方法:")
7 | request = urllib.request.Request('https://www.tuicool.com/')
8 | request.add_header("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101")
9 | response1=urllib.request.urlopen(request)
10 | html=response1.read().decode('utf-8')
11 | print("输出状态码:")
12 | print(response1.getcode())
13 | print("输出文本长度:")
14 | print(len(html))
15 | print(html)
16 |
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo8.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 绘制散点图
4 | """
5 |
6 | import numpy as np
7 | import matplotlib.pyplot as plt
8 |
9 | # 数据个数
10 | n = 1024
11 | # 均值为0, 方差为1的随机数
12 | x = np.random.normal(0, 1, n)
13 | y = np.random.normal(0, 1, n)
14 |
15 | # 计算颜色值
16 | color = np.arctan2(y, x)
17 | # 绘制散点图
18 | plt.scatter(x, y, s = 75, c = color, alpha = 0.5)
19 | # 设置坐标轴范围
20 | plt.xlim((-1.5, 1.5))
21 | plt.ylim((-1.5, 1.5))
22 |
23 | # 不显示坐标轴的值
24 | plt.xticks(())
25 | plt.yticks(())
26 |
27 | plt.show()
--------------------------------------------------------------------------------
/PythonSpider/openvc_video.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed May 23 22:29:59 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | import cv2
9 | # 播放本地视频
10 | capture = cv2.VideoCapture("D:\\you-get_download\\muzi.flv")
11 | while(capture.isOpened()):
12 | ret, frame = capture.read()
13 | #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
14 | cv2.imshow("frame", frame) #彩色画面播放
15 | #cv2.imshow("frame", gray) #黑白画面播放
16 | if cv2.waitKey(30) == ord('q'):
17 | break
18 |
19 |
20 |
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo18.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 主次坐标轴
4 | """
5 | import numpy as np
6 | import matplotlib.pyplot as plt
7 |
8 | # 定义数据
9 | x = np.arange(0, 10, 0.1)
10 | y1 = 0.05 * x ** 2
11 | y2 = -1 * y1
12 |
13 | # 定义figure
14 | fig, ax1 = plt.subplots()
15 | # 得到ax1的对称轴ax2
16 | ax2 = ax1.twinx()
17 | # 绘制图像
18 | ax1.plot(x, y1, 'g-')
19 | ax2.plot(x, y2, 'b--')
20 |
21 | # 设置label
22 | ax1.set_xlabel('X data')
23 | ax1.set_xlabel('Y1', color = 'g')
24 | ax2.set_xlabel('Y2', color = 'b')
25 |
26 | plt.show()
27 |
--------------------------------------------------------------------------------
/PythonSpider/openvc_camera.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed May 23 11:11:09 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | # 打开摄像头并灰度化显示
9 | import cv2
10 | capture = cv2.VideoCapture(0)
11 | while(True):
12 | # 获取一帧
13 | ret, frame = capture.read()
14 | # 将这帧转换为灰度图
15 | # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
16 | #第一个参数是窗口名称,第二个参数从摄像头读取到的内容
17 | cv2.imshow('frame', frame)
18 | if cv2.waitKey(1) == ord('q'):
19 | break
20 | capture.release()
21 | cv2.destroyAllWindows()
22 |
--------------------------------------------------------------------------------
/PythonDemo/numpy/numpy简单介绍:
--------------------------------------------------------------------------------
1 | NumPy系统是Python的一种开源的数值计算扩展。
2 | 这种工具可用来存储和处理大型矩阵,比Python自身的嵌套列表(nested list structure)结构
3 | 要高效的多(该结构也可以用来表示矩阵(matrix))。
4 |
5 |
6 | 外文名:numpy
7 | 含 义:Python的一种开源的数字扩展
8 | 内 容:一个强大的N维数组对象Array
9 | 用 途:存储和处理大型矩阵
10 | 一个用python实现的科学计算包。包括:1、一个强大的N维数组对象Array;2、比较成熟的(广播)函数库;
11 | 3、用于整合C/C++和Fortran代码的工具包;4、实用的线性代数、傅里叶变换和随机数生成函数。
12 | numpy和稀疏矩阵运算包scipy配合使用更加方便。
13 |
14 | NumPy(Numeric Python)提供了许多高级的数值编程工具,
15 | 如:矩阵数据类型、矢量处理,以及精密的运算库。
16 | 专为进行严格的数字处理而产生。多为很多大型金融公司使用,以及核心的科学计算组织如:
17 | Lawrence Livermore,NASA用其处理一些本来使用C++,Fortran或Matlab等所做的任务。
18 |
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo16.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | figure绘制多图
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 | import matplotlib.gridspec as gridspec
8 |
9 | # 定义figure
10 | plt.figure()
11 | # 分隔figure
12 | gs = gridspec.GridSpec(3, 3)
13 | ax1 = plt.subplot(gs[0, :])
14 | ax2 = plt.subplot(gs[1, 0:2])
15 | ax3 = plt.subplot(gs[1, 2])
16 | ax4 = plt.subplot(gs[2, :])
17 |
18 | # 绘制图像
19 | ax1.plot([0, 1], [0, 1])
20 | ax1.set_title('Test')
21 |
22 | ax2.plot([0, 1], [0, 1])
23 |
24 | ax3.plot([0, 1], [0, 1])
25 |
26 | ax4.plot([0, 1], [0, 1])
27 |
28 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | figure的使用
4 | """
5 | import matplotlib.pyplot as plt
6 | import numpy as np
7 | #
8 | x = np.linspace(-1, 1, 50)
9 |
10 |
11 | # figure 1
12 | y1 = 2 * x + 1
13 | plt.figure()
14 | plt.plot(x, y1)
15 |
16 |
17 | # figure 2
18 | y2 = x**2
19 | plt.figure()
20 | plt.plot(x, y2)
21 |
22 |
23 | # figure 3,指定figure的编号并指定figure的大小, 指定线的颜色, 宽度和类型
24 | #一个坐标轴上画了两个图形
25 | y2 = x**2
26 | plt.figure(num = 5, figsize = (4, 4))
27 | plt.plot(x, y1)
28 | plt.plot(x, y2, color = 'red', linewidth = 1.0, linestyle = '--')
29 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/weixin/weixinlocation.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Fri Mar 16 08:22:17 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | # -*- coding: utf-8 -*-
9 | """
10 | 微信好友性别及位置信息
11 | """
12 |
13 | #导入模块
14 | from wxpy import Bot
15 |
16 | '''Q
17 | 微信机器人登录有3种模式,
18 | (1)极简模式:robot = Bot()
19 | (2)终端模式:robot = Bot(console_qr=True)
20 | (3)缓存模式(可保持登录状态):robot = Bot(cache_path=True)
21 | '''
22 | #初始化机器人,选择缓存模式(扫码)登录
23 | robot = Bot(cache_path=True)
24 |
25 | #获取好友
26 | robot.chats()
27 | #robot.mps()#获取微信公众号信息
28 |
29 | #获取好友的统计信息
30 | Friends = robot.friends()
31 | print(Friends.stats_text())
32 |
--------------------------------------------------------------------------------
/PythonDemo/.spyproject/workspace.ini:
--------------------------------------------------------------------------------
1 | [workspace]
2 | restore_data_on_startup = True
3 | save_data_on_exit = True
4 | save_history = True
5 | save_non_project_files = False
6 |
7 | [main]
8 | version = 0.1.0
9 | recent_files = ['C:\\Users\\Administrator\\.spyder-py3\\temp.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\numpy\\arrayboolean.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\numpy\\arraymethod.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\weixin\\weixinQianming.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\PIL\\cutImage.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\PIL\\demo1加载图像.py', 'D:\\Anaconda3\\lib\\site-packages\\PIL\\Image.py']
10 |
11 |
--------------------------------------------------------------------------------
/PythonSpider/openvc_video2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed May 23 22:38:40 2018
4 |
5 | @author: Administrator
6 | """
7 | #录制视频
8 | #https://www.jianshu.com/p/2b79012c0228
9 | import cv2
10 | capture = cv2.VideoCapture(0)
11 | # 定义编码方式并创建VideoWriter对象
12 | fourcc = cv2.VideoWriter_fourcc(*'MJPG')
13 | outfile = cv2.VideoWriter("D:\\you-get_download\\output.avi", fourcc, 25., (640, 480))
14 | while(capture.isOpened()):
15 | ret, frame = capture.read()
16 | if ret:
17 | outfile.write(frame) # 写入文件
18 | cv2.imshow('frame', frame)
19 | if cv2.waitKey(1) == ord('q'):
20 | break
21 | else: break
22 |
--------------------------------------------------------------------------------
/PythonSpider/selenium/csdn.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Sat Mar 17 18:30:06 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | from selenium import webdriver
9 | ## 创建浏览器对象
10 | browser = webdriver.Firefox()
11 | ## 打开小米社区网站
12 | browser.get('https://passport.csdn.net/account/login')
13 | browser.find_element_by_xpath("//*[@id='username']").clear()#清空输入框
14 | browser.find_element_by_xpath("//*[@id='username']").send_keys("1361583339@qq.com")#输入账号
15 | browser.find_element_by_xpath("//*[@id='password']").clear()#清空输入框
16 | browser.find_element_by_xpath("//*[@id='password']").send_keys("cSdN153963")#输入密码
17 | browser.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/div[1]/div/form/input[8]").click()#登录
18 |
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo10.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 绘制登高线图
4 | """
5 | import matplotlib.pyplot as plt
6 | import numpy as np
7 |
8 | # 定义等高线高度函数
9 | def f(x, y):
10 | return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(- x ** 2 - y ** 2)
11 |
12 | # 数据数目
13 | n = 256
14 | # 定义x, y
15 | x = np.linspace(-3, 3, n)
16 | y = np.linspace(-3, 3, n)
17 |
18 | # 生成网格数据
19 | X, Y = np.meshgrid(x, y)
20 |
21 |
22 | # 填充等高线的颜色, 8是等高线分为几部分
23 | plt.contourf(X, Y, f(X, Y), 8, alpha = 0.75, cmap = plt.cm.hot)
24 | # 绘制等高线
25 | C = plt.contour(X, Y, f(X, Y), 8, colors = 'black', linewidth = 0.5)
26 | # 绘制等高线数据
27 | plt.clabel(C, inline = True, fontsize = 10)
28 |
29 | # 去除坐标轴
30 | plt.xticks(())
31 | plt.yticks(())
32 | plt.show()
33 |
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo3.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 设置坐标轴
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 | import numpy as np
8 |
9 | # 绘制普通图像
10 | x = np.linspace(-1, 1, 50)
11 | y1 = 2 * x + 1
12 | y2 = x**2
13 |
14 | plt.figure()
15 | plt.plot(x, y1)
16 | plt.plot(x, y2, color = 'red', linewidth = 1.0, linestyle = '--')
17 |
18 | # 设置坐标轴的取值范围
19 | plt.xlim((-1, 1))
20 | plt.ylim((0, 3))
21 |
22 | # 设置坐标轴的lable
23 | #标签里面必须添加字体变量:fontproperties='SimHei',fontsize=14。不然可能会乱码
24 | plt.xlabel(u'这是x轴',fontproperties='SimHei',fontsize=14)
25 | plt.ylabel(u'这是y轴',fontproperties='SimHei',fontsize=14)
26 |
27 | # 设置x坐标轴刻度, 之前为0.25, 修改后为0.5
28 | #也就是在坐标轴上取5个点,x轴的范围为-1到1所以取5个点之后刻度就变为0.5了
29 | plt.xticks(np.linspace(-1, 1, 5))
30 |
31 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo12.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 绘制3d图形
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 | import numpy as np
8 | from mpl_toolkits.mplot3d import Axes3D
9 | # 定义figure
10 | fig = plt.figure()
11 | # 将figure变为3d
12 | ax = Axes3D(fig)
13 |
14 | # 数据数目
15 | n = 256
16 | # 定义x, y
17 | x = np.arange(-4, 4, 0.25)
18 | y = np.arange(-4, 4, 0.25)
19 |
20 | # 生成网格数据
21 | X, Y = np.meshgrid(x, y)
22 |
23 | # 计算每个点对的长度
24 | R = np.sqrt(X ** 2 + Y ** 2)
25 | # 计算Z轴的高度
26 | Z = np.sin(R)
27 |
28 | # 绘制3D曲面
29 | ax.plot_surface(X, Y, Z, rstride = 1, cstride = 1, cmap = plt.get_cmap('rainbow'))
30 | # 绘制从3D曲面到底部的投影
31 | ax.contour(X, Y, Z, zdim = 'z', offset = -2, cmap = 'rainbow')
32 |
33 | # 设置z轴的维度
34 | ax.set_zlim(-2, 2)
35 |
36 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo19.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 动画
4 | """
5 | import numpy as np
6 | import matplotlib.pyplot as plt
7 | from matplotlib import animation
8 |
9 |
10 | # 定义figure
11 | fig, ax = plt.subplots()
12 |
13 | # 定义数据
14 | x = np.arange(0, 2 * np.pi, 0.01)
15 | # line, 表示只取返回值中的第一个元素
16 | line, = ax.plot(x, np.sin(x))
17 |
18 | # 定义动画的更新
19 | def update(i):
20 | line.set_ydata(np.sin(x + i/10))
21 | return line,
22 |
23 | # 定义动画的初始值
24 | def init():
25 | line.set_ydata(np.sin(x))
26 | return line,
27 |
28 | # 创建动画
29 | ani = animation.FuncAnimation(fig = fig, func = update, init_func = init, interval = 10, blit = False, frames = 200)
30 |
31 | # 展示动画
32 | plt.show()
33 |
34 | # 动画保存
35 | ani.save('sin.html', writer = 'imagemagick', fps = 30, dpi = 100)
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo5.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 设置
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 | import numpy as np
8 |
9 | # 绘制普通图像
10 | x = np.linspace(-1, 1, 50)
11 | y1 = 2 * x + 1
12 | y2 = x**2
13 |
14 | plt.figure()
15 | # 在绘制时设置lable, 逗号是必须的
16 | l1, = plt.plot(x, y1, label = 'line')
17 | l2, = plt.plot(x, y2, label = 'parabola', color = 'red', linewidth = 1.0, linestyle = '--')
18 |
19 | # 设置坐标轴的取值范围
20 | plt.xlim((-1, 1))
21 | plt.ylim((0, 2))
22 |
23 | # 设置坐标轴的lable
24 | plt.xlabel('X')
25 | plt.ylabel('Y')
26 |
27 | # 设置x坐标轴刻度, 原来为0.25, 修改后为0.5
28 | plt.xticks(np.linspace(-1, 1, 5))
29 | # 设置y坐标轴刻度及标签, $$是设置字体
30 | plt.yticks([0, 0.5], ['$minimum$', 'normal'])
31 |
32 | # 设置legend
33 | plt.legend(handles = [l1, l2,], labels = ['a', 'b'], loc = 'best')
34 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo15.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | figure绘制多图
4 | """
5 | import matplotlib.pyplot as plt
6 |
7 | # 定义figure
8 | plt.figure()
9 | # figure分成3行3列, 取得第一个子图的句柄, 第一个子图跨度为1行3列, 起点是表格(0, 0)
10 | ax1 = plt.subplot2grid((3, 3), (0, 0), colspan = 3, rowspan = 1)
11 | ax1.plot([0, 1], [0, 1])
12 | ax1.set_title('Test')
13 |
14 | # figure分成3行3列, 取得第二个子图的句柄, 第二个子图跨度为1行3列, 起点是表格(1, 0)
15 | ax2 = plt.subplot2grid((3, 3), (1, 0), colspan = 2, rowspan = 1)
16 | ax2.plot([0, 1], [0, 1])
17 |
18 | # figure分成3行3列, 取得第三个子图的句柄, 第三个子图跨度为1行1列, 起点是表格(1, 2)
19 | ax3 = plt.subplot2grid((3, 3), (1, 2), colspan = 1, rowspan = 1)
20 | ax3.plot([0, 1], [0, 1])
21 |
22 | # figure分成3行3列, 取得第四个子图的句柄, 第四个子图跨度为1行3列, 起点是表格(2, 0)
23 | ax4 = plt.subplot2grid((3, 3), (2, 0), colspan = 3, rowspan = 1)
24 | ax4.plot([0, 1], [0, 1])
25 |
26 | plt.show()
27 |
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo7.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed Mar 14 17:11:15 2018
4 | 设置坐标轴label上数字的样式
5 | """
6 |
7 | import matplotlib.pyplot as plt
8 | import numpy as np
9 |
10 | # 绘制普通图像
11 | x = np.linspace(-3, 3, 50)
12 | y = 2 * x + 1
13 |
14 | plt.figure()
15 | plt.plot(x, y)
16 |
17 | # 将上、右边框去掉
18 | ax = plt.gca()
19 | ax.spines['right'].set_color('none')
20 | ax.spines['top'].set_color('none')
21 |
22 | # 设置x轴的位置及数据在坐标轴上的位置
23 | ax.xaxis.set_ticks_position('bottom')
24 | ax.spines['bottom'].set_position(('data', 0))
25 | # 设置y轴的位置及数据在坐标轴上的位置
26 | ax.yaxis.set_ticks_position('left')
27 | ax.spines['left'].set_position(('data', 0))
28 |
29 | # 设置坐标轴label的大小,背景色等信息
30 | for label in ax.get_xticklabels() + ax.get_yticklabels():
31 | label.set_fontsize(12)
32 | label.set_bbox(dict(facecolor = 'green', edgecolor = 'None', alpha = 0.7))
33 |
34 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo9.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 绘制柱状图
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 | import numpy as np
8 |
9 | # 数据数目
10 | n = 10
11 | x = np.arange(n)
12 | # 生成数据, 均匀分布(0.5, 1.0)之间
13 | y1 = (1 - x / float(n)) * np.random.uniform(0.5, 1.0, n)
14 | y2 = (1 - x / float(n)) * np.random.uniform(0.5, 1.0, n)
15 |
16 | # 绘制柱状图, 向上
17 | plt.bar(x, y1, facecolor = 'blue', edgecolor = 'white')
18 | # 绘制柱状图, 向下
19 | plt.bar(x, -y2, facecolor = 'green', edgecolor = 'white')
20 |
21 |
22 | temp = zip(x, y2)
23 | # 在柱状图上显示具体数值, ha水平对齐, va垂直对齐
24 | for x, y in zip(x, y1):
25 | plt.text(x + 0.05, y + 0.1, '%.2f' % y, ha = 'center', va = 'bottom')
26 |
27 | for x, y in temp:
28 | plt.text(x + 0.05, -y - 0.1, '%.2f' % y, ha = 'center', va = 'bottom')
29 |
30 | # 设置坐标轴范围
31 | plt.xlim(-1, n)
32 | plt.ylim(-1.5, 1.5)
33 | # 去除坐标轴
34 | plt.xticks(())
35 | plt.yticks(())
36 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/simple.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | Minimal Example
4 | ===============
5 |
6 | 使用默认参数根据美国宪法生成方形的词云
7 | """
8 |
9 | from os import path
10 | from wordcloud import WordCloud
11 |
12 | d = path.dirname(__file__)
13 |
14 | # 读取整个文本
15 | text = open(path.join(d, 'constitution.txt')).read()
16 |
17 | # 生成一个词云图像
18 | wordcloud = WordCloud().generate(text)
19 |
20 | # matplotlib的方式展示生成的词云图像
21 | import matplotlib.pyplot as plt
22 | plt.imshow(wordcloud, interpolation='bilinear')
23 | plt.axis("off")
24 |
25 | #max_font_size设定生成词云中的文字最大大小
26 | #width,height,margin可以设置图片属性
27 | # generate 可以对全部文本进行自动分词,但是他对中文支持不好
28 | wordcloud = WordCloud(max_font_size=66).generate(text)
29 | plt.figure()
30 | plt.imshow(wordcloud, interpolation="bilinear")
31 | plt.axis("off")
32 | plt.show()
33 |
34 | # pil方式展示生成的词云图像(如果你没有matplotlib)
35 | # image = wordcloud.to_image()
36 | # image.show()
37 |
--------------------------------------------------------------------------------
/PythonSpider/openvc_camera2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed May 23 11:14:42 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | # 打开摄像头并灰度化显示
9 | import cv2
10 | capture = cv2.VideoCapture(0)
11 | # OpenCV人脸识别分类器
12 | classifier = cv2.CascadeClassifier( "D:\openvc\haarcascade_frontalface_default.xml" )
13 | color = (0, 255, 0) # 定义绘制颜色
14 |
15 | while(True):
16 | # 获取一帧
17 | ret, frame = capture.read()
18 | # 将这帧转换为灰度图
19 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
20 | # 调用识别人脸
21 | faceRects = classifier.detectMultiScale( gray, scaleFactor=1.2, minNeighbors=3, minSize=(32, 32))
22 | for (x, y, w, h) in faceRects:
23 | cv2.rectangle(gray, (x, y), (x + w, y + h), (255, 0, 0), 2)
24 | cv2.imshow("frame", gray)
25 | if cv2.waitKey(1) & 0xFF == ord('q'):
26 | break
27 |
28 | capture.release()
29 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 备注:会一直更新下去
2 |
3 | ### PythonDemo文件夹:
4 | 包含第三库:**matplotlib(2D绘图库)**,**wordcloud(词云)**,**jieba(中文分词)**,**SnowNLP(Simplified Chinese Text Processing)**以及numpy的例子
5 | 以及使用**itchat**以及**wxpy**对**微信好友信息实现的统计以及基于图灵机器人实现的微信聊天机器人**。
6 |
7 | [用python玩微信(聊天机器人,好友信息统计)](http://blog.csdn.net/qq_34337272/article/details/79559802)
8 |
9 | [Python第三方库matplotlib(2D绘图库)入门与进阶](http://blog.csdn.net/qq_34337272/article/details/79555544)
10 |
11 | [Python第三方库wordcloud(词云)快速入门与进阶](http://blog.csdn.net/qq_34337272/article/details/79552929)
12 |
13 | [Python第三方库jieba(中文分词)入门与进阶(官方文档))](http://blog.csdn.net/qq_34337272/article/details/79554772)
14 |
15 | [Python第三方库SnowNLP(Simplified Chinese Text Processing)快速入门与进阶)](http://blog.csdn.net/qq_34337272/article/details/79577288)
16 |
17 | ### PythonSpider文件夹
18 | 主要包括一些爬虫(知乎,妹子图等等)的实现,目前更新了下列文章
19 |
20 | [selenium在爬虫领域的初涉(自动打开网站爬取信息)](http://blog.csdn.net/qq_34337272/article/details/79594809)
21 |
--------------------------------------------------------------------------------
/PythonSpider/selenium/zhihu.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Sat Mar 17 18:30:06 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | from selenium import webdriver
9 | ## 创建浏览器对象
10 | browser = webdriver.Firefox()
11 | ## 打开小米社区网站
12 | browser.get('https://www.zhihu.com/signin?next=%2F')
13 | browser.find_element_by_xpath("/html/body/div[1]/div/main/div/div/div/div[2]/div[1]/form/div[1]/div[2]/div[1]/input").clear()#清空输入框
14 | browser.find_element_by_xpath("/html/body/div[1]/div/main/div/div/div/div[2]/div[1]/form/div[1]/div[2]/div[1]/input").send_keys("18163138155")#输入账号
15 | browser.find_element_by_xpath("/html/body/div[1]/div/main/div/div/div/div[2]/div[1]/form/div[2]/div/div[1]/input").clear()#清空输入框
16 | browser.find_element_by_xpath("/html/body/div[1]/div/main/div/div/div/div[2]/div[1]/form/div[2]/div/div[1]/input").send_keys("ks1996721kr")#输入密码
17 | browser.find_element_by_xpath("/html/body/div[1]/div/main/div/div/div/div[2]/div[1]/form/button").click()#登录
18 |
--------------------------------------------------------------------------------
/PythonDemo/numpy/arrayboolean.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 16:07:17 2018
4 |
5 | @author: Administrator
6 | @description: any和all函数
7 | """
8 | import numpy as np
9 | from numpy.matlib import randn
10 | print('Boolean values are coerced to 1 (True) and 0 (False) in the above methods. Thus, sum is often used as a means of counting True values in a boolean array:')
11 | arr = randn(100)
12 | print("输出生成的随机数数组中数值大于0的个数:")
13 | print((arr > 0).sum())
14 | bools = np.array([False, False, True, False])
15 | print(bools)
16 | print("只要有一个为true就输出true:")
17 | print(bools.any()) # true
18 | print("全部才输出true:")
19 | print(bools.all()) #false
20 | bools2 = np.array([ True, True, True, True])
21 | print(bools2.all()) #true
22 |
23 | #两个数组之间
24 | # any():a数组与b数组有一个元素对应相等就输出true
25 | #all():a数组与b数组每个元素都对应相等才输出true
26 | a=np.array([1,2,3])
27 | b=np.array([2,2,3])
28 | boolean=(a==b).all()
29 | boolean2=(a==b).any()
30 | print(boolean)#true
31 | print(boolean2)#true
--------------------------------------------------------------------------------
/PythonDemo/weixin/signatures.txt:
--------------------------------------------------------------------------------
1 | 打扰到 分心 自己前进 除了招妹 入群 大家 尽快 不要我能 尝试 别人 成功 只有简单 平和 宁静 快乐 轻松better me你好 明天欢乐 阳光几时遗憾 哪个 痛苦 努力幡动 风动 亦非 风吹 人心学到老 活到老主理 衣品 UNA 尤娜 天成15629323382 包容 宽容 号码 运用很久以前一喊 名字 还是哈哈哈 哈哈勇往直前 勇士 一样快乐奋斗 梦想宽容 怯懦 明白 选择 因为789296 拼搏 无能为力 感动 努力守信 敬业 爱家 诚实自寻烦恼 所有 问题 烦恼 只不过立即行动48 红包 头像 好友 添加快乐 重要慢慢 忽略 感觉 没有快乐 人生逆水 清羽 億佰 游鱼 迎风谢谢 如此猜猜 新品 神秘 什么咸鱼 做些 证明 总是 不是开心梦里 哪怕 曾经 至少 拥有勇敢 就要红尘 沾染 胭脂 青春 不解癞蛤蟆 天鹅 寂寞 没有半个 切图 CEO 前端 商人程序开发 微信 18071906679 13129808189 设限芳华 愿得 满树 韶华 刹那征程 星辰 大海全心全意 服务 人民享下 寻平处 处行 发上 高处若无真 不爱 寂寞 一生 不错一生 半途而废 怀抱 希望等待幸运 努力浴火重生 涅槃 凤凰大不一样 感受 理论 准备 不同fine独家 记忆 喜欢奇妙 人生等待 单纯 到来 习惯 以为一天勤之为 工成 于行过时 永不 一首 努力玉汝于成 motivated man 才疏学浅 艰难困苦载雾 不吸 厚德 自强我要 低调 全世界 知道念念不忘 回响 必有QBQ 问题 背后身心 疲惫 三十 犹如work hard silence let success明月 几时 抬头 自己fighting青青俗人 入世 总有 一样 一些金天囯际 雪莲 充满活力 保养 生态苦短 放平 心有 快乐 心态平谈 平常心 生活拉群 小姐姐 bug 有时候 人工草莓 众生植草 愚笨 春生 荒地 田野脸皮厚 心黑 不含糊 做事永远都是 凋谢 春天 便是 意义春庭 犹见 离人照 落花 多情逆水 游鱼 迎风快乐 简单其折 之大 不知 世界2764 钻石 金刚hello world守信 敬业 爱家 诚实破坏性 吞食 苔藓 巨石 缓慢安之若素 冷暖自知 阳光车险 寿险 信用卡 团体 理财直播 Python 回复 交流 加入所有 填满 伤痛 呐喊 不是靜如 處子 動如脫心不动 不痛
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo17.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | figure图的嵌套
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 |
8 | # 定义figure
9 | fig = plt.figure()
10 |
11 | # 定义数据
12 | x = [1, 2, 3, 4, 5, 6, 7]
13 | y = [1, 3, 4, 2, 5, 8, 6]
14 |
15 | # figure的百分比, 从figure 10%的位置开始绘制, 宽高是figure的80%
16 | left, bottom, width, height = 0.1, 0.1, 0.8, 0.8
17 | # 获得绘制的句柄
18 | ax1 = fig.add_axes([left, bottom, width, height])
19 | # 绘制点(x,y)
20 | ax1.plot(x, y, 'r')
21 | ax1.set_xlabel('x')
22 | ax1.set_ylabel('y')
23 | ax1.set_title('test')
24 |
25 |
26 | # 嵌套方法一
27 | # figure的百分比, 从figure 10%的位置开始绘制, 宽高是figure的80%
28 | left, bottom, width, height = 0.2, 0.6, 0.25, 0.25
29 | # 获得绘制的句柄
30 | ax2 = fig.add_axes([left, bottom, width, height])
31 | # 绘制点(x,y)
32 | ax2.plot(x, y, 'r')
33 | ax2.set_xlabel('x')
34 | ax2.set_ylabel('y')
35 | ax2.set_title('part1')
36 |
37 |
38 | # 嵌套方法二
39 | plt.axes([bottom, left, width, height])
40 | plt.plot(x, y, 'r')
41 | plt.xlabel('x')
42 | plt.ylabel('y')
43 | plt.title('part2')
44 |
45 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/numpy/creatArray.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 14:13:32 2018
4 |
5 | @author: Snailclimb
6 | @description: numpy库创建数组的一些方法
7 | """
8 | import numpy as np
9 | from numpy.matlib import randn
10 | print("创建一维数组:")
11 | data1 = [3, 3.3, 9, 5, 6]
12 | arr1 = np.array(data1)
13 | print(arr1)
14 |
15 | print("创建二维数组:")
16 | data2 = [[1, 2, 3, 4], [5, 6, 7, 8]]
17 | arr2 = np.array(data2)
18 | print(arr2)
19 | # Type of data in array.
20 | print("输出第一个数组的数据类型:",arr1.dtype)
21 | print("输出第二个数组的维数:",arr2.ndim)
22 | print("输出第三个数组的形状:",arr2.shape)
23 | #用zeros函数创建数组
24 | print("np.zeros(10)创建10个元素都是0的一维数组: ")
25 | print(np.zeros(10))
26 | print("np.zeros((3, 6))创建3行6列都是0的二维数组:")
27 | print(np.zeros((3, 6)))
28 | #用Empty函数创建数组,其初始值为乱值
29 | print("np.empty((3,6))创建3行6列都是0的二维数组:")
30 | print(np.empty((3,6)))
31 | #用arrange函数创建数组
32 | print("np.arange(9)创建一维数组:")
33 | print(np.arange(9))
34 | #用随机函数randn创建二维数组,7行4列
35 | print("randn(7, 4))创建数字随机的一维数组:")
36 | data = randn(7, 4)
37 | print(data)
--------------------------------------------------------------------------------
/PythonDemo/weixin/weixinItchatSexAs.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 17:09:26 2018
4 |
5 | @author: Snalclimb
6 | @description 微信好友性别比例
7 | """
8 |
9 | import itchat
10 | import matplotlib.pyplot as plt
11 | from collections import Counter
12 | itchat.auto_login(hotReload=True)
13 | friends = itchat.get_friends(update=True)
14 | sexs = list(map(lambda x: x['Sex'], friends[1:]))
15 | counts = list(map(lambda x: x[1], Counter(sexs).items()))
16 | labels = ['FeMale','Male', 'Unknown']
17 | colors = ['red', 'yellowgreen', 'lightskyblue']
18 | plt.figure(figsize=(8, 5), dpi=80)
19 | plt.axes(aspect=1)
20 | plt.pie(counts, # 性别统计结果
21 | labels=labels, # 性别展示标签
22 | colors=colors, # 饼图区域配色
23 | labeldistance=1.1, # 标签距离圆点距离
24 | autopct='%3.1f%%', # 饼图区域文本格式
25 | shadow=False, # 饼图是否显示阴影
26 | startangle=90, # 饼图起始角度
27 | pctdistance=0.6 # 饼图区域文本距离圆点距离
28 | )
29 | plt.legend(loc='upper right',)
30 | plt.title('%s的微信好友性别组成' % friends[0]['NickName'])
31 | plt.show()
32 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/simple.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed Mar 14 08:09:05 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | #!/usr/bin/env python
9 | """
10 | Minimal Example
11 | ===============
12 | Generating a square wordcloud from the US constitution using default arguments.
13 | """
14 |
15 | from os import path
16 | from wordcloud import WordCloud
17 |
18 | d = path.dirname(__file__)
19 |
20 | # Read the whole text.
21 | text = open(path.join(d, 'constitution.txt')).read()
22 |
23 | # Generate a word cloud image
24 | wordcloud = WordCloud().generate(text)
25 |
26 | # Display the generated image:
27 | # the matplotlib way:
28 | import matplotlib.pyplot as plt
29 | plt.imshow(wordcloud, interpolation='bilinear')
30 | plt.axis("off")
31 |
32 | # lower max_font_size
33 | wordcloud = WordCloud(max_font_size=40).generate(text)
34 | plt.figure()
35 | plt.imshow(wordcloud, interpolation="bilinear")
36 | plt.axis("off")
37 | plt.show()
38 |
39 | # The pil way (if you don't have matplotlib)
40 | # image = wordcloud.to_image()
41 | # image.show()
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/masked.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | Masked wordcloud
4 | ================
5 |
6 | 使用蒙版图像可以生成任意形状的wordcloud。
7 | """
8 |
9 | from os import path
10 | from PIL import Image
11 | import numpy as np
12 | import matplotlib.pyplot as plt
13 |
14 | from wordcloud import WordCloud, STOPWORDS
15 |
16 | d = path.dirname(__file__)
17 |
18 | # 读取整个文本.
19 | text = open(path.join(d, 'alice.txt')).read()
20 |
21 | #读取图片(图片来源:http://www.stencilry.org/stencils/movies/alice%20in%20wonderland/255fk.jpg)
22 | alice_mask = np.array(Image.open(path.join(d, "alice_mask.png")))
23 |
24 | stopwords = set(STOPWORDS)
25 | stopwords.add("said")
26 | #设置词云的一些属性
27 | wc = WordCloud(background_color="white", max_words=2000, mask=alice_mask,
28 | stopwords=stopwords)
29 | # 生成词云
30 | wc.generate(text)
31 |
32 | #保存到本地
33 | wc.to_file(path.join(d, "alice.png"))
34 |
35 | #展示
36 | plt.imshow(wc, interpolation='bilinear')
37 | plt.axis("off")
38 | plt.figure()
39 | plt.imshow(alice_mask, cmap=plt.cm.gray, interpolation='bilinear')
40 | plt.axis("off")
41 | plt.show()
42 |
--------------------------------------------------------------------------------
/PythonSpider/spider/urllib.requestDemo1.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 17:25:58 2018
4 |
5 | @author: Snaliclimb
6 | @description: urllib.request的三种使用
7 | """
8 | import urllib.request,http.cookiejar
9 | print("第一种方法:")
10 | response1=urllib.request.urlopen('http://www.baidu.com')
11 | html=response1.read()
12 | print("输出状态码:")
13 | print(response1.getcode())
14 | print("输出文本长度:")
15 | print(len(html))
16 |
17 | print("第二种方法:")
18 | request = urllib.request.Request('http://www.baidu.com')
19 | request.add_header("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101")
20 | response1=urllib.request.urlopen(request)
21 | html=response1.read()
22 | print("输出状态码:")
23 | print(response1.getcode())
24 | print("输出文本长度:")
25 | print(len(html))
26 |
27 | print("第三种方法:")
28 | cj = http.cookiejar.CookieJar()
29 | opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
30 | urllib.request.install_opener(opener)
31 | response3 = urllib.request.urlopen('http://www.baidu.com')
32 | print(response3.getcode())
33 | print(cj)
34 | print(response3.read())
--------------------------------------------------------------------------------
/PythonSpider/openvc_camera3.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed May 23 11:23:10 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | import cv2
9 |
10 | detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
11 | cap = cv2.VideoCapture(0)
12 | sampleNum = 0
13 | #Id = raw_input('enter your id: ')
14 |
15 | while True:
16 | ret, img = cap.read()
17 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
18 | faces = detector.detectMultiScale(gray, 1.3, 5)
19 | for (x, y, w, h) in faces:
20 | cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
21 |
22 | # incrementing sample number
23 | sampleNum = sampleNum + 1
24 | # saving the captured face in the dataset folder
25 | cv2.imwrite("D:\\picture\\face\\" + str(1) + '.' + str(sampleNum) + ".jpg", gray[y:y + h, x:x + w]) #
26 |
27 | cv2.imshow('frame', img)
28 | # wait for 100 miliseconds
29 | if cv2.waitKey(100) & 0xFF == ord('q'):
30 | break
31 | # break if the sample number is morethan 20
32 | elif sampleNum > 100:
33 | break
34 |
35 | cap.release()
36 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo4.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 设置坐标轴
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 | import numpy as np
8 |
9 | # 绘制普通图像
10 | x = np.linspace(-1, 1, 50)
11 | y1 = 2 * x + 1
12 | y2 = x**2
13 |
14 | plt.figure()
15 | plt.plot(x, y1)
16 | plt.plot(x, y2, color = 'red', linewidth = 1.0, linestyle = '--')
17 |
18 | # 设置坐标轴的取值范围
19 | plt.xlim((-1, 1))
20 | plt.ylim((0, 3))
21 |
22 | # 设置坐标轴的lable
23 | #标签里面必须添加字体变量:fontproperties='SimHei',fontsize=14。不然可能会乱码
24 | plt.xlabel(u'这是x轴',fontproperties='SimHei',fontsize=14)
25 | plt.ylabel(u'这是y轴',fontproperties='SimHei',fontsize=14)
26 |
27 | # 设置x坐标轴刻度, 之前为0.25, 修改后为0.5
28 | #也就是在坐标轴上取5个点,x轴的范围为-1到1所以取5个点之后刻度就变为0.5了
29 | plt.xticks(np.linspace(-1, 1, 5))
30 | # 获取当前的坐标轴, gca = get current axis
31 | ax = plt.gca()
32 | # 设置右边框和上边框
33 | ax.spines['right'].set_color('none')
34 | ax.spines['top'].set_color('none')
35 | # 设置x坐标轴为下边框
36 | ax.xaxis.set_ticks_position('bottom')
37 | # 设置y坐标轴为左边框
38 | ax.yaxis.set_ticks_position('left')
39 | # 设置x轴, y周在(0, 0)的位置
40 | ax.spines['bottom'].set_position(('data', 0))
41 | ax.spines['left'].set_position(('data', 0))
42 |
43 |
44 | plt.show()
--------------------------------------------------------------------------------
/PythonDemo/Matplotlib/demo6.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 添加注解和绘制点以及在图形上绘制线或点
4 | """
5 |
6 | import matplotlib.pyplot as plt
7 | import numpy as np
8 |
9 | # 绘制普通图像
10 | x = np.linspace(-3, 3, 50)
11 | y = 2 * x + 1
12 |
13 | plt.figure()
14 | plt.plot(x, y)
15 |
16 | # 将上、右边框去掉
17 | ax = plt.gca()
18 | ax.spines['right'].set_color('none')
19 | ax.spines['top'].set_color('none')
20 |
21 | # 设置x轴的位置及数据在坐标轴上的位置
22 | ax.xaxis.set_ticks_position('bottom')
23 | ax.spines['bottom'].set_position(('data', 0))
24 | # 设置y轴的位置及数据在坐标轴上的位置
25 | ax.yaxis.set_ticks_position('left')
26 | ax.spines['left'].set_position(('data', 0))
27 |
28 | # 定义(x0, y0)点
29 | x0 = 1
30 | y0 = 2 * x0 + 1
31 |
32 | # 绘制(x0, y0)点
33 | plt.scatter(x0, y0, s = 50, color = 'blue')
34 | # 绘制虚线
35 | plt.plot([x0, x0], [y0, 0], 'k--', lw = 2.5)
36 | # 绘制注解一
37 | plt.annotate(r'$2 * x + 1 = %s$' % y0, xy = (x0, y0), xycoords = 'data', xytext = (+30, -30), \
38 | textcoords = 'offset points', fontsize = 16, arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3, rad = .2'))
39 |
40 | # 绘制注解二
41 | plt.text(-3, 3, r'$Test\ text. \mu \sigma_i, \alpha_i$', fontdict = {'size': 16, 'color': 'red'})
42 | plt.show()
--------------------------------------------------------------------------------
/PythonSpider/openvcDemo2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue May 22 16:12:39 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | import cv2
9 | filepath = "D:\\picture\\318394.jpg"
10 | img = cv2.imread(filepath) # 读取图片
11 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 转换灰色
12 | # OpenCV人脸识别分类器
13 | classifier = cv2.CascadeClassifier( "D:\openvc\haarcascade_frontalface_default.xml" )
14 | color = (0, 255, 0) # 定义绘制颜色
15 | # 调用识别人脸
16 | faceRects = classifier.detectMultiScale( gray, scaleFactor=1.2, minNeighbors=3, minSize=(32, 32))
17 | if len(faceRects): # 大于0则检测到人脸
18 | for faceRect in faceRects: # 单独框出每一张人脸
19 | x, y, w, h = faceRect
20 | # 框出人脸
21 | cv2.rectangle(img, (x, y), (x + h, y + w), color, 2)
22 | # 左眼
23 | cv2.circle(img, (x + w // 4, y + h // 4 + 30), min(w // 8, h // 8), color)
24 | #右眼
25 | cv2.circle(img, (x + 3 * w // 4, y + h // 4 + 30), min(w // 8, h // 8), color)
26 | #嘴巴
27 | cv2.rectangle(img, (x + 3 * w // 8, y + 3 * h // 4), (x + 5 * w // 8, y + 7 * h // 8), color)
28 | cv2.imshow("image", img) # 显示图像
29 | c = cv2.waitKey(10)
30 | cv2.waitKey(0)
31 | cv2.destroyAllWindows()
32 |
--------------------------------------------------------------------------------
/PythonSpider/openvc_camera4.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed May 23 12:12:53 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | import cv2
9 | import os
10 | import numpy as np
11 | from PIL import Image
12 |
13 | # recognizer = cv2.createLBPHFaceRecognizer()
14 | detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
15 | recognizer = cv2.face.LBPHFaceRecognizer_create()
16 |
17 |
18 | def get_images_and_labels(path):
19 | image_paths = [os.path.join(path, f) for f in os.listdir(path)]
20 | face_samples = []
21 | ids = []
22 |
23 | for image_path in image_paths:
24 | image = Image.open(image_path).convert('L')
25 | image_np = np.array(image, 'uint8')
26 | if os.path.split(image_path)[-1].split(".")[-1] != 'jpg':
27 | continue
28 | image_id = int(os.path.split(image_path)[-1].split(".")[1])
29 | faces = detector.detectMultiScale(image_np)
30 | for (x, y, w, h) in faces:
31 | face_samples.append(image_np[y:y + h, x:x + w])
32 | ids.append(image_id)
33 |
34 | return face_samples, ids
35 |
36 |
37 | faces, Ids = get_images_and_labels("D:\\picture\\face")
38 | recognizer.train(faces, np.array(Ids))
39 | recognizer.save("trainner.yml")
--------------------------------------------------------------------------------
/PythonSpider/SimpleCrawler.py:
--------------------------------------------------------------------------------
1 | import json
2 | import requests
3 | class SimpleCrawler:
4 | init_url = "https://zhuanlan.zhihu.com/api/columns/pythoneer/followers"
5 | offset = 0
6 | def crawl(self, params = None): #必须指定UA, 否则知乎服务器会判定请求不合法
7 | headers = {
8 | "Host": "zhuanlan.zhihu.com",
9 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
10 | "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36",
11 | }
12 | response = requests.get(self.init_url, headers = headers, params = params)
13 | print(response.url)
14 | data = response.json()# 7000 表示所有关注量# 分页加载更多, 递归调用
15 | while self.offset < 7000:
16 | self.parse(data)
17 | self.offset += 20
18 | params = {
19 | "limit": 20,
20 | "offset": self.offset
21 | }
22 | self.crawl(params)
23 | def parse(self, data):
24 | #以json格式存储到文件
25 | with open("followers.json", "a", encoding = "utf-8") as f:
26 | for item in data:
27 | f.write(json.dumps(item))
28 | f.write('\n')
29 | if __name__ == '__main__':
30 | SimpleCrawler().crawl();
--------------------------------------------------------------------------------
/PythonSpider/selenium/xiaomiShequ.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Sat Mar 17 17:06:02 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | ## 引入WebDriver的包
9 | from selenium import webdriver
10 | from bs4 import BeautifulSoup
11 | ## 创建浏览器对象
12 | browser = webdriver.Firefox()
13 | ## 打开小米社区网站
14 | browser.get('https://account.xiaomi.com/pass/serviceLogin?callback=http%3A%2F%2Fbbs.xiaomi.cn%2Flogin%2Fcallback%3Ffollowup%3Dhttp%253A%252F%252Fbbs.xiaomi.cn%252F%26sign%3DM2E4MTg3MzE3MGJmZGFiMTc0MTE5NmNjZTAyYWNmMDZhNTEwOTU2NQ%2C%2C&sid=new_bbs_xiaomi_cn&_locale=zh_CN')
15 | browser.find_element_by_xpath("//*[@id='username']").clear()#清空输入框
16 | browser.find_element_by_xpath("//*[@id='username']").send_keys("18163138155")#输入账号
17 | browser.find_element_by_xpath("//*[@id='pwd']").clear()#清空输入框
18 | browser.find_element_by_xpath("//*[@id='pwd']").send_keys("ks1996721kr")#输入密码
19 | browser.find_element_by_xpath("//*[@id='login-button']").click()#登录
20 | base_url="http://bbs.xiaomi.cn/d-{page}"
21 | for i in range(1,6):
22 | url=base_url.format(page=i)
23 | browser.get(url)
24 | bs4=BeautifulSoup(browser.page_source,'lxml')
25 | titles=bs4.find_all('div', {'class':'title'})
26 | for title in titles:
27 | title_content=title.get_text().strip('\n')
28 | print(title_content)
29 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/frequency.py:
--------------------------------------------------------------------------------
1 |
2 | import multidict as multidict
3 | import numpy as np
4 | import re
5 | from PIL import Image
6 | from os import path
7 | from wordcloud import WordCloud
8 | import matplotlib.pyplot as plt
9 |
10 | def getFrequencyDictForText(sentence):
11 | fullTermsDict = multidict.MultiDict()
12 | tmpDict = {}
13 |
14 | # making dict for counting frequencies
15 | for text in sentence.split(" "):
16 | if re.match("a|the|an|the|to|in|for|of|or|by|with|is|on|that|be",text):
17 | continue
18 | val = tmpDict.get(text,0)
19 | tmpDict[text.lower()] = val+1
20 | for key in tmpDict:
21 | fullTermsDict.add(key,tmpDict[key])
22 | return fullTermsDict
23 |
24 |
25 |
26 | def makeImage(text):
27 | alice_mask = np.array(Image.open("alice_mask.png"))
28 |
29 | #background_color:设置图片背景色;max_words:设置图片能容纳的最大词数;mask:设置词云样式
30 | wc = WordCloud(background_color="white", max_words=1000, mask=alice_mask)
31 | # 生成词云
32 | wc.generate_from_frequencies(text)
33 |
34 | # 展示
35 | plt.imshow(wc, interpolation="bilinear")
36 | plt.axis("off")
37 | plt.show()
38 |
39 | d = path.dirname(__file__)
40 |
41 | text = open(path.join(d, 'alice.txt'),encoding='utf-8')
42 | text = text.read()
43 | makeImage(getFrequencyDictForText(text))
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/colored.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | Image-colored wordcloud
4 | =======================
5 | 您可以在ImageColorGenerator中实现使用基于图像的着色策略对文字云进行着色,它使用由源图像中的单词占用的区域的平均颜色。
6 |
7 | """
8 |
9 | from os import path
10 | from PIL import Image
11 | import numpy as np
12 | import matplotlib.pyplot as plt
13 |
14 | from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
15 |
16 | d = path.dirname(__file__)
17 |
18 | # 读取整个文本
19 | text = open(path.join(d, 'alice.txt')).read()
20 |
21 | # 读取蒙板/彩色图像(图片是从http://jirkavinse.deviantart.com/art/quot-Real-Life-quot-Alice-282261010下载的)
22 | alice_coloring = np.array(Image.open(path.join(d, "alice_color.png")))
23 | stopwords = set(STOPWORDS)
24 | stopwords.add("said")
25 |
26 | wc = WordCloud(background_color="white", max_words=2000, mask=alice_coloring,
27 | stopwords=stopwords, max_font_size=40, random_state=42)
28 | # 生成词云
29 | wc.generate(text)
30 |
31 | # 从图像创建着色
32 | image_colors = ImageColorGenerator(alice_coloring)
33 |
34 | # 显示
35 | plt.imshow(wc, interpolation="bilinear")
36 | plt.axis("off") #不显示坐标尺寸
37 | plt.figure()
38 | # 重新着色词云并显示
39 | # 我们也可以直接在构造函数中给使用:color_func=image_colors
40 | plt.imshow(wc.recolor(color_func=image_colors), interpolation="bilinear")
41 | plt.axis("off") #不显示坐标尺寸
42 | plt.figure()
43 | plt.imshow(alice_coloring, cmap=plt.cm.gray, interpolation="bilinear")
44 | plt.axis("off") #不显示坐标尺寸
45 | plt.show()#一次绘制三张图
46 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | env/
12 | build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *,cover
47 | .hypothesis/
48 |
49 | # Translations
50 | *.mo
51 | *.pot
52 |
53 | # Django stuff:
54 | *.log
55 | local_settings.py
56 |
57 | # Flask stuff:
58 | instance/
59 | .webassets-cache
60 |
61 | # Scrapy stuff:
62 | .scrapy
63 |
64 | # Sphinx documentation
65 | docs/_build/
66 |
67 | # PyBuilder
68 | target/
69 |
70 | # Jupyter Notebook
71 | .ipynb_checkpoints
72 |
73 | # pyenv
74 | .python-version
75 |
76 | # celery beat schedule file
77 | celerybeat-schedule
78 |
79 | # dotenv
80 | .env
81 |
82 | # virtualenv
83 | .venv/
84 | venv/
85 | ENV/
86 |
87 | # Spyder project settings
88 | .spyderproject
89 |
90 | # Rope project settings
91 | .ropeproject
92 |
--------------------------------------------------------------------------------
/PythonSpider/spider/bs4quickstart.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 20:17:37 2018
4 |
5 | @author: Administrator
6 | @description: BeautifulSoup快速开始案例
7 | """
8 | html_doc = """
9 |
The Dormouse's story
10 |
11 | The Dormouse's story
12 |
13 | Once upon a time there were three little sisters; and their names were
14 | Elsie,
15 | Lacie and
16 | Tillie;
17 | and they lived at the bottom of a well.
18 |
19 | ...
20 | """
21 | from bs4 import BeautifulSoup
22 | import re
23 | soup = BeautifulSoup(html_doc,"lxml")
24 | print("从文档中找到所有标签的链接:")
25 | for link in soup.find_all('a'):
26 | print(link.get('href'))
27 | print("正则表达式匹配:")
28 | link_node=soup.find('a',href=re.compile(r"illi"))
29 | print("标签名:",link_node.name)
30 | print("链接属性:",link_node.get('href'))
31 | print("标签文字:",link_node.text)
32 | print("根据class获取相应段落文字:")
33 | p_node=soup.find('p' ,"story")
34 | print(p_node.get_text())
35 | print(soup.title)#The Dormouse's story
36 | print(soup.title.name)#title
37 | print(soup.title.parent.name)#head
38 | print(soup.title.string)#The Dormouse's story
39 | print(soup.title.text)#The Dormouse's story
40 | #print(soup.get_text())#从文档中获取所有文字内容:
--------------------------------------------------------------------------------
/PythonSpider/spider/bs4WangYiYun.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 12:53:20 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | # 爬取网易云音乐的爬虫
9 | # -*- coding: utf-8 -*-
10 | from bs4 import BeautifulSoup
11 | import urllib.request
12 | import urllib
13 |
14 | #获取网页
15 | def gethtml(url, headers={}):
16 | req = urllib.request.Request(url, headers=headers)
17 | response = urllib.request.urlopen(req)
18 | content = response.read().decode('utf-8')
19 | response.close()
20 | return content
21 |
22 | #解析音乐列表网页
23 | def parsehtmlMusicList(html):
24 | soup = BeautifulSoup(html, 'lxml')
25 | list_pic = soup.select('ul#m-pl-container li div img')
26 | list_nameUrl = soup.select('ul#m-pl-container li div a.msk')
27 | list_num = soup.select('div.bottom span.nb')
28 | list_author = soup.select('ul#m-pl-container li p a')
29 | n = 0
30 | length = len(list_pic)
31 | while n < length:
32 | print('歌单图片:'+list_pic[n]['src']+'\n\n')
33 | print('歌单名称:'+list_nameUrl[n]['title']+'\n\n歌单地址:'+list_nameUrl[n]['href']+'\n\n')
34 | print('歌单播放量:'+list_num[n].text+'\n\n')
35 | print('歌单作者:'+list_author[n]['title']+'\n\n作者主页:'+list_author[n]['href']+'\n\n\n')
36 | n += 1
37 |
38 |
39 | url = 'http://music.163.com/discover/playlist'
40 | url = gethtml(url, headers={
41 | 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
42 | 'Host': 'music.163.com'
43 | })
44 | parsehtmlMusicList(url)
--------------------------------------------------------------------------------
/PythonDemo/saveToExcel/xlwtDemo.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 14:40:09 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | import xlwt
9 |
10 |
11 | def set_style(name, height, bold = False):
12 | style = xlwt.XFStyle() #初始化样式
13 |
14 | font = xlwt.Font() #为样式创建字体
15 | font.name = name
16 | font.bold = bold
17 | font.color_index = 4
18 | font.height = height
19 |
20 | style.font = font
21 | return style
22 |
23 |
24 | def write_excel():
25 | #创建工作簿
26 | workbook = xlwt.Workbook(encoding='utf-8')
27 | #创建sheet
28 | data_sheet = workbook.add_sheet('demo')
29 | row0 = [u'歌单介绍', u'歌曲链接地址', '歌曲播放次数', '收藏次数','评论次数']
30 | row1 = [u'测试', '15:50:33-15:52:14', '22706', 4190202,'sss']
31 | data_sheet.col(0).width = 9999#设置单元格宽度
32 | data_sheet.col(1).width = 9999#设置单元格宽度
33 | data_sheet.col(2).width = 4444#设置单元格宽度
34 | data_sheet.col(3).width = 3333#设置单元格宽度
35 | data_sheet.col(4).width = 3333#设置单元格宽度
36 | #生成第一行和第二行
37 | for i in range(len(row0)):
38 | data_sheet.write(0, i, row0[i], set_style('Times New Roman', 220, True))
39 | data_sheet.write(1, i, row1[i], set_style('Times New Roman', 220, True))
40 |
41 | #保存文件
42 | workbook.save('C:/Users/Administrator/Desktop/xlwtDemo.xls')
43 |
44 |
45 | if __name__ == '__main__':
46 | write_excel()
47 | print (u'创建demo.xlsx文件成功' )
--------------------------------------------------------------------------------
/PythonSpider/openvc_camera5.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Wed May 23 12:28:46 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | import cv2
9 |
10 |
11 | recognizer = cv2.face.LBPHFaceRecognizer_create()
12 | # recognizer = cv2.createLBPHFaceRecognizer() # in OpenCV 2
13 | recognizer.read("trainner.yml")
14 | # recognizer.load('trainner/trainner.yml') # in OpenCV 2
15 |
16 | cascade_path = "haarcascade_frontalface_default.xml"
17 | face_cascade = cv2.CascadeClassifier(cascade_path)
18 | cam = cv2.VideoCapture(0)
19 | # font = cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 1, 1) # in OpenCV 2
20 | font = cv2.FONT_HERSHEY_SIMPLEX
21 |
22 | while True:
23 | ret, im = cam.read()
24 | gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
25 | faces = face_cascade.detectMultiScale(gray, 1.2, 5)
26 | for (x, y, w, h) in faces:
27 | cv2.rectangle(im, (x - 50, y - 50), (x + w + 50, y + h + 50), (225, 0, 0), 2)
28 | img_id, conf = recognizer.predict(gray[y:y + h, x:x + w])
29 | if conf > 50:
30 | if img_id == 1:
31 | img_id = 'jianyujianyu'
32 | elif img_id == 2:
33 | img_id = 'ghost'
34 | else:
35 | img_id = "Unknown"
36 | # cv2.cv.PutText(cv2.cv.fromarray(im), str(Id), (x, y + h), font, 255)
37 | cv2.putText(im, str(img_id), (x, y + h), font, 0.55, (0, 255, 0), 1)
38 | cv2.imshow('im', im)
39 | if cv2.waitKey(10) & 0xFF == ord('q'):
40 | break
41 |
42 | cam.release()
43 | cv2.destroyAllWindows()
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/a_new_hope.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | 使用自定义颜色
4 | ===================
5 |
6 | 使用重新着色方法和自定义着色功能。
7 | """
8 |
9 | import numpy as np
10 | from PIL import Image
11 | from os import path
12 | import matplotlib.pyplot as plt
13 | import random
14 |
15 | from wordcloud import WordCloud, STOPWORDS
16 |
17 |
18 | def grey_color_func(word, font_size, position, orientation, random_state=None,
19 | **kwargs):
20 | return "hsl(0, 0%%, %d%%)" % random.randint(60, 100)
21 |
22 | d = path.dirname(__file__)
23 |
24 | # 读取图片(图片来源:http://www.stencilry.org/stencils/movies/star%20wars/storm-trooper.gif)
25 | mask = np.array(Image.open(path.join(d, "stormtrooper_mask.png")))
26 |
27 | # 文字来源:“新希望”电影剧本(网址:http://www.imsdb.com/scripts/Star-Wars-A-New-Hope.html)
28 | text = open(path.join(d, 'a_new_hope.txt')).read()
29 |
30 | # 预处理一点点文本
31 | text = text.replace("HAN", "Han")
32 | text = text.replace("LUKE'S", "Luke")
33 |
34 | # 添加电影剧本特定的停用词
35 | stopwords = set(STOPWORDS)
36 | stopwords.add("int")
37 | stopwords.add("ext")
38 |
39 | wc = WordCloud(max_words=1000, mask=mask, stopwords=stopwords, margin=10,
40 | random_state=1).generate(text)
41 | # 存储默认的彩色图像
42 | default_colors = wc.to_array()
43 | plt.title("Custom colors")
44 | plt.imshow(wc.recolor(color_func=grey_color_func, random_state=3),
45 | interpolation="bilinear")
46 | wc.to_file("a_new_hope.png")
47 | plt.axis("off")
48 | plt.figure()
49 | plt.title("Default colors")
50 | plt.imshow(default_colors, interpolation="bilinear")
51 | plt.axis("off")
52 | plt.show()
53 |
--------------------------------------------------------------------------------
/PythonDemo/SnowNLP/demo1.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Fri Mar 16 09:01:24 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | from snownlp import SnowNLP
9 |
10 | s = SnowNLP(u'这个东西真心很赞')
11 |
12 | #分词
13 | s.words # [u'这个', u'东西', u'真心',
14 | # u'很', u'赞']
15 | #词性标注
16 | s.tags # [(u'这个', u'r'), (u'东西', u'n'),
17 | # (u'真心', u'd'), (u'很', u'd'),
18 | # (u'赞', u'Vg')]
19 | #情绪判断
20 | #返回值为正面情绪的概率,
21 | #越接近1表示正面情绪
22 | #越接近0表示负面情绪
23 | s.sentiments # 0.9769663402895832 positive的概率
24 |
25 | #返回文本拼音
26 | s.pinyin # [u'zhe', u'ge', u'dong', u'xi',
27 | # u'zhen', u'xin', u'hen', u'zan']
28 |
29 | #繁体转简体
30 | s = SnowNLP(u'「繁體字」「繁體中文」的叫法在臺灣亦很常見。')
31 |
32 | s.han # u'「繁体字」「繁体中文」的叫法
33 | # 在台湾亦很常见。'
34 |
35 | text = u'''
36 | 自然语言处理是计算机科学领域与人工智能领域中的一个重要方向。
37 | 它研究能实现人与计算机之间用自然语言进行有效通信的各种理论和方法。
38 | 自然语言处理是一门融语言学、计算机科学、数学于一体的科学。
39 | 因此,这一领域的研究将涉及自然语言,即人们日常使用的语言,
40 | 所以它与语言学的研究有着密切的联系,但又有重要的区别。
41 | 自然语言处理并不是一般地研究自然语言,
42 | 而在于研制能有效地实现自然语言通信的计算机系统,
43 | 特别是其中的软件系统。因而它是计算机科学的一部分。
44 | '''
45 |
46 | s = SnowNLP(text)
47 | #关键词提取
48 | s.keywords(3) # [u'语言', u'自然', u'计算机']
49 |
50 | #文本概括
51 | s.summary(3) # [u'因而它是计算机科学的一部分',
52 | # u'自然语言处理是一门融语言学、计算机科学、
53 | # 数学于一体的科学',
54 | # u'自然语言处理是计算机科学领域与人工智能
55 | # 领域中的一个重要方向']
56 | s.sentences
57 | print(s.sentences)
58 | #评价词语对文本的重要程度
59 | s = SnowNLP([[u'这篇', u'文章'],
60 | [u'那篇', u'论文'],
61 | [u'这个']])
62 | s.tf
63 | s.idf
64 | #文本相似性
65 | s.sim([u'文章'])# [0.3756070762985226, 0, 0]
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/emoji.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | 表情实例
4 | ===============
5 | 一个简单的例子,显示如何包含表情符号。 请注意,这个例子似乎不适用于OS X(苹果系统),但是确实如此
6 | 在Ubuntu中正常工作
7 | 包含表情符号有3个重要步骤:
8 | 1) 使用io.open而不是内置的open来读取文本输入。 这确保它被加载为UTF-8
9 | 2) 重写词云使用的正则表达式以将文本解析为单词。 默认表达式只会匹配ascii的单词
10 | 3) 将默认字体覆盖为支持表情符号的东西。 包含的Symbola字体包括黑色和白色大多数表情符号的白色轮廓。 目前PIL / Pillow库存在的问题似乎可以预防
11 | 它在OS X上运行正常(https://github.com/python-pillow/Pillow/issues/1774)。
12 | 如果你有问题,试试在Ubuntu上运行
13 | """
14 | import io
15 | import string
16 | from os import path
17 | from wordcloud import WordCloud
18 |
19 | d = path.dirname(__file__)
20 |
21 | #使用io.open将文件正确加载为UTF-8非常重要
22 | text = io.open(path.join(d, 'happy-emoji.txt')).read()
23 |
24 | # the regex used to detect words is a combination of normal words, ascii art, and emojis
25 | # 2+ consecutive letters (also include apostrophes), e.x It's
26 | normal_word = r"(?:\w[\w']+)"
27 | # 2+ consecutive punctuations, e.x. :)
28 | ascii_art = r"(?:[{punctuation}][{punctuation}]+)".format(punctuation=string.punctuation)
29 | # a single character that is not alpha_numeric or other ascii printable
30 | emoji = r"(?:[^\s])(? height else height
14 | #生成新图片[白底]
15 | new_image = Image.new(image.mode, (new_image_length, new_image_length), color='white')
16 | #将之前的图粘贴在新图上,居中
17 | if width > height:#原图宽大于高,则填充图片的竖直维度
18 | new_image.paste(image, (0, int((new_image_length - height) / 2)))#(x,y)二元组表示粘贴上图相对下图的起始位置
19 | else:
20 | new_image.paste(image, (int((new_image_length - width) / 2),0))
21 | return new_image
22 |
23 | #切图
24 | def cut_image(image):
25 | width, height = image.size
26 | item_width = int(width / 3)
27 | box_list = []
28 | # (left, upper, right, lower)
29 | for i in range(0,3):
30 | for j in range(0,3):
31 | #print((i*item_width,j*item_width,(i+1)*item_width,(j+1)*item_width))
32 | box = (j*item_width,i*item_width,(j+1)*item_width,(i+1)*item_width)
33 | box_list.append(box)
34 |
35 | image_list = [image.crop(box) for box in box_list]
36 |
37 | return image_list
38 |
39 | #保存
40 | def save_images(image_list):
41 | index = 1
42 | for image in image_list:
43 | image.save('./result/python'+str(index) + '.png', 'PNG')
44 | index += 1
45 |
46 |
47 |
48 | if __name__ == '__main__':
49 | file_path = "alice_color.png"
50 | image = Image.open(file_path)
51 | #image.show()
52 | image = fill_image(image)
53 | image_list = cut_image(image)
54 | save_images(image_list)
--------------------------------------------------------------------------------
/PythonDemo/numpy/arraymethod2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 15:37:14 2018
4 |
5 | @author: Administrator
6 | """
7 | import numpy as np
8 | from numpy.matlib import randn
9 | arr = np.empty((8, 4)) #二维数组
10 | #range(8)即 [0, 1, 2, 3, 4, 5, 6, 7]
11 | for i in range(8):
12 | arr[i] = i #第i行的数字都为i;
13 |
14 | print(arr)
15 | print(arr[[4, 3, 0, 6]]) #[[ 4. 4. 4. 4.] [ 3. 3. 3. 3.] [ 0. 0. 0. 0.] [ 6. 6. 6. 6.]]
16 | arr = np.arange(32).reshape((8, 4))
17 | print("np.arange(32).reshape((8, 4)):")
18 | print(arr)
19 | print(arr[[1, 5, 7, 2], [0, 3, 1, 2]])#[ 4 23 29 10]
20 | print(" 输出矩阵转置: ")
21 | arr = np.arange(15).reshape((3, 5))
22 | print(arr.T)
23 | print("输出np.arange(10):")
24 | arr = np.arange(10)
25 | print(arr)
26 | print("输出np.sqrt(arr):")
27 | print(np.sqrt(arr)) #仍是一维数组,求数组中的每个元素求平方根
28 | print("输出np.exp(arr)):")
29 | print(np.exp(arr)) #仍是一维数组,求以e为底,数组中的每个元素作为指数的值
30 | print("randn(8):")
31 | x = randn(8) #生成8个随机数
32 | print(x)
33 | print("randn(8):")
34 | y = randn(8)
35 | print(y)
36 | print(np.maximum(x, y)) #仍是一维数组,每个元素为数组x和y对应元素最大的那个;
37 | print("-------------------------------------")
38 | xarr = np.array([1.1, 1.2, 1.3, 1.4, 1.5])
39 | yarr = np.array([2.1, 2.2, 2.3, 2.4, 2.5])
40 | cond = np.array([True, False, True, True, False])
41 | result = np.where(cond, xarr, yarr)
42 | print(result)#输出:[1.1 2.2 1.3 1.4 2.5]
43 | print("-------------------------------------")
44 | arr = randn(4, 4)
45 | print(arr)
46 | print(np.where(arr > 0, 2, -2))
47 | print("-------------------------------------")
48 | arr = np.random.randn(5, 4) # normally-distributed data
49 | print(arr)
50 | print(arr.mean())
51 | print(np.mean(arr))
52 | print(arr.sum())
53 | print(arr.mean(axis=1))
54 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/happy-emoji.txt:
--------------------------------------------------------------------------------
1 | happy happy happy happy happy happy happy happy happy happy
2 | smiley smiley smiley smiley smiley smiley smiley smiley smiley smiley
3 | happy happy happy happy happy happy happy happy happy happy
4 | smiley smiley smiley smiley smiley smiley smiley smiley smiley smiley
5 | happy happy happy happy happy happy happy happy happy happy
6 | smiley smiley smiley smiley smiley smiley smiley smiley smiley smiley
7 | 😀 😀 😀 😀 😀 😀 😀 😀 😀 😀
8 | :) :) :) :) :) :) :) :) :) :)
9 | 😀 😀 😀 😀 😀 😀 😀 😀 😀 😀
10 | :) :) :) :) :) :) :) :) :) :)
11 | 😀 😀 😀 😀 😀 😀 😀 😀 😀 😀
12 | :) :) :) :) :) :) :) :) :) :)
13 | 😀 😀 😀 😀 😀 😀 😀 😀 😀 😀
14 | :) :) :) :) :) :) :) :) :) :)
15 | 😀 😀 😀 😀 😀 😀 😀 😀 😀 😀
16 | :) :) :) :) :) :) :) :) :) :)
17 | smile smile smile smile smile smile smile smile smile smile
18 | face face face face face face face face face face face face
19 | contented, content, cheerful, cheery, merry, joyful, jovial, jolly, joking, jocular, gleeful, carefree, untroubled, delighted, smiling, beaming, grinning, glowing, satisfied, gratified, buoyant, radiant, sunny, blithe, joyous, beatific, blessed
20 | 😊
21 |
22 | 😃 Smileys & People
23 |
24 | 😀 Grinning Face
25 | 😁 Grinning Face With Smiling Eyes
26 | 😂 Face With Tears of Joy
27 | 🤣 Rolling on the Floor Laughing
28 | 😃 Smiling Face With Open Mouth
29 | 😄 Smiling Face With Open Mouth & Smiling Eyes
30 | 😅 Smiling Face With Open Mouth & Cold Sweat
31 | 😆 Smiling Face With Open Mouth & Closed Eyes
32 | 😉 Winking Face
33 | 😊 Smiling Face With Smiling Eyes
34 | 😋 Face Savouring Delicious Food
35 | 😎 Smiling Face With Sunglasses
36 | 😍 Smiling Face With Heart-eyes
37 | 😘 Face Blowing a Kiss
38 | 😗 Kissing Face
39 | 😙 Kissing Face With Smiling Eyes
40 | 😚 Kissing Face With Closed Eyes
41 | ☺️ Smiling Face
42 | 🙂 Slightly Smiling Face
43 |
--------------------------------------------------------------------------------
/PythonDemo/numpy/arraymethod.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 14:51:47 2018
4 |
5 | @author: Administrator
6 | @description: numpy库操纵数组的一些方法
7 | """
8 | import numpy as np
9 | from numpy.matlib import randn
10 | #定义数组类型
11 | arr3 = np.array([1, 2, 3], dtype=np.float64)
12 | arr4 = np.array([1, 2, 3], dtype=np.int32)
13 | print(arr3.dtype)#float64
14 | print(arr4.dtype)#int32
15 | #转换数组类型
16 | arr5 = np.array([1, 2, 3, 4, 5])
17 | print(arr5.dtype) #int32
18 | arr6 = arr5.astype(np.float64) #将数组5的数据类型转换为float64
19 | print(arr6.dtype) #float64
20 | #数组间以及数组与数之间的运算
21 | arr = np.array([[1., 2., 3.], [4., 5., 6.]])
22 | print(arr * arr) #相应元素相乘,输出为[[1. 4. 9.] [16. 25. 36.]]
23 | print(arr - arr) #相应元素相减,输出为[[0. 0. 0.] [0. 0. 0.]]
24 | #创建二维数组,取值,修改值
25 | arr2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
26 | print(arr2d[2]) #数组标号从0开始,输出第三行元素:[7 8 9]
27 | #创建三维数组
28 | arr3d = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) #2个二维数组
29 | old_values = arr3d[0].copy() #将第1个二维数组拷贝至old_values
30 | print(old_values) #输出:[[1 2 3], [4 5 6]]
31 | arr3d[0] = 3 #将第1个二维数组的元素都修改为3
32 | arr3d[1] = 3 #将第2个二维数组的元素都修改为3
33 | print(arr3d) #输出全为3的三维数组
34 | arr3d[0] = old_values
35 | print(arr3d) # 输出 [[[1 2 3] [4 5 6]] [[3 3 3] [3 3 3]] ]
36 |
37 | names = np.array(['Bob', 'Joe', 'Will', 'Bob', 'Will', 'Joe', 'Joe'])
38 | print("输出names数组:")
39 | print(names)
40 | print("输出randn(7, 4)生成的7行4列的随机数函数")
41 | data = randn(7, 4)
42 | print(data)
43 | print("判断names数组中的每一个元素是否等于Bob:")
44 | print(names == 'Bob') #, 输出 [True False False True FalseFalse False]
45 | print("data[names == 'Bob']输出data中判断为true的行元素:")
46 | print(data[names == 'Bob'])
47 | print("data[names == 'Bob', 2:]输出data中判断为true所在的行,及第3列第4列的所有元素:")
48 | print(data[names == 'Bob', 2:],) #输出data中判断为true所在的行,及第3列第4列的所有元素;
49 | print("data[names == 'Bob', 3]输出data中判断为true所在的行及第4列的元素 :")
50 | print(data[names == 'Bob', 3])
51 | print("输出名字为Bob以及Will所在的行元素 :")
52 | print(data[((names == 'Bob') | (names == 'Will'))]) #输出名字为Bob以及Will所在的行元素
53 |
--------------------------------------------------------------------------------
/PythonDemo/test.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | Created on 2018年1月21日
5 |
6 | @author: Administrator
7 | '''
8 | # drawtree.py
9 |
10 | from turtle import Turtle
11 |
12 |
13 | def tree(plist, l, a, f):
14 | """ plist is list of pens
15 | l is length of branch
16 | a is half of the angle between 2 branches
17 | f is factor by which branch is shortened
18 | from level to level."""
19 | if l > 5: #
20 | lst = []
21 | for p in plist:
22 | p.forward(l) # 沿着当前的方向画画Move the turtle forward by the specified distance, in the direction the turtle is headed.
23 | q = p.clone() # Create and return a clone of the turtle with same position, heading and turtle properties.
24 | p.left(a) # Turn turtle left by angle units
25 | q.right(a) # turn turtle right by angle units, nits are by default degrees, but can be set via the degrees() and radians() functions.
26 | lst.append(p) # 将元素增加到列表的最后
27 | lst.append(q)
28 | tree(lst, l * f, a, f)
29 |
30 |
31 | def main():
32 | p = Turtle()
33 | p.color("green")
34 | p.pensize(5)
35 | # p.setundobuffer(None)
36 | p.hideturtle() # Make the turtle invisible. It’s a good idea to do this while you’re in the middle of doing some complex drawing,
37 | # because hiding the turtle speeds up the drawing observably.
38 | # p.speed(10)
39 | # p.getscreen().tracer(1,0)#Return the TurtleScreen object the turtle is drawing on.
40 | p.speed(10)
41 | # TurtleScreen methods can then be called for that object.
42 | p.left(90) # Turn turtle left by angle units. direction 调整画笔
43 |
44 | p.penup() # Pull the pen up – no drawing when moving.
45 | p.goto(0, -200) # Move turtle to an absolute position. If the pen is down, draw line. Do not change the turtle’s orientation.
46 | p.pendown() # Pull the pen down – drawing when moving. 这三条语句是一个组合相当于先把笔收起来再移动到指定位置,再把笔放下开始画
47 | # 否则turtle一移动就会自动的把线画出来
48 |
49 | # t = tree([p], 200, 65, 0.6375)
50 | t = tree([p], 200, 65, 0.6375)
51 |
52 |
53 | main()
54 |
--------------------------------------------------------------------------------
/PythonSpider/.spyproject/workspace.ini:
--------------------------------------------------------------------------------
1 | [workspace]
2 | restore_data_on_startup = True
3 | save_data_on_exit = True
4 | save_history = True
5 | save_non_project_files = False
6 |
7 | [main]
8 | version = 0.1.0
9 | recent_files = ['C:\\Users\\Administrator\\.spyder-py3\\temp.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\SimpleCrawler.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\followers.json', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\bs4quickstart.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\urllib.requestDemo1.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\bs4WangYiYunToExcel2.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\bs4WangYiYunToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\bs4WangYiYun.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\bs4Meizitu.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\bs4JokeToExcel.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\requestsTuicool.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\requestsTuicool2.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\urllib.requestTuicool.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\spider\\urllib.requestTuicool2.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\selenium\\firstDemo.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\selenium\\geckodriver.log', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\selenium\\xiaomiShequ.py', 'D:\\Anaconda3\\lib\\site-packages\\selenium\\webdriver\\__init__.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\selenium\\csdn.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\selenium\\zhihu.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\weixin\\crawler.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvcDemo1.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvcDemo2.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvc_camera.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvc_camera2.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvc_camera3.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\haarcascade_frontalface_default.xml', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvc_camera4.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvc_camera5.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvc_video.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\openvc_video2.py']
10 |
11 |
--------------------------------------------------------------------------------
/PythonDemo/weixin/weixinQianming.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | 朋友圈朋友签名的词云生成以及
4 | 签名情感分析
5 | """
6 | import re,jieba,itchat
7 | import jieba.analyse
8 | import numpy as np
9 | from PIL import Image
10 | from snownlp import SnowNLP
11 | from wordcloud import WordCloud
12 | import matplotlib.pyplot as plt
13 | itchat.auto_login(hotReload=True)
14 | friends = itchat.get_friends(update=True)
15 | def analyseSignature(friends):
16 | signatures = ''
17 | emotions = []
18 | for friend in friends:
19 | signature = friend['Signature']
20 | if(signature != None):
21 | signature = signature.strip().replace('span', '').replace('class', '').replace('emoji', '')
22 | signature = re.sub(r'1f(\d.+)','',signature)
23 | if(len(signature)>0):
24 | nlp = SnowNLP(signature)
25 | emotions.append(nlp.sentiments)
26 | signatures += ' '.join(jieba.analyse.extract_tags(signature,5))
27 | with open('signatures.txt','wt',encoding='utf-8') as file:
28 | file.write(signatures)
29 |
30 | # 朋友圈朋友签名的词云相关属性设置
31 | back_coloring = np.array(Image.open('alice_color.png'))
32 | wordcloud = WordCloud(
33 | font_path='simfang.ttf',
34 | background_color="white",
35 | max_words=1200,
36 | mask=back_coloring,
37 | max_font_size=75,
38 | random_state=45,
39 | width=1250,
40 | height=1000,
41 | margin=15
42 | )
43 |
44 | #生成朋友圈朋友签名的词云
45 | wordcloud.generate(signatures)
46 | plt.imshow(wordcloud)
47 | plt.axis("off")
48 | plt.show()
49 | wordcloud.to_file('signatures.jpg')#保存到本地文件
50 |
51 | # Signature Emotional Judgment
52 | count_good = len(list(filter(lambda x:x>0.66,emotions)))#正面积极
53 | count_normal = len(list(filter(lambda x:x>=0.33 and x<=0.66,emotions)))#中性
54 | count_bad = len(list(filter(lambda x:x<0.33,emotions)))#负面消极
55 | labels = [u'负面消极',u'中性',u'正面积极']
56 | values = (count_bad,count_normal,count_good)
57 | plt.rcParams['font.sans-serif'] = ['simHei']
58 | plt.rcParams['axes.unicode_minus'] = False
59 | plt.xlabel(u'情感判断')#x轴
60 | plt.ylabel(u'频数')#y轴
61 | plt.xticks(range(3),labels)
62 | plt.legend(loc='upper right',)
63 | plt.bar(range(3), values, color = 'rgb')
64 | plt.title(u'%s的微信好友签名信息情感分析' % friends[0]['NickName'])
65 | plt.show()
66 | analyseSignature(friends)
--------------------------------------------------------------------------------
/PythonSpider/spider/bs4Meizitu.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Mon Mar 12 22:20:22 2018
4 |
5 | @author: Administrator
6 | @description: BeautifulSoup抓取美女图片
7 | """
8 |
9 | import requests
10 | from bs4 import BeautifulSoup
11 | import os,re
12 | #导入所需要的模块
13 | class mzitu():
14 | def all_url(self, url):
15 | html = self.request(url)##
16 | all_a = BeautifulSoup(html.text, 'lxml').find('div', class_='all').find_all('a', href=re.compile('[0~9]'))
17 | for a in all_a:
18 | title = a.get_text()
19 | print('------开始保存:', title)
20 | path = str(title).replace("?", '_') ##替换掉带有的?
21 | self.mkdir(path) ##调用mkdir函数创建文件夹!这儿path代表的是标题title
22 | href = a['href']
23 | self.html(href)
24 |
25 | def html(self, href): ##获得图片的页面地址并保存图片
26 | html = self.request(href)
27 | max_span = BeautifulSoup(html.text, 'lxml').find('div', class_='pagenavi').find_all('span')[-2].get_text()
28 | #这个上面有提到
29 | for page in range(1, int(max_span) + 1):
30 | page_url = href + '/' + str(page)
31 | self.img(page_url) ##调用img函数
32 |
33 | def img(self, page_url): ##处理图片页面地址获得图片的实际地址
34 | img_html = self.request(page_url)
35 | img_url = BeautifulSoup(img_html.text, 'lxml').find('div', class_='main-image').find('img')['src']
36 | self.save(img_url)
37 |
38 | def save(self, img_url): ##保存图片
39 | name = img_url[-9:-4]
40 | img = self.request(img_url)
41 | f = open(name + '.jpg', 'ab')
42 | f.write(img.content)
43 | f.close()
44 |
45 | def mkdir(self, path): ##创建文件夹
46 | path = path.strip()
47 | isExists = os.path.exists(os.path.join("E:\mzitu2", path))
48 | if not isExists:
49 | print('建了一个名字叫做', path, '的文件夹!')
50 | os.makedirs(os.path.join("E:\mzitu2", path))
51 | os.chdir(os.path.join("E:\mzitu2", path)) ##切换到目录
52 | return True
53 | else:
54 | print( path, '文件夹已经存在了!')
55 | return False
56 |
57 | def request(self, url): ##这个函数获取网页的response 然后返回
58 | headers = {
59 | 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36',
60 | 'referer': "http://www.mzitu.com/100260/2" #伪造一个访问来源
61 | }
62 | content = requests.get(url, headers=headers)
63 | return content
64 | #设置启动函数
65 | def main():
66 | Mzitu = mzitu() ##实例化
67 | Mzitu.all_url('http://www.mzitu.com/all') ##给函数all_url传入参数
68 |
69 | main()
--------------------------------------------------------------------------------
/PythonSpider/spider/bs4JokeToExcel.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 12:58:54 2018
4 | http://blog.csdn.net/weixin_39198406/article/details/73332565
5 | @author: Administrator
6 | """
7 |
8 | #抓取糗事百科笑话的脚本
9 | import urllib.request
10 | from bs4 import BeautifulSoup
11 | import xlwt #写入文件
12 | import time
13 |
14 | #返回文本式的html
15 | def getHTML(url):
16 | #给头文件伪装成浏览器访问
17 | headers = {'User-Agent': 'User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'}
18 | req = urllib.request.Request(url, headers=headers)
19 | return urllib.request.urlopen(req).read()
20 |
21 | #返回一个bs4_url对象
22 | def creatSoup(url):
23 | html_text = getHTML(url)
24 | soup_0 = BeautifulSoup(html_text,'html5lib')
25 | return soup_0
26 |
27 | #新建Excel文件和其中的一个sheet,注意传的参数是字符串格式,新建完在空间中打开,直接使用write写入数据
28 | def creatExcelAndSheet(sheetName):
29 | #新建一个excel文件
30 | file = xlwt.Workbook(encoding = 'utf-8', style_compression = 0)
31 | #新建一个sheet
32 | sheet = file.add_sheet(sheetName)
33 | #返回打开的sheet对象
34 | return sheet,file
35 |
36 | #执行写入Excel的程序。参数含义 a-选择写入行,b-选择写入列,c-选择写入的内容(字符串类型)
37 | def writeToSheet(a,b,c):
38 | sheet.write(a,b,c)
39 |
40 | #抓取结束的提示信息,分别是页循环次数和内容循环次数,由于结束之前页和内容循环数还会+1.所以summary要-1
41 | def summaryAllContent(a,b,url):
42 | print('提示:抓取结束,无更多内容!')
43 | print('------------------Summary------------------')
44 | print('您抓取的网址为%s'%url)
45 | print('共抓取 %d页 共 %d个内容'%(a-1,b-1))
46 | print('-------------------------------------------')
47 |
48 | #得到每一条内容的处理函数,根据不同的html需要修改
49 | def getEachContent(eachContent):
50 | a = eachContent.select('div')[0]
51 | b = a.select('span')[0]
52 | sss = ''
53 | for s in b.strings:
54 | sss+=s
55 | return sss
56 |
57 | sheet,file = creatExcelAndSheet('data')
58 |
59 | i = 1
60 | k = 1
61 | while i <2:
62 |
63 | # url = 'https://www.qiushibaike.com/8hr/page/1/?s=4991834' 根据url多页的特性,找到翻页的一个参数
64 | url = 'https://www.qiushibaike.com/8hr/page/' + str(i) + '/?s=4991834'
65 | soup = creatSoup(url)
66 | a_soup = soup.select('a[class=contentHerf]') #根据关键字取得按list存放的内容
67 | contentLen = len(a_soup) #取得列表长度
68 | print('Info: 第%d页有%d个笑话'%(i,contentLen))
69 |
70 | for eachContent in a_soup:
71 | sss = getEachContent(eachContent)
72 | writeToSheet(k,0,k)
73 | writeToSheet(k,1,sss)
74 | print('正在获取第%d个内容...Done'%k)
75 | time.sleep(0.05)
76 | k+=1
77 |
78 | print('提示: 正在获取下一页内容...')
79 | i += 1
80 | time.sleep(3)
81 |
82 | summaryAllContent(i,k,url)
83 | file.save('C:/Users/Administrator/Desktop/糗事百科Data.xls') #这里写要保存的路径
--------------------------------------------------------------------------------
/PythonSpider/spider/bs4WangYiYunToExcel.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 15:11:32 2018
4 |
5 | @author: Snailclimb
6 | @description 爬取网易云音乐歌单(这里只爬取了一页)
7 | """
8 |
9 | from bs4 import BeautifulSoup
10 | import urllib.request
11 | import urllib
12 | import xlwt
13 |
14 | #获取网页
15 | def gethtml(url, headers={}):
16 | req = urllib.request.Request(url, headers=headers)
17 | response = urllib.request.urlopen(req)
18 | content = response.read().decode('utf-8')
19 | response.close()
20 | return content
21 | def set_style(name, height, bold = False):
22 | style = xlwt.XFStyle() #初始化样式
23 |
24 | font = xlwt.Font() #为样式创建字体
25 | font.name = name
26 | font.bold = bold
27 | font.color_index = 4
28 | font.height = height
29 |
30 | style.font = font
31 | return style
32 |
33 | #解析音乐列表网页
34 | def parsehtmlMusicList(html):
35 | soup = BeautifulSoup(html, 'lxml')
36 | list_pic = soup.select('ul#m-pl-container li div img')
37 | list_nameUrl = soup.select('ul#m-pl-container li div a.msk')
38 | list_num = soup.select('div.bottom span.nb')
39 | list_author = soup.select('ul#m-pl-container li p a')
40 | n = 0
41 | length = len(list_pic)
42 | #创建工作簿
43 | workbook = xlwt.Workbook(encoding='utf-8')
44 | #创建sheet
45 | data_sheet = workbook.add_sheet('demo')
46 | row0 = [u'歌单介绍', u'歌曲链接地址', u'歌曲播放次数', u'歌单作者']
47 | data_sheet.col(0).width = 9999#设置单元格宽度
48 | data_sheet.col(1).width = 9999#设置单元格宽度
49 | data_sheet.col(2).width = 4444#设置单元格宽度
50 | data_sheet.col(3).width = 3333#设置单元格宽度
51 | data_sheet.col(4).width = 3333#设置单元格宽度
52 | #生成第一行和第二行
53 | for i in range(len(row0)):
54 | data_sheet.write(0, i, row0[i], set_style('Times New Roman', 220, True))
55 | while n < length:
56 | description=list_nameUrl[n]['title']#歌单介绍
57 | songhref= list_nameUrl[n]['href']
58 | num=list_num[n].text#歌曲播放量
59 | #picture=list_pic[n]['src']#图片链接地址
60 | author=list_author[n]['title']#歌单作者
61 | row=[description, songhref, num, author]
62 | #print('歌单图片:'+list_pic[n]['src']+'\n\n')
63 | #print('歌单名称:'+list_nameUrl[n]['title']+'\n\n歌单地址:'+list_nameUrl[n]['href']+'\n\n')
64 | #print('歌单播放量:'+list_num[n].text+'\n\n')
65 | #print('歌单作者:'+list_author[n]['title']+'\n\n作者主页:'+list_author[n]['href']+'\n\n\n')
66 | n += 1
67 | for i in range(len(row)):
68 | data_sheet.write(n, i, row[i], set_style('Times New Roman', 220, True))
69 | workbook.save('C:/Users/Administrator/Desktop/xlwtDemo.xls')
70 | url = 'http://music.163.com/discover/playlist'
71 | url = gethtml(url, headers={
72 | 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
73 | 'Host': 'music.163.com'
74 | })
75 | parsehtmlMusicList(url)
76 |
77 |
78 |
--------------------------------------------------------------------------------
/PythonSpider/spider/bs4WangYiYunToExcel2.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 15:11:32 2018
4 |
5 | @author: Administrator
6 | """
7 |
8 | from bs4 import BeautifulSoup
9 | import urllib.request
10 | import urllib
11 | import xlwt
12 |
13 | #获取网页
14 | def gethtml(url, headers={}):
15 | req = urllib.request.Request(url, headers=headers)
16 | response = urllib.request.urlopen(req)
17 | content = response.read().decode('utf-8')
18 | response.close()
19 | return content
20 | def set_style(name, height, bold = False):
21 | style = xlwt.XFStyle() #初始化样式
22 |
23 | font = xlwt.Font() #为样式创建字体
24 | font.name = name
25 | font.bold = bold
26 | font.color_index = 4
27 | font.height = height
28 |
29 | style.font = font
30 | return style
31 |
32 | #解析音乐列表网页
33 | def parsehtmlMusicList(html):
34 | soup = BeautifulSoup(html, 'lxml')
35 | list_pic = soup.select('ul#m-pl-container li div img')
36 | list_nameUrl = soup.select('ul#m-pl-container li div a.msk')
37 | list_num = soup.select('div.bottom span.nb')
38 | list_author = soup.select('ul#m-pl-container li p a')
39 | n = 0
40 | length = len(list_pic)
41 | #创建工作簿
42 | workbook = xlwt.Workbook(encoding='utf-8')
43 | #创建sheet
44 | data_sheet = workbook.add_sheet('demo')
45 | row0 = [u'歌单介绍', u'歌曲链接地址', u'歌曲播放次数', u'歌单作者']
46 | data_sheet.col(0).width = 9999#设置单元格宽度
47 | data_sheet.col(1).width = 9999#设置单元格宽度
48 | data_sheet.col(2).width = 4444#设置单元格宽度
49 | data_sheet.col(3).width = 3333#设置单元格宽度
50 | data_sheet.col(4).width = 3333#设置单元格宽度
51 | #生成第一行和第二行
52 | for i in range(len(row0)):
53 | data_sheet.write(0, i, row0[i], set_style('Times New Roman', 220, True))
54 | while n < length:
55 | description=list_nameUrl[n]['title']#歌单介绍
56 | songhref= list_nameUrl[n]['href']
57 | num=list_num[n].text#歌曲播放量
58 | #picture=list_pic[n]['src']#图片链接地址
59 | author=list_author[n]['title']#歌单作者
60 | row=[description, songhref, num, author]
61 | #print('歌单图片:'+list_pic[n]['src']+'\n\n')
62 | #print('歌单名称:'+list_nameUrl[n]['title']+'\n\n歌单地址:'+list_nameUrl[n]['href']+'\n\n')
63 | #print('歌单播放量:'+list_num[n].text+'\n\n')
64 | #print('歌单作者:'+list_author[n]['title']+'\n\n作者主页:'+list_author[n]['href']+'\n\n\n')
65 | n += 1
66 | for i in range(len(row)):
67 | data_sheet.write(n, i, row[i], set_style('Times New Roman', 220, True))
68 | workbook.save('C:/Users/Administrator/Desktop/bs4WangYiYunDemo2.xls')
69 | url = 'http://music.163.com/discover/playlist'
70 | url= 'http://music.163.com/discover/playlist/?order=hot&cat=民谣&limit=35&offset=35'
71 | url = gethtml(url, headers={
72 | 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
73 | 'Host': 'music.163.com'
74 | })
75 |
76 | parsehtmlMusicList(url)
77 |
78 |
--------------------------------------------------------------------------------
/PythonDemo/SnowNLP/test.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from __future__ import print_function
3 | from __future__ import unicode_literals
4 |
5 | text = '''
6 | 如果你是一位教师,那么不管你的工作单位是高中、大学还是职业培训等教育机构,你都能在MOOC上找到对学生有用的内容。近期许多MOOC实验项目的目标都是建设一个课堂教学支持系统。我们根据研究结果、采访和我们参与的课程整理出以下建议,希望能够指导教师将MOOC的经验和资源运用到传统课堂教学中。
7 | 1900年挪威特隆赫姆的科学课,图片来自WikiMedia。
8 | 1.善用电子设备
9 | 学生们都具备参与在线课堂的工具,而教师也可以利用自己的设备参与线上社交。如果你是一名学生,就把这篇文章转给你的老师吧。让老师看看怎样用智能手机和笔记本电脑记录你的活动,并迅速回复评论;看看你用哪些手机应用查看地图、搜索信息和购物;展示你的微博、人人和网盘,还有其他人留下的评论。最后,告诉老师,如果他们要开在线课程,并且需要学生助手,别忘了叫上你。
10 | 2.让课堂更广阔
11 | MOOC的成功证明,相比课堂教学,许多学生更喜欢在线学习。随着智能手机、平板电脑和笔记本电脑在学生族中的流行,学生们有了与朋友、家人和老师交流的新方式。显然,在头脑清醒、精神集中的时候,看课程视频、做练习和参与课堂讨论的效率都更高。在MOOC,这意味着一个印度学生和一个新汉普郡的学生能够达到同一水平。因此在传统课堂中,我们也要让那些在足球训练场上、在滑雪度假村和在家养病的学生能够和坐在课时第一排的学生学到同样多的东西。在线工具能够让课堂不再受限于校园,学生们也能够获得更加美好而难忘的学习体验。
12 | 3.参与是成功之母
13 | MOOC研究显示,成功的学生都会充分利用所有的在线资源,例如视频、测试、课堂讨论和由其他学生编写的课程维基百科。对于课堂教学,教师可以建立在线平台,让学生在课堂之外也能参与到学校中。这种交流可以只是发一条微博或者公告,邀请学生对备课提出建议。邀请学生把能够帮助他们复习所学知识的相关文章或图片发布到网上。只要利用这些小诀窍,大家就都能看到谁能跟上课程进度,进而鼓励他们或者提出建议。在课堂上可以表扬在网络上活跃的学生,或者解答学生在网上提出的问题。
14 | 4.建立网络社区
15 | 为了活跃课堂,你需要在网络上建一个“据点”,也就是说,需要建立一个网站,为学生提供课件,提醒任务完成时间,并且让学生之间建立联系。假设你是一位老师,并且已经有了自己的注册、评分和考勤系统,那就把这些运用到网络上吧。我们的目标是为学生建立一个平台,让他们能在现有的网络社交活动、与班上同学的交流和课堂作业之间自由转换。
16 | W·伊恩-欧伯恩(W. Ian O’Byrne)是纽黑文大学的教育技术助教,他建议利用谷歌协作平台实现这个目的。他指出,学生们都有自己的移动设备,并且希望有一个“够酷而且适合聚会”的地方学习。只把课程都放到网上是不够的,需要精心设计漂亮的页面,并且这个网页要方便学生进行互动。
17 | 他说:“用好谷歌协作平台的关键仅仅是迈出第一步。把它当作一项工程,认真编辑,打造你自己的在线学习空间,就像每年组织一批学生一样。你可以在每个新学年调整课程内容,不断建设升级,把你的数字学习社区建设得越来越好。”
18 | MOOC是学校的一种新形式,欧伯恩建议在起步的时候,先为每门课程的课件加上指针,再利用软件工具,就可以轻松根据学生的学习进度添加课程。他希望,在学生使用在线社区的同时,教师也能发现参与在线社区的方式。
19 | 5.从线上到线下
20 | MOOC的一个缺陷就是无法组建高效的学习小组,而教师在这方面可以大有作为。当学生们看到其他同学更新了课程内容,他们就知道谁掌握了所学的知识,从而邀请这些同学合作完成任务,或向他们请教。我经常向教师们介绍这个例子:我在Google+圈子里发了一条信息,例如“明天我们会讨论矛盾冲突在吸引读者注意力方面的作用。今晚,在你回家的路上,拍一张照片或一段录像。用文字介绍你的见闻,以证明这个观点,并邀请其他同学参与讨论。”我收到的作业包括交通堵塞,猫狗对峙,被泡在水里的花园以及足球训练中的射门。第二天,学生们就可以归纳整理前一天晚上在网络上收集到的评论了。
21 | 6.用好你的相机
22 | 随着智能手机和平板电脑的普及,相机也变得无处不在,而且分享照片也越来越简单。MOOC的明星教授说,把45分钟的讲座变成10分钟一段的视频让他们被迫“升级课程”。不是每个老师都能通过这种方式吸引一批学生,但是他们可以参考这个经验,为课堂制作自己的视频,例如实地考察录像。让整个班都出去跑一趟可能不可行,但利用视频和照片,可以把考察点“带”到课室中来。利用智能手机耳机上配备的话筒,还可以为视频配上讲解,从而高效地用多个视频介绍完一个知识点。
23 | 将MOOC应用到传统课堂教学
24 | 随着大规模网络公开课的发展,教师可以考虑把在线教育的方法应用到自己的课堂教学中。MOOC的课程制作涉及比较复杂的技术,但使用这些课程几乎不费吹灰之力,而且成本也远远不及课程制作。没有加入edX或Coursera的大部分学校可以进行更多自创内容的尝试,就像自出版一样,这也是许多cMOOC的尝试。教师也可以向自己的目标努力。通过打开课堂,建立网络社区和制作教学视频,可以让更多的教师和学生享受到MOOC的投入带来的收益。
25 | '''
26 |
27 |
28 | from snownlp import normal
29 | from snownlp import seg
30 | from snownlp.summary import textrank
31 |
32 |
33 | if __name__ == '__main__':
34 | t = normal.zh2hans(text)
35 | sents = normal.get_sentences(t)
36 | doc = []
37 | for sent in sents:
38 | words = seg.seg(sent)
39 | words = normal.filter_stop(words)
40 | doc.append(words)
41 | rank = textrank.TextRank(doc)
42 | rank.solve()
43 | for index in rank.top_index(5):
44 | print(sents[index])
45 | keyword_rank = textrank.KeywordTextRank(doc)
46 | keyword_rank.solve()
47 | for w in keyword_rank.top_index(5):
48 | print(w)
--------------------------------------------------------------------------------
/PythonSpider/weixin/crawler.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | __author__ = "liuzhijun"
3 |
4 | import requests
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | def crawl():
15 | # url中的参数需要根据自己的情况做调整
16 | url = "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzU4NDQ4MzU5OA==&scene=124&"
17 |
18 | headers = """
19 | Host: mp.weixin.qq.com
20 | Connection: keep-alive
21 | User-Agent: Mozilla/5.0 (Linux; Android 7.0; FRD-AL10 Build/HUAWEIFRD-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/44068 Mobile Safari/537.36 MicroMessenger/6.6.6.1300(0x26060636) NetType/WIFI Language/zh_CN
22 | x-wechat-key: e4d0b85bfed5799347d003048a6b2808543504e012e45917fa9963daf81d43fb5bb1033e428d2363c71bf081895cb4e5e31cb1d4c7cfe3cfbc1a1818bcb44e8796bd595ba7dbbcb009578a5e8298e07e
23 | x-wechat-uin: MzIwMjA1OTM3
24 | Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,image/wxpic,image/sharpp,image/apng,*/*;q=0.8
25 | Accept-Encoding: gzip, deflate
26 | Accept-Language: zh-CN,zh-CN;q=0.8,en-US;q=0.6
27 | Cookie: sd_userid=24811523971059409; sd_cookie_crttime=1523971059409; pgv_pvid=5490707453; pgv_info=ssid=s5182460012; rewardsn=; wxtokenkey=777; wxuin=320205937; devicetype=android-24; version=26060636; lang=zh_CN; pass_ticket=0iXHmW5c7/qdielT0m3lOeuxrLCMdn31Wc+lwcDdeScap7bw8BjSC1U7tLHbRLIN; wap_sid2=CPHo15gBElxlZmFuaVRkbTlERFlJblFGRXFBeVlKSmNMbWRJRXdfNTJEdU1sSjlNTmdTd0gyemg3WXRMVjFoTTVGSHZfNGVTRDlYdnE5d2JwZ1ppMU95dFBhVGowcnNEQUFBfjD0vqvXBTgNQJVO
28 | Q-UA2: QV=3&PL=ADR&PR=WX&PP=com.tencent.mm&PPVN=6.6.6&TBSVC=43607&CO=BK&COVC=044068&PB=GE&VE=GA&DE=PHONE&CHID=0&LCID=9422&MO= FRD-AL10 &RL=1080*1794&OS=7.0&API=24
29 | Q-GUID: 53abc69bd03d1e8b8bb80ef3117888cb
30 | Q-Auth: 31045b957cf33acf31e40be2f3e71c5217597676a9729f1b
31 | """
32 | headers = headers_to_dict(headers)
33 | response = requests.get(url, headers=headers, verify=False)
34 | print(response.text)
35 | if '验证' in response.text:
36 | raise Exception("获取微信公众号文章失败,可能是因为你的请求参数有误,请重新获取")
37 | data = extract_data(response.text)
38 | for item in data:
39 | print(item)
40 |
41 |
42 | def extract_data(html_content):
43 | """
44 | 从html页面中提取历史文章数据
45 | :param html_content 页面源代码
46 | :return: 历史文章列表
47 | """
48 | import re
49 | import html
50 | import json
51 |
52 | rex = "msgList = '({.*?})'"
53 | pattern = re.compile(pattern=rex, flags=re.S)
54 | match = pattern.search(html_content)
55 | if match:
56 | data = match.group(1)
57 | data = html.unescape(data)
58 | data = json.loads(data)
59 | articles = data.get("list")
60 | for item in articles:
61 | print(item)
62 | return articles
63 |
64 |
65 | def headers_to_dict(headers):
66 | """
67 | 将字符串
68 | '''
69 | Host: mp.weixin.qq.com
70 | Connection: keep-alive
71 | Cache-Control: max-age=
72 | '''
73 | 转换成字典类型
74 | :param headers: str
75 | :return: dict
76 | """
77 | headers = headers.split("\n")
78 | d_headers = dict()
79 | for h in headers:
80 | h = h.strip()
81 | if h:
82 | k, v = h.split(":", 1)
83 | d_headers[k] = v.strip()
84 | return d_headers
85 |
86 |
87 | if __name__ == '__main__':
88 | crawl()
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/colored_by_group.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """
3 | Colored by Group Example
4 | ========================
5 |
6 | 生成一个根据从颜色到单词的预定义映射分配颜色的词云
7 | """
8 |
9 | from wordcloud import (WordCloud, get_single_color_func)
10 | import matplotlib.pyplot as plt
11 |
12 |
13 | class SimpleGroupedColorFunc(object):
14 | """Create a color function object which assigns EXACT colors
15 | to certain words based on the color to words mapping
16 |
17 | Parameters
18 | ----------
19 | color_to_words : dict(str -> list(str))
20 | A dictionary that maps a color to the list of words.
21 |
22 | default_color : str
23 | Color that will be assigned to a word that's not a member
24 | of any value from color_to_words.
25 | """
26 |
27 | def __init__(self, color_to_words, default_color):
28 | self.word_to_color = {word: color
29 | for (color, words) in color_to_words.items()
30 | for word in words}
31 |
32 | self.default_color = default_color
33 |
34 | def __call__(self, word, **kwargs):
35 | return self.word_to_color.get(word, self.default_color)
36 |
37 |
38 | class GroupedColorFunc(object):
39 | """Create a color function object which assigns DIFFERENT SHADES of
40 | specified colors to certain words based on the color to words mapping.
41 |
42 | Uses wordcloud.get_single_color_func
43 |
44 | Parameters
45 | ----------
46 | color_to_words : dict(str -> list(str))
47 | A dictionary that maps a color to the list of words.
48 |
49 | default_color : str
50 | Color that will be assigned to a word that's not a member
51 | of any value from color_to_words.
52 | """
53 |
54 | def __init__(self, color_to_words, default_color):
55 | self.color_func_to_words = [
56 | (get_single_color_func(color), set(words))
57 | for (color, words) in color_to_words.items()]
58 |
59 | self.default_color_func = get_single_color_func(default_color)
60 |
61 | def get_color_func(self, word):
62 | """Returns a single_color_func associated with the word"""
63 | try:
64 | color_func = next(
65 | color_func for (color_func, words) in self.color_func_to_words
66 | if word in words)
67 | except StopIteration:
68 | color_func = self.default_color_func
69 |
70 | return color_func
71 |
72 | def __call__(self, word, **kwargs):
73 | return self.get_color_func(word)(word, **kwargs)
74 |
75 |
76 | text = """The Zen of Python, by Tim Peters
77 | Beautiful is better than ugly.
78 | Explicit is better than implicit.
79 | Simple is better than complex.
80 | Complex is better than complicated.
81 | Flat is better than nested.
82 | Sparse is better than dense.
83 | Readability counts.
84 | Special cases aren't special enough to break the rules.
85 | Although practicality beats purity.
86 | Errors should never pass silently.
87 | Unless explicitly silenced.
88 | In the face of ambiguity, refuse the temptation to guess.
89 | There should be one-- and preferably only one --obvious way to do it.
90 | Although that way may not be obvious at first unless you're Dutch.
91 | Now is better than never.
92 | Although never is often better than *right* now.
93 | If the implementation is hard to explain, it's a bad idea.
94 | If the implementation is easy to explain, it may be a good idea.
95 | Namespaces are one honking great idea -- let's do more of those!"""
96 |
97 | # Since the text is small collocations are turned off and text is lower-cased
98 | wc = WordCloud(collocations=False).generate(text.lower())
99 |
100 | color_to_words = {
101 | # words below will be colored with a green single color function
102 | '#00ff00': ['beautiful', 'explicit', 'simple', 'sparse',
103 | 'readability', 'rules', 'practicality',
104 | 'explicitly', 'one', 'now', 'easy', 'obvious', 'better'],
105 | # will be colored with a red single color function
106 | 'red': ['ugly', 'implicit', 'complex', 'complicated', 'nested',
107 | 'dense', 'special', 'errors', 'silently', 'ambiguity',
108 | 'guess', 'hard']
109 | }
110 |
111 | # Words that are not in any of the color_to_words values
112 | # will be colored with a grey single color function
113 | default_color = 'grey'
114 |
115 | # Create a color function with single tone
116 | # grouped_color_func = SimpleGroupedColorFunc(color_to_words, default_color)
117 |
118 | # Create a color function with multiple tones
119 | grouped_color_func = GroupedColorFunc(color_to_words, default_color)
120 |
121 | # Apply our color function
122 | wc.recolor(color_func=grouped_color_func)
123 |
124 | # Plot
125 | plt.figure()
126 | plt.imshow(wc, interpolation="bilinear")
127 | plt.axis("off")
128 | plt.show()
129 |
--------------------------------------------------------------------------------
/PythonDemo/weixin/weixin.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Created on Tue Mar 13 17:01:33 2018
4 |
5 | @author: Administrator
6 | @description 查询微信好友
7 | """
8 |
9 | #!/usr/bin/env python
10 | # encoding=utf-8
11 | from __future__ import print_function
12 |
13 | import os
14 | import requests
15 | import re
16 | import time
17 | import xml.dom.minidom
18 | import json
19 | import sys
20 | import math
21 | import subprocess
22 | import ssl
23 | import threading
24 | import urllib.request
25 |
26 | DEBUG = False
27 |
28 | MAX_GROUP_NUM = 2 # 每组人数
29 | INTERFACE_CALLING_INTERVAL = 5 # 接口调用时间间隔, 间隔太短容易出现"操作太频繁", 会被限制操作半小时左右
30 | MAX_PROGRESS_LEN = 50
31 |
32 | QRImagePath = os.path.join(os.getcwd(), 'qrcode.jpg')
33 |
34 | tip = 0
35 | uuid = ''
36 |
37 | base_uri = ''
38 | redirect_uri = ''
39 | push_uri = ''
40 |
41 | skey = ''
42 | wxsid = ''
43 | wxuin = ''
44 | pass_ticket = ''
45 | deviceId = 'e000000000000000'
46 |
47 | BaseRequest = {}
48 |
49 | ContactList = []
50 | My = []
51 | SyncKey = []
52 |
53 | try:
54 | xrange
55 | range = xrange
56 | except:
57 | # python 3
58 | pass
59 |
60 |
61 | def responseState(func, BaseResponse):
62 | ErrMsg = BaseResponse['ErrMsg']
63 | Ret = BaseResponse['Ret']
64 | if DEBUG or Ret != 0:
65 | print('func: %s, Ret: %d, ErrMsg: %s' % (func, Ret, ErrMsg))
66 |
67 | if Ret != 0:
68 | return False
69 |
70 | return True
71 |
72 |
73 | def getUUID():
74 | global uuid
75 |
76 | url = 'https://login.weixin.qq.com/jslogin'
77 | params = {
78 | 'appid': 'wx782c26e4c19acffb',
79 | 'fun': 'new',
80 | 'lang': 'zh_CN',
81 | '_': int(time.time()),
82 | }
83 |
84 | r = myRequests.get(url=url, params=params)
85 | r.encoding = 'utf-8'
86 | data = r.text
87 |
88 | # print(data)
89 |
90 | # window.QRLogin.code = 200; window.QRLogin.uuid = "oZwt_bFfRg==";
91 | regx = r'window.QRLogin.code = (\d+); window.QRLogin.uuid = "(\S+?)"'
92 | pm = re.search(regx, data)
93 |
94 | code = pm.group(1)
95 | uuid = pm.group(2)
96 |
97 | if code == '200':
98 | return True
99 |
100 | return False
101 |
102 |
103 | def showQRImage():
104 | global tip
105 |
106 | url = 'https://login.weixin.qq.com/qrcode/' + uuid
107 | params = {
108 | 't': 'webwx',
109 | '_': int(time.time()),
110 | }
111 |
112 | r = myRequests.get(url=url, params=params)
113 | tip = 1
114 |
115 | f = open(QRImagePath, 'wb+')
116 | f.write(r.content)
117 | f.close()
118 | time.sleep(1)
119 |
120 | if sys.platform.find('darwin') >= 0:
121 | subprocess.call(['open', QRImagePath])
122 | else:
123 | os.startfile(QRImagePath)
124 |
125 | print('请使用微信扫描二维码以登录')
126 |
127 |
128 | def waitForLogin():
129 | global tip, base_uri, redirect_uri, push_uri
130 |
131 | url = 'https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s' % (
132 | tip, uuid, int(time.time()))
133 |
134 | r = myRequests.get(url=url)
135 | r.encoding = 'utf-8'
136 | data = r.text
137 |
138 | # print(data)
139 |
140 | # window.code=500;
141 | regx = r'window.code=(\d+);'
142 | pm = re.search(regx, data)
143 |
144 | code = pm.group(1)
145 |
146 | if code == '201': # 已扫描
147 | print('成功扫描,请在手机上点击确认以登录')
148 | tip = 0
149 | elif code == '200': # 已登录
150 | print('正在登录...')
151 | regx = r'window.redirect_uri="(\S+?)";'
152 | pm = re.search(regx, data)
153 | redirect_uri = pm.group(1) + '&fun=new'
154 | base_uri = redirect_uri[:redirect_uri.rfind('/')]
155 |
156 | # push_uri与base_uri对应关系(排名分先后)(就是这么奇葩..)
157 | services = [
158 | ('wx2.qq.com', 'webpush2.weixin.qq.com'),
159 | ('qq.com', 'webpush.weixin.qq.com'),
160 | ('web1.wechat.com', 'webpush1.wechat.com'),
161 | ('web2.wechat.com', 'webpush2.wechat.com'),
162 | ('wechat.com', 'webpush.wechat.com'),
163 | ('web1.wechatapp.com', 'webpush1.wechatapp.com'),
164 | ]
165 | push_uri = base_uri
166 | for (searchUrl, pushUrl) in services:
167 | if base_uri.find(searchUrl) >= 0:
168 | push_uri = 'https://%s/cgi-bin/mmwebwx-bin' % pushUrl
169 | break
170 |
171 | # closeQRImage
172 | if sys.platform.find('darwin') >= 0: # for OSX with Preview
173 | os.system("osascript -e 'quit app \"Preview\"'")
174 | elif code == '408': # 超时
175 | pass
176 | # elif code == '400' or code == '500':
177 |
178 | return code
179 |
180 |
181 | def login():
182 | global skey, wxsid, wxuin, pass_ticket, BaseRequest
183 |
184 | r = myRequests.get(url=redirect_uri)
185 | r.encoding = 'utf-8'
186 | data = r.text
187 |
188 | # print(data)
189 |
190 | doc = xml.dom.minidom.parseString(data)
191 | root = doc.documentElement
192 |
193 | for node in root.childNodes:
194 | if node.nodeName == 'skey':
195 | skey = node.childNodes[0].data
196 | elif node.nodeName == 'wxsid':
197 | wxsid = node.childNodes[0].data
198 | elif node.nodeName == 'wxuin':
199 | wxuin = node.childNodes[0].data
200 | elif node.nodeName == 'pass_ticket':
201 | pass_ticket = node.childNodes[0].data
202 |
203 | # print('skey: %s, wxsid: %s, wxuin: %s, pass_ticket: %s' % (skey, wxsid,
204 | # wxuin, pass_ticket))
205 |
206 | if not all((skey, wxsid, wxuin, pass_ticket)):
207 | return False
208 |
209 | BaseRequest = {
210 | 'Uin': int(wxuin),
211 | 'Sid': wxsid,
212 | 'Skey': skey,
213 | 'DeviceID': deviceId,
214 | }
215 |
216 | return True
217 |
218 |
219 | def webwxinit():
220 | url = (base_uri +
221 | '/webwxinit?pass_ticket=%s&skey=%s&r=%s' % (
222 | pass_ticket, skey, int(time.time())))
223 | params = {'BaseRequest': BaseRequest}
224 | headers = {'content-type': 'application/json; charset=UTF-8'}
225 |
226 | r = myRequests.post(url=url, data=json.dumps(params), headers=headers)
227 | r.encoding = 'utf-8'
228 | data = r.json()
229 |
230 | if DEBUG:
231 | f = open(os.path.join(os.getcwd(), 'webwxinit.json'), 'wb')
232 | f.write(r.content)
233 | f.close()
234 |
235 | # print(data)
236 |
237 | global ContactList, My, SyncKey
238 | dic = data
239 | ContactList = dic['ContactList']
240 | My = dic['User']
241 | SyncKey = dic['SyncKey']
242 |
243 | state = responseState('webwxinit', dic['BaseResponse'])
244 | return state
245 |
246 |
247 | def webwxgetcontact():
248 | url = (base_uri +
249 | '/webwxgetcontact?pass_ticket=%s&skey=%s&r=%s' % (
250 | pass_ticket, skey, int(time.time())))
251 | headers = {'content-type': 'application/json; charset=UTF-8'}
252 |
253 | r = myRequests.post(url=url, headers=headers)
254 | r.encoding = 'utf-8'
255 | data = r.json()
256 |
257 | if DEBUG:
258 | f = open(os.path.join(os.getcwd(), 'webwxgetcontact.json'), 'wb')
259 | f.write(r.content)
260 | f.close()
261 |
262 | dic = data
263 | MemberList = dic['MemberList']
264 |
265 | # 倒序遍历,不然删除的时候出问题..
266 | SpecialUsers = ["newsapp", "fmessage", "filehelper", "weibo", "qqmail", "tmessage", "qmessage", "qqsync",
267 | "floatbottle", "lbsapp", "shakeapp", "medianote", "qqfriend", "readerapp", "blogapp", "facebookapp",
268 | "masssendapp",
269 | "meishiapp", "feedsapp", "voip", "blogappweixin", "weixin", "brandsessionholder", "weixinreminder",
270 | "wxid_novlwrv3lqwv11", "gh_22b87fa7cb3c", "officialaccounts", "notification_messages", "wxitil",
271 | "userexperience_alarm"]
272 | for i in range(len(MemberList) - 1, -1, -1):
273 | Member = MemberList[i]
274 | if Member['VerifyFlag'] & 8 != 0: # 公众号/服务号
275 | MemberList.remove(Member)
276 | elif Member['UserName'] in SpecialUsers: # 特殊账号
277 | MemberList.remove(Member)
278 | elif Member['UserName'].find('@@') != -1: # 群聊
279 | MemberList.remove(Member)
280 | elif Member['UserName'] == My['UserName']: # 自己
281 | MemberList.remove(Member)
282 |
283 | return MemberList
284 |
285 |
286 | def syncKey():
287 | SyncKeyItems = ['%s_%s' % (item['Key'], item['Val'])
288 | for item in SyncKey['List']]
289 | SyncKeyStr = '|'.join(SyncKeyItems)
290 | return SyncKeyStr
291 |
292 |
293 | def syncCheck():
294 | url = push_uri + '/synccheck?'
295 | params = {
296 | 'skey': BaseRequest['Skey'],
297 | 'sid': BaseRequest['Sid'],
298 | 'uin': BaseRequest['Uin'],
299 | 'deviceId': BaseRequest['DeviceID'],
300 | 'synckey': syncKey(),
301 | 'r': int(time.time()),
302 | }
303 |
304 | r = myRequests.get(url=url, params=params)
305 | r.encoding = 'utf-8'
306 | data = r.text
307 |
308 | # print(data)
309 |
310 | # window.synccheck={retcode:"0",selector:"2"}
311 | regx = r'window.synccheck={retcode:"(\d+)",selector:"(\d+)"}'
312 | pm = re.search(regx, data)
313 |
314 | retcode = pm.group(1)
315 | selector = pm.group(2)
316 |
317 | return selector
318 |
319 |
320 | def webwxsync():
321 | global SyncKey
322 |
323 | url = base_uri + '/webwxsync?lang=zh_CN&skey=%s&sid=%s&pass_ticket=%s' % (
324 | BaseRequest['Skey'], BaseRequest['Sid'], urllib.quote_plus(pass_ticket))
325 | params = {
326 | 'BaseRequest': BaseRequest,
327 | 'SyncKey': SyncKey,
328 | 'rr': ~int(time.time()),
329 | }
330 | headers = {'content-type': 'application/json; charset=UTF-8'}
331 |
332 | r = myRequests.post(url=url, data=json.dumps(params))
333 | r.encoding = 'utf-8'
334 | data = r.json()
335 |
336 | # print(data)
337 |
338 | dic = data
339 | SyncKey = dic['SyncKey']
340 |
341 | state = responseState('webwxsync', dic['BaseResponse'])
342 | return state
343 |
344 |
345 | def heartBeatLoop():
346 | while True:
347 | selector = syncCheck()
348 | if selector != '0':
349 | webwxsync()
350 | time.sleep(1)
351 |
352 |
353 | def main():
354 | global myRequests
355 |
356 | if hasattr(ssl, '_create_unverified_context'):
357 | ssl._create_default_https_context = ssl._create_unverified_context
358 |
359 | headers = {
360 | 'User-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36'}
361 | myRequests = requests.Session()
362 | myRequests.headers.update(headers)
363 |
364 | if not getUUID():
365 | print('获取uuid失败')
366 | return
367 |
368 | print('正在获取二维码图片...')
369 | showQRImage()
370 |
371 | while waitForLogin() != '200':
372 | pass
373 |
374 | os.remove(QRImagePath)
375 |
376 | if not login():
377 | print('登录失败')
378 | return
379 |
380 | if not webwxinit():
381 | print('初始化失败')
382 | return
383 |
384 | MemberList = webwxgetcontact()
385 |
386 | threading.Thread(target=heartBeatLoop)
387 |
388 | MemberCount = len(MemberList)
389 | print('通讯录共%s位好友' % MemberCount)
390 |
391 | d = {}
392 | imageIndex = 0
393 | for Member in MemberList:
394 | imageIndex = imageIndex + 1
395 | # name = 'C:\\Users\\Public\\Pictures\\' + str(imageIndex) + '.jpg'
396 | # imageUrl = 'http://wx2.qq.com' + Member['HeadImgUrl']
397 | # r = myRequests.get(url=imageUrl, headers=headers)
398 | # imageContent = (r.content)
399 | # fileImage = open(name, 'wb')
400 | # fileImage.write(imageContent)
401 | # fileImage.close()
402 | # print('正在下载第:' + str(imageIndex) + '位好友头像')
403 | d[Member['UserName']] = (Member['NickName'], Member['RemarkName'])
404 | city = Member['City']
405 | city = 'nocity' if city == '' else city
406 | name = Member['NickName']
407 | name = 'noname' if name == '' else name
408 | sign = Member['Signature']
409 | sign = 'nosign' if sign == '' else sign
410 | remark = Member['RemarkName']
411 | remark = 'noremark' if remark == '' else remark
412 | alias = Member['Alias']
413 | alias = 'noalias' if alias == '' else alias
414 | nick = Member['NickName']
415 | nick = 'nonick' if nick == '' else nick
416 | print(name, '|||', city, '|||', Member['Sex'], '|||', Member['StarFriend'], '|||', sign,
417 | '|||', remark, '|||', alias, '|||', nick)
418 |
419 |
420 |
421 | if __name__ == '__main__':
422 | main()
423 | print('回车键退出...')
424 | input()
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/alice_license.txt:
--------------------------------------------------------------------------------
1 | ***** This file should be named 11.txt or 11.zip *****
2 | This and all associated files of various formats will be found in:
3 | http://www.gutenberg.org/1/11/
4 |
5 |
6 |
7 | Updated editions will replace the previous one--the old editions
8 | will be renamed.
9 |
10 | Creating the works from public domain print editions means that no
11 | one owns a United States copyright in these works, so the Foundation
12 | (and you!) can copy and distribute it in the United States without
13 | permission and without paying copyright royalties. Special rules,
14 | set forth in the General Terms of Use part of this license, apply to
15 | copying and distributing Project Gutenberg-tm electronic works to
16 | protect the PROJECT GUTENBERG-tm concept and trademark. Project
17 | Gutenberg is a registered trademark, and may not be used if you
18 | charge for the eBooks, unless you receive specific permission. If you
19 | do not charge anything for copies of this eBook, complying with the
20 | rules is very easy. You may use this eBook for nearly any purpose
21 | such as creation of derivative works, reports, performances and
22 | research. They may be modified and printed and given away--you may do
23 | practically ANYTHING with public domain eBooks. Redistribution is
24 | subject to the trademark license, especially commercial
25 | redistribution.
26 |
27 |
28 |
29 | *** START: FULL LICENSE ***
30 |
31 | THE FULL PROJECT GUTENBERG LICENSE
32 | PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK
33 |
34 | To protect the Project Gutenberg-tm mission of promoting the free
35 | distribution of electronic works, by using or distributing this work
36 | (or any other work associated in any way with the phrase "Project
37 | Gutenberg"), you agree to comply with all the terms of the Full Project
38 | Gutenberg-tm License (available with this file or online at
39 | http://gutenberg.org/license).
40 |
41 |
42 | Section 1. General Terms of Use and Redistributing Project Gutenberg-tm
43 | electronic works
44 |
45 | 1.A. By reading or using any part of this Project Gutenberg-tm
46 | electronic work, you indicate that you have read, understand, agree to
47 | and accept all the terms of this license and intellectual property
48 | (trademark/copyright) agreement. If you do not agree to abide by all
49 | the terms of this agreement, you must cease using and return or destroy
50 | all copies of Project Gutenberg-tm electronic works in your possession.
51 | If you paid a fee for obtaining a copy of or access to a Project
52 | Gutenberg-tm electronic work and you do not agree to be bound by the
53 | terms of this agreement, you may obtain a refund from the person or
54 | entity to whom you paid the fee as set forth in paragraph 1.E.8.
55 |
56 | 1.B. "Project Gutenberg" is a registered trademark. It may only be
57 | used on or associated in any way with an electronic work by people who
58 | agree to be bound by the terms of this agreement. There are a few
59 | things that you can do with most Project Gutenberg-tm electronic works
60 | even without complying with the full terms of this agreement. See
61 | paragraph 1.C below. There are a lot of things you can do with Project
62 | Gutenberg-tm electronic works if you follow the terms of this agreement
63 | and help preserve free future access to Project Gutenberg-tm electronic
64 | works. See paragraph 1.E below.
65 |
66 | 1.C. The Project Gutenberg Literary Archive Foundation ("the Foundation"
67 | or PGLAF), owns a compilation copyright in the collection of Project
68 | Gutenberg-tm electronic works. Nearly all the individual works in the
69 | collection are in the public domain in the United States. If an
70 | individual work is in the public domain in the United States and you are
71 | located in the United States, we do not claim a right to prevent you from
72 | copying, distributing, performing, displaying or creating derivative
73 | works based on the work as long as all references to Project Gutenberg
74 | are removed. Of course, we hope that you will support the Project
75 | Gutenberg-tm mission of promoting free access to electronic works by
76 | freely sharing Project Gutenberg-tm works in compliance with the terms of
77 | this agreement for keeping the Project Gutenberg-tm name associated with
78 | the work. You can easily comply with the terms of this agreement by
79 | keeping this work in the same format with its attached full Project
80 | Gutenberg-tm License when you share it without charge with others.
81 |
82 | 1.D. The copyright laws of the place where you are located also govern
83 | what you can do with this work. Copyright laws in most countries are in
84 | a constant state of change. If you are outside the United States, check
85 | the laws of your country in addition to the terms of this agreement
86 | before downloading, copying, displaying, performing, distributing or
87 | creating derivative works based on this work or any other Project
88 | Gutenberg-tm work. The Foundation makes no representations concerning
89 | the copyright status of any work in any country outside the United
90 | States.
91 |
92 | 1.E. Unless you have removed all references to Project Gutenberg:
93 |
94 | 1.E.1. The following sentence, with active links to, or other immediate
95 | access to, the full Project Gutenberg-tm License must appear prominently
96 | whenever any copy of a Project Gutenberg-tm work (any work on which the
97 | phrase "Project Gutenberg" appears, or with which the phrase "Project
98 | Gutenberg" is associated) is accessed, displayed, performed, viewed,
99 | copied or distributed:
100 |
101 | This eBook is for the use of anyone anywhere at no cost and with
102 | almost no restrictions whatsoever. You may copy it, give it away or
103 | re-use it under the terms of the Project Gutenberg License included
104 | with this eBook or online at www.gutenberg.org
105 |
106 | 1.E.2. If an individual Project Gutenberg-tm electronic work is derived
107 | from the public domain (does not contain a notice indicating that it is
108 | posted with permission of the copyright holder), the work can be copied
109 | and distributed to anyone in the United States without paying any fees
110 | or charges. If you are redistributing or providing access to a work
111 | with the phrase "Project Gutenberg" associated with or appearing on the
112 | work, you must comply either with the requirements of paragraphs 1.E.1
113 | through 1.E.7 or obtain permission for the use of the work and the
114 | Project Gutenberg-tm trademark as set forth in paragraphs 1.E.8 or
115 | 1.E.9.
116 |
117 | 1.E.3. If an individual Project Gutenberg-tm electronic work is posted
118 | with the permission of the copyright holder, your use and distribution
119 | must comply with both paragraphs 1.E.1 through 1.E.7 and any additional
120 | terms imposed by the copyright holder. Additional terms will be linked
121 | to the Project Gutenberg-tm License for all works posted with the
122 | permission of the copyright holder found at the beginning of this work.
123 |
124 | 1.E.4. Do not unlink or detach or remove the full Project Gutenberg-tm
125 | License terms from this work, or any files containing a part of this
126 | work or any other work associated with Project Gutenberg-tm.
127 |
128 | 1.E.5. Do not copy, display, perform, distribute or redistribute this
129 | electronic work, or any part of this electronic work, without
130 | prominently displaying the sentence set forth in paragraph 1.E.1 with
131 | active links or immediate access to the full terms of the Project
132 | Gutenberg-tm License.
133 |
134 | 1.E.6. You may convert to and distribute this work in any binary,
135 | compressed, marked up, nonproprietary or proprietary form, including any
136 | word processing or hypertext form. However, if you provide access to or
137 | distribute copies of a Project Gutenberg-tm work in a format other than
138 | "Plain Vanilla ASCII" or other format used in the official version
139 | posted on the official Project Gutenberg-tm web site (www.gutenberg.org),
140 | you must, at no additional cost, fee or expense to the user, provide a
141 | copy, a means of exporting a copy, or a means of obtaining a copy upon
142 | request, of the work in its original "Plain Vanilla ASCII" or other
143 | form. Any alternate format must include the full Project Gutenberg-tm
144 | License as specified in paragraph 1.E.1.
145 |
146 | 1.E.7. Do not charge a fee for access to, viewing, displaying,
147 | performing, copying or distributing any Project Gutenberg-tm works
148 | unless you comply with paragraph 1.E.8 or 1.E.9.
149 |
150 | 1.E.8. You may charge a reasonable fee for copies of or providing
151 | access to or distributing Project Gutenberg-tm electronic works provided
152 | that
153 |
154 | - You pay a royalty fee of 20% of the gross profits you derive from
155 | the use of Project Gutenberg-tm works calculated using the method
156 | you already use to calculate your applicable taxes. The fee is
157 | owed to the owner of the Project Gutenberg-tm trademark, but he
158 | has agreed to donate royalties under this paragraph to the
159 | Project Gutenberg Literary Archive Foundation. Royalty payments
160 | must be paid within 60 days following each date on which you
161 | prepare (or are legally required to prepare) your periodic tax
162 | returns. Royalty payments should be clearly marked as such and
163 | sent to the Project Gutenberg Literary Archive Foundation at the
164 | address specified in Section 4, "Information about donations to
165 | the Project Gutenberg Literary Archive Foundation."
166 |
167 | - You provide a full refund of any money paid by a user who notifies
168 | you in writing (or by e-mail) within 30 days of receipt that s/he
169 | does not agree to the terms of the full Project Gutenberg-tm
170 | License. You must require such a user to return or
171 | destroy all copies of the works possessed in a physical medium
172 | and discontinue all use of and all access to other copies of
173 | Project Gutenberg-tm works.
174 |
175 | - You provide, in accordance with paragraph 1.F.3, a full refund of any
176 | money paid for a work or a replacement copy, if a defect in the
177 | electronic work is discovered and reported to you within 90 days
178 | of receipt of the work.
179 |
180 | - You comply with all other terms of this agreement for free
181 | distribution of Project Gutenberg-tm works.
182 |
183 | 1.E.9. If you wish to charge a fee or distribute a Project Gutenberg-tm
184 | electronic work or group of works on different terms than are set
185 | forth in this agreement, you must obtain permission in writing from
186 | both the Project Gutenberg Literary Archive Foundation and Michael
187 | Hart, the owner of the Project Gutenberg-tm trademark. Contact the
188 | Foundation as set forth in Section 3 below.
189 |
190 | 1.F.
191 |
192 | 1.F.1. Project Gutenberg volunteers and employees expend considerable
193 | effort to identify, do copyright research on, transcribe and proofread
194 | public domain works in creating the Project Gutenberg-tm
195 | collection. Despite these efforts, Project Gutenberg-tm electronic
196 | works, and the medium on which they may be stored, may contain
197 | "Defects," such as, but not limited to, incomplete, inaccurate or
198 | corrupt data, transcription errors, a copyright or other intellectual
199 | property infringement, a defective or damaged disk or other medium, a
200 | computer virus, or computer codes that damage or cannot be read by
201 | your equipment.
202 |
203 | 1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for the "Right
204 | of Replacement or Refund" described in paragraph 1.F.3, the Project
205 | Gutenberg Literary Archive Foundation, the owner of the Project
206 | Gutenberg-tm trademark, and any other party distributing a Project
207 | Gutenberg-tm electronic work under this agreement, disclaim all
208 | liability to you for damages, costs and expenses, including legal
209 | fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
210 | LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE
211 | PROVIDED IN PARAGRAPH F3. YOU AGREE THAT THE FOUNDATION, THE
212 | TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE
213 | LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE OR
214 | INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH
215 | DAMAGE.
216 |
217 | 1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you discover a
218 | defect in this electronic work within 90 days of receiving it, you can
219 | receive a refund of the money (if any) you paid for it by sending a
220 | written explanation to the person you received the work from. If you
221 | received the work on a physical medium, you must return the medium with
222 | your written explanation. The person or entity that provided you with
223 | the defective work may elect to provide a replacement copy in lieu of a
224 | refund. If you received the work electronically, the person or entity
225 | providing it to you may choose to give you a second opportunity to
226 | receive the work electronically in lieu of a refund. If the second copy
227 | is also defective, you may demand a refund in writing without further
228 | opportunities to fix the problem.
229 |
230 | 1.F.4. Except for the limited right of replacement or refund set forth
231 | in paragraph 1.F.3, this work is provided to you 'AS-IS' WITH NO OTHER
232 | WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
233 | WARRANTIES OF MERCHANTIBILITY OR FITNESS FOR ANY PURPOSE.
234 |
235 | 1.F.5. Some states do not allow disclaimers of certain implied
236 | warranties or the exclusion or limitation of certain types of damages.
237 | If any disclaimer or limitation set forth in this agreement violates the
238 | law of the state applicable to this agreement, the agreement shall be
239 | interpreted to make the maximum disclaimer or limitation permitted by
240 | the applicable state law. The invalidity or unenforceability of any
241 | provision of this agreement shall not void the remaining provisions.
242 |
243 | 1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation, the
244 | trademark owner, any agent or employee of the Foundation, anyone
245 | providing copies of Project Gutenberg-tm electronic works in accordance
246 | with this agreement, and any volunteers associated with the production,
247 | promotion and distribution of Project Gutenberg-tm electronic works,
248 | harmless from all liability, costs and expenses, including legal fees,
249 | that arise directly or indirectly from any of the following which you do
250 | or cause to occur: (a) distribution of this or any Project Gutenberg-tm
251 | work, (b) alteration, modification, or additions or deletions to any
252 | Project Gutenberg-tm work, and (c) any Defect you cause.
253 |
254 |
255 | Section 2. Information about the Mission of Project Gutenberg-tm
256 |
257 | Project Gutenberg-tm is synonymous with the free distribution of
258 | electronic works in formats readable by the widest variety of computers
259 | including obsolete, old, middle-aged and new computers. It exists
260 | because of the efforts of hundreds of volunteers and donations from
261 | people in all walks of life.
262 |
263 | Volunteers and financial support to provide volunteers with the
264 | assistance they need, is critical to reaching Project Gutenberg-tm's
265 | goals and ensuring that the Project Gutenberg-tm collection will
266 | remain freely available for generations to come. In 2001, the Project
267 | Gutenberg Literary Archive Foundation was created to provide a secure
268 | and permanent future for Project Gutenberg-tm and future generations.
269 | To learn more about the Project Gutenberg Literary Archive Foundation
270 | and how your efforts and donations can help, see Sections 3 and 4
271 | and the Foundation web page at http://www.pglaf.org.
272 |
273 |
274 | Section 3. Information about the Project Gutenberg Literary Archive
275 | Foundation
276 |
277 | The Project Gutenberg Literary Archive Foundation is a non profit
278 | 501(c)(3) educational corporation organized under the laws of the
279 | state of Mississippi and granted tax exempt status by the Internal
280 | Revenue Service. The Foundation's EIN or federal tax identification
281 | number is 64-6221541. Its 501(c)(3) letter is posted at
282 | http://pglaf.org/fundraising. Contributions to the Project Gutenberg
283 | Literary Archive Foundation are tax deductible to the full extent
284 | permitted by U.S. federal laws and your state's laws.
285 |
286 | The Foundation's principal office is located at 4557 Melan Dr. S.
287 | Fairbanks, AK, 99712., but its volunteers and employees are scattered
288 | throughout numerous locations. Its business office is located at
289 | 809 North 1500 West, Salt Lake City, UT 84116, (801) 596-1887, email
290 | business@pglaf.org. Email contact links and up to date contact
291 | information can be found at the Foundation's web site and official
292 | page at http://pglaf.org
293 |
294 | For additional contact information:
295 | Dr. Gregory B. Newby
296 | Chief Executive and Director
297 | gbnewby@pglaf.org
298 |
299 |
300 | Section 4. Information about Donations to the Project Gutenberg
301 | Literary Archive Foundation
302 |
303 | Project Gutenberg-tm depends upon and cannot survive without wide
304 | spread public support and donations to carry out its mission of
305 | increasing the number of public domain and licensed works that can be
306 | freely distributed in machine readable form accessible by the widest
307 | array of equipment including outdated equipment. Many small donations
308 | ($1 to $5,000) are particularly important to maintaining tax exempt
309 | status with the IRS.
310 |
311 | The Foundation is committed to complying with the laws regulating
312 | charities and charitable donations in all 50 states of the United
313 | States. Compliance requirements are not uniform and it takes a
314 | considerable effort, much paperwork and many fees to meet and keep up
315 | with these requirements. We do not solicit donations in locations
316 | where we have not received written confirmation of compliance. To
317 | SEND DONATIONS or determine the status of compliance for any
318 | particular state visit http://pglaf.org
319 |
320 | While we cannot and do not solicit contributions from states where we
321 | have not met the solicitation requirements, we know of no prohibition
322 | against accepting unsolicited donations from donors in such states who
323 | approach us with offers to donate.
324 |
325 | International donations are gratefully accepted, but we cannot make
326 | any statements concerning tax treatment of donations received from
327 | outside the United States. U.S. laws alone swamp our small staff.
328 |
329 | Please check the Project Gutenberg Web pages for current donation
330 | methods and addresses. Donations are accepted in a number of other
331 | ways including checks, online payments and credit card donations.
332 | To donate, please visit: http://pglaf.org/donate
333 |
334 |
335 | Section 5. General Information About Project Gutenberg-tm electronic
336 | works.
337 |
338 | Professor Michael S. Hart is the originator of the Project Gutenberg-tm
339 | concept of a library of electronic works that could be freely shared
340 | with anyone. For thirty years, he produced and distributed Project
341 | Gutenberg-tm eBooks with only a loose network of volunteer support.
342 |
343 |
344 | Project Gutenberg-tm eBooks are often created from several printed
345 | editions, all of which are confirmed as Public Domain in the U.S.
346 | unless a copyright notice is included. Thus, we do not necessarily
347 | keep eBooks in compliance with any particular paper edition.
348 |
349 |
350 | Most people start at our Web site which has the main PG search facility:
351 |
352 | http://www.gutenberg.org
353 |
354 | This Web site includes information about Project Gutenberg-tm,
355 | including how to make donations to the Project Gutenberg Literary
356 | Archive Foundation, how to help produce our new eBooks, and how to
357 | subscribe to our email newsletter to hear about new eBooks.
358 |
359 |
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/constitution.txt:
--------------------------------------------------------------------------------
1 | We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.
2 |
3 | Article. I.
4 |
5 | Section. 1.
6 |
7 | All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives.
8 |
9 | Section. 2.
10 |
11 | The House of Representatives shall be composed of Members chosen every second Year by the People of the several States, and the Electors in each State shall have the Qualifications requisite for Electors of the most numerous Branch of the State Legislature.
12 |
13 | No Person shall be a Representative who shall not have attained to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State in which he shall be chosen.
14 |
15 | Representatives and direct Taxes shall be apportioned among the several States which may be included within this Union, according to their respective Numbers, which shall be determined by adding to the whole Number of free Persons, including those bound to Service for a Term of Years, and excluding Indians not taxed, three fifths of all other Persons. The actual Enumeration shall be made within three Years after the first Meeting of the Congress of the United States, and within every subsequent Term of ten Years, in such Manner as they shall by Law direct. The Number of Representatives shall not exceed one for every thirty Thousand, but each State shall have at Least one Representative; and until such enumeration shall be made, the State of New Hampshire shall be entitled to chuse three, Massachusetts eight, Rhode-Island and Providence Plantations one, Connecticut five, New-York six, New Jersey four, Pennsylvania eight, Delaware one, Maryland six, Virginia ten, North Carolina five, South Carolina five, and Georgia three.
16 |
17 | When vacancies happen in the Representation from any State, the Executive Authority thereof shall issue Writs of Election to fill such Vacancies.
18 |
19 | The House of Representatives shall chuse their Speaker and other Officers; and shall have the sole Power of Impeachment.
20 |
21 | Section. 3.
22 |
23 | The Senate of the United States shall be composed of two Senators from each State, chosen by the Legislature thereof for six Years; and each Senator shall have one Vote.
24 |
25 | Immediately after they shall be assembled in Consequence of the first Election, they shall be divided as equally as may be into three Classes. The Seats of the Senators of the first Class shall be vacated at the Expiration of the second Year, of the second Class at the Expiration of the fourth Year, and of the third Class at the Expiration of the sixth Year, so that one third may be chosen every second Year; and if Vacancies happen by Resignation, or otherwise, during the Recess of the Legislature of any State, the Executive thereof may make temporary Appointments until the next Meeting of the Legislature, which shall then fill such Vacancies.
26 |
27 | No Person shall be a Senator who shall not have attained to the Age of thirty Years, and been nine Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State for which he shall be chosen.
28 |
29 | The Vice President of the United States shall be President of the Senate, but shall have no Vote, unless they be equally divided.
30 |
31 | The Senate shall chuse their other Officers, and also a President pro tempore, in the Absence of the Vice President, or when he shall exercise the Office of President of the United States.
32 |
33 | The Senate shall have the sole Power to try all Impeachments. When sitting for that Purpose, they shall be on Oath or Affirmation. When the President of the United States is tried, the Chief Justice shall preside: And no Person shall be convicted without the Concurrence of two thirds of the Members present.
34 |
35 | Judgment in Cases of Impeachment shall not extend further than to removal from Office, and disqualification to hold and enjoy any Office of honor, Trust or Profit under the United States: but the Party convicted shall nevertheless be liable and subject to Indictment, Trial, Judgment and Punishment, according to Law.
36 |
37 | Section. 4.
38 |
39 | The Times, Places and Manner of holding Elections for Senators and Representatives, shall be prescribed in each State by the Legislature thereof; but the Congress may at any time by Law make or alter such Regulations, except as to the Places of chusing Senators.
40 |
41 | The Congress shall assemble at least once in every Year, and such Meeting shall be on the first Monday in December, unless they shall by Law appoint a different Day.
42 |
43 | Section. 5.
44 |
45 | Each House shall be the Judge of the Elections, Returns and Qualifications of its own Members, and a Majority of each shall constitute a Quorum to do Business; but a smaller Number may adjourn from day to day, and may be authorized to compel the Attendance of absent Members, in such Manner, and under such Penalties as each House may provide.
46 |
47 | Each House may determine the Rules of its Proceedings, punish its Members for disorderly Behaviour, and, with the Concurrence of two thirds, expel a Member.
48 |
49 | Each House shall keep a Journal of its Proceedings, and from time to time publish the same, excepting such Parts as may in their Judgment require Secrecy; and the Yeas and Nays of the Members of either House on any question shall, at the Desire of one fifth of those Present, be entered on the Journal.
50 |
51 | Neither House, during the Session of Congress, shall, without the Consent of the other, adjourn for more than three days, nor to any other Place than that in which the two Houses shall be sitting.
52 |
53 | Section. 6.
54 |
55 | The Senators and Representatives shall receive a Compensation for their Services, to be ascertained by Law, and paid out of the Treasury of the United States. They shall in all Cases, except Treason, Felony and Breach of the Peace, be privileged from Arrest during their Attendance at the Session of their respective Houses, and in going to and returning from the same; and for any Speech or Debate in either House, they shall not be questioned in any other Place.
56 |
57 | No Senator or Representative shall, during the Time for which he was elected, be appointed to any civil Office under the Authority of the United States, which shall have been created, or the Emoluments whereof shall have been encreased during such time; and no Person holding any Office under the United States, shall be a Member of either House during his Continuance in Office.
58 |
59 | Section. 7.
60 |
61 | All Bills for raising Revenue shall originate in the House of Representatives; but the Senate may propose or concur with Amendments as on other Bills.
62 |
63 | Every Bill which shall have passed the House of Representatives and the Senate, shall, before it become a Law, be presented to the President of the United States: If he approve he shall sign it, but if not he shall return it, with his Objections to that House in which it shall have originated, who shall enter the Objections at large on their Journal, and proceed to reconsider it. If after such Reconsideration two thirds of that House shall agree to pass the Bill, it shall be sent, together with the Objections, to the other House, by which it shall likewise be reconsidered, and if approved by two thirds of that House, it shall become a Law. But in all such Cases the Votes of both Houses shall be determined by yeas and Nays, and the Names of the Persons voting for and against the Bill shall be entered on the Journal of each House respectively. If any Bill shall not be returned by the President within ten Days (Sundays excepted) after it shall have been presented to him, the Same shall be a Law, in like Manner as if he had signed it, unless the Congress by their Adjournment prevent its Return, in which Case it shall not be a Law.
64 |
65 | Every Order, Resolution, or Vote to which the Concurrence of the Senate and House of Representatives may be necessary (except on a question of Adjournment) shall be presented to the President of the United States; and before the Same shall take Effect, shall be approved by him, or being disapproved by him, shall be repassed by two thirds of the Senate and House of Representatives, according to the Rules and Limitations prescribed in the Case of a Bill.
66 |
67 | Section. 8.
68 |
69 | The Congress shall have Power To lay and collect Taxes, Duties, Imposts and Excises, to pay the Debts and provide for the common Defence and general Welfare of the United States; but all Duties, Imposts and Excises shall be uniform throughout the United States;
70 |
71 | To borrow Money on the credit of the United States;
72 |
73 | To regulate Commerce with foreign Nations, and among the several States, and with the Indian Tribes;
74 |
75 | To establish an uniform Rule of Naturalization, and uniform Laws on the subject of Bankruptcies throughout the United States;
76 |
77 | To coin Money, regulate the Value thereof, and of foreign Coin, and fix the Standard of Weights and Measures;
78 |
79 | To provide for the Punishment of counterfeiting the Securities and current Coin of the United States;
80 |
81 | To establish Post Offices and post Roads;
82 |
83 | To promote the Progress of Science and useful Arts, by securing for limited Times to Authors and Inventors the exclusive Right to their respective Writings and Discoveries;
84 |
85 | To constitute Tribunals inferior to the supreme Court;
86 |
87 | To define and punish Piracies and Felonies committed on the high Seas, and Offences against the Law of Nations;
88 |
89 | To declare War, grant Letters of Marque and Reprisal, and make Rules concerning Captures on Land and Water;
90 |
91 | To raise and support Armies, but no Appropriation of Money to that Use shall be for a longer Term than two Years;
92 |
93 | To provide and maintain a Navy;
94 |
95 | To make Rules for the Government and Regulation of the land and naval Forces;
96 |
97 | To provide for calling forth the Militia to execute the Laws of the Union, suppress Insurrections and repel Invasions;
98 |
99 | To provide for organizing, arming, and disciplining, the Militia, and for governing such Part of them as may be employed in the Service of the United States, reserving to the States respectively, the Appointment of the Officers, and the Authority of training the Militia according to the discipline prescribed by Congress;
100 |
101 | To exercise exclusive Legislation in all Cases whatsoever, over such District (not exceeding ten Miles square) as may, by Cession of particular States, and the Acceptance of Congress, become the Seat of the Government of the United States, and to exercise like Authority over all Places purchased by the Consent of the Legislature of the State in which the Same shall be, for the Erection of Forts, Magazines, Arsenals, dock-Yards, and other needful Buildings;--And
102 |
103 | To make all Laws which shall be necessary and proper for carrying into Execution the foregoing Powers, and all other Powers vested by this Constitution in the Government of the United States, or in any Department or Officer thereof.
104 |
105 | Section. 9.
106 |
107 | The Migration or Importation of such Persons as any of the States now existing shall think proper to admit, shall not be prohibited by the Congress prior to the Year one thousand eight hundred and eight, but a Tax or duty may be imposed on such Importation, not exceeding ten dollars for each Person.
108 |
109 | The Privilege of the Writ of Habeas Corpus shall not be suspended, unless when in Cases of Rebellion or Invasion the public Safety may require it.
110 |
111 | No Bill of Attainder or ex post facto Law shall be passed.
112 |
113 | No Capitation, or other direct, Tax shall be laid, unless in Proportion to the Census or enumeration herein before directed to be taken.
114 |
115 | No Tax or Duty shall be laid on Articles exported from any State.
116 |
117 | No Preference shall be given by any Regulation of Commerce or Revenue to the Ports of one State over those of another; nor shall Vessels bound to, or from, one State, be obliged to enter, clear, or pay Duties in another.
118 |
119 | No Money shall be drawn from the Treasury, but in Consequence of Appropriations made by Law; and a regular Statement and Account of the Receipts and Expenditures of all public Money shall be published from time to time.
120 |
121 | No Title of Nobility shall be granted by the United States: And no Person holding any Office of Profit or Trust under them, shall, without the Consent of the Congress, accept of any present, Emolument, Office, or Title, of any kind whatever, from any King, Prince, or foreign State.
122 |
123 | Section. 10.
124 |
125 | No State shall enter into any Treaty, Alliance, or Confederation; grant Letters of Marque and Reprisal; coin Money; emit Bills of Credit; make any Thing but gold and silver Coin a Tender in Payment of Debts; pass any Bill of Attainder, ex post facto Law, or Law impairing the Obligation of Contracts, or grant any Title of Nobility.
126 |
127 | No State shall, without the Consent of the Congress, lay any Imposts or Duties on Imports or Exports, except what may be absolutely necessary for executing it's inspection Laws: and the net Produce of all Duties and Imposts, laid by any State on Imports or Exports, shall be for the Use of the Treasury of the United States; and all such Laws shall be subject to the Revision and Controul of the Congress.
128 |
129 | No State shall, without the Consent of Congress, lay any Duty of Tonnage, keep Troops, or Ships of War in time of Peace, enter into any Agreement or Compact with another State, or with a foreign Power, or engage in War, unless actually invaded, or in such imminent Danger as will not admit of delay.
130 |
131 | Article. II.
132 |
133 | Section. 1.
134 |
135 | The executive Power shall be vested in a President of the United States of America. He shall hold his Office during the Term of four Years, and, together with the Vice President, chosen for the same Term, be elected, as follows:
136 |
137 | Each State shall appoint, in such Manner as the Legislature thereof may direct, a Number of Electors, equal to the whole Number of Senators and Representatives to which the State may be entitled in the Congress: but no Senator or Representative, or Person holding an Office of Trust or Profit under the United States, shall be appointed an Elector.
138 |
139 | The Electors shall meet in their respective States, and vote by Ballot for two Persons, of whom one at least shall not be an Inhabitant of the same State with themselves. And they shall make a List of all the Persons voted for, and of the Number of Votes for each; which List they shall sign and certify, and transmit sealed to the Seat of the Government of the United States, directed to the President of the Senate. The President of the Senate shall, in the Presence of the Senate and House of Representatives, open all the Certificates, and the Votes shall then be counted. The Person having the greatest Number of Votes shall be the President, if such Number be a Majority of the whole Number of Electors appointed; and if there be more than one who have such Majority, and have an equal Number of Votes, then the House of Representatives shall immediately chuse by Ballot one of them for President; and if no Person have a Majority, then from the five highest on the List the said House shall in like Manner chuse the President. But in chusing the President, the Votes shall be taken by States, the Representation from each State having one Vote; A quorum for this purpose shall consist of a Member or Members from two thirds of the States, and a Majority of all the States shall be necessary to a Choice. In every Case, after the Choice of the President, the Person having the greatest Number of Votes of the Electors shall be the Vice President. But if there should remain two or more who have equal Votes, the Senate shall chuse from them by Ballot the Vice President.
140 |
141 | The Congress may determine the Time of chusing the Electors, and the Day on which they shall give their Votes; which Day shall be the same throughout the United States.
142 |
143 | No Person except a natural born Citizen, or a Citizen of the United States, at the time of the Adoption of this Constitution, shall be eligible to the Office of President; neither shall any Person be eligible to that Office who shall not have attained to the Age of thirty five Years, and been fourteen Years a Resident within the United States.
144 |
145 | In Case of the Removal of the President from Office, or of his Death, Resignation, or Inability to discharge the Powers and Duties of the said Office, the Same shall devolve on the Vice President, and the Congress may by Law provide for the Case of Removal, Death, Resignation or Inability, both of the President and Vice President, declaring what Officer shall then act as President, and such Officer shall act accordingly, until the Disability be removed, or a President shall be elected.
146 |
147 | The President shall, at stated Times, receive for his Services, a Compensation, which shall neither be increased nor diminished during the Period for which he shall have been elected, and he shall not receive within that Period any other Emolument from the United States, or any of them.
148 |
149 | Before he enter on the Execution of his Office, he shall take the following Oath or Affirmation:--"I do solemnly swear (or affirm) that I will faithfully execute the Office of President of the United States, and will to the best of my Ability, preserve, protect and defend the Constitution of the United States."
150 |
151 | Section. 2.
152 |
153 | The President shall be Commander in Chief of the Army and Navy of the United States, and of the Militia of the several States, when called into the actual Service of the United States; he may require the Opinion, in writing, of the principal Officer in each of the executive Departments, upon any Subject relating to the Duties of their respective Offices, and he shall have Power to grant Reprieves and Pardons for Offences against the United States, except in Cases of Impeachment.
154 |
155 | He shall have Power, by and with the Advice and Consent of the Senate, to make Treaties, provided two thirds of the Senators present concur; and he shall nominate, and by and with the Advice and Consent of the Senate, shall appoint Ambassadors, other public Ministers and Consuls, Judges of the supreme Court, and all other Officers of the United States, whose Appointments are not herein otherwise provided for, and which shall be established by Law: but the Congress may by Law vest the Appointment of such inferior Officers, as they think proper, in the President alone, in the Courts of Law, or in the Heads of Departments.
156 |
157 | The President shall have Power to fill up all Vacancies that may happen during the Recess of the Senate, by granting Commissions which shall expire at the End of their next Session.
158 |
159 | Section. 3.
160 |
161 | He shall from time to time give to the Congress Information of the State of the Union, and recommend to their Consideration such Measures as he shall judge necessary and expedient; he may, on extraordinary Occasions, convene both Houses, or either of them, and in Case of Disagreement between them, with Respect to the Time of Adjournment, he may adjourn them to such Time as he shall think proper; he shall receive Ambassadors and other public Ministers; he shall take Care that the Laws be faithfully executed, and shall Commission all the Officers of the United States.
162 |
163 | Section. 4.
164 |
165 | The President, Vice President and all civil Officers of the United States, shall be removed from Office on Impeachment for, and Conviction of, Treason, Bribery, or other high Crimes and Misdemeanors.
166 |
167 | Article III.
168 |
169 | Section. 1.
170 |
171 | The judicial Power of the United States shall be vested in one supreme Court, and in such inferior Courts as the Congress may from time to time ordain and establish. The Judges, both of the supreme and inferior Courts, shall hold their Offices during good Behaviour, and shall, at stated Times, receive for their Services a Compensation, which shall not be diminished during their Continuance in Office.
172 |
173 | Section. 2.
174 |
175 | The judicial Power shall extend to all Cases, in Law and Equity, arising under this Constitution, the Laws of the United States, and Treaties made, or which shall be made, under their Authority;--to all Cases affecting Ambassadors, other public Ministers and Consuls;--to all Cases of admiralty and maritime Jurisdiction;--to Controversies to which the United States shall be a Party;--to Controversies between two or more States;-- between a State and Citizens of another State,--between Citizens of different States,--between Citizens of the same State claiming Lands under Grants of different States, and between a State, or the Citizens thereof, and foreign States, Citizens or Subjects.
176 |
177 | In all Cases affecting Ambassadors, other public Ministers and Consuls, and those in which a State shall be Party, the supreme Court shall have original Jurisdiction. In all the other Cases before mentioned, the supreme Court shall have appellate Jurisdiction, both as to Law and Fact, with such Exceptions, and under such Regulations as the Congress shall make.
178 |
179 | The Trial of all Crimes, except in Cases of Impeachment, shall be by Jury; and such Trial shall be held in the State where the said Crimes shall have been committed; but when not committed within any State, the Trial shall be at such Place or Places as the Congress may by Law have directed.
180 |
181 | Section. 3.
182 |
183 | Treason against the United States, shall consist only in levying War against them, or in adhering to their Enemies, giving them Aid and Comfort. No Person shall be convicted of Treason unless on the Testimony of two Witnesses to the same overt Act, or on Confession in open Court.
184 |
185 | The Congress shall have Power to declare the Punishment of Treason, but no Attainder of Treason shall work Corruption of Blood, or Forfeiture except during the Life of the Person attainted.
186 |
187 | Article. IV.
188 |
189 | Section. 1.
190 |
191 | Full Faith and Credit shall be given in each State to the public Acts, Records, and judicial Proceedings of every other State. And the Congress may by general Laws prescribe the Manner in which such Acts, Records and Proceedings shall be proved, and the Effect thereof.
192 |
193 | Section. 2.
194 |
195 | The Citizens of each State shall be entitled to all Privileges and Immunities of Citizens in the several States.
196 |
197 | A Person charged in any State with Treason, Felony, or other Crime, who shall flee from Justice, and be found in another State, shall on Demand of the executive Authority of the State from which he fled, be delivered up, to be removed to the State having Jurisdiction of the Crime.
198 |
199 | No Person held to Service or Labour in one State, under the Laws thereof, escaping into another, shall, in Consequence of any Law or Regulation therein, be discharged from such Service or Labour, but shall be delivered up on Claim of the Party to whom such Service or Labour may be due.
200 |
201 | Section. 3.
202 |
203 | New States may be admitted by the Congress into this Union; but no new State shall be formed or erected within the Jurisdiction of any other State; nor any State be formed by the Junction of two or more States, or Parts of States, without the Consent of the Legislatures of the States concerned as well as of the Congress.
204 |
205 | The Congress shall have Power to dispose of and make all needful Rules and Regulations respecting the Territory or other Property belonging to the United States; and nothing in this Constitution shall be so construed as to Prejudice any Claims of the United States, or of any particular State.
206 |
207 | Section. 4.
208 |
209 | The United States shall guarantee to every State in this Union a Republican Form of Government, and shall protect each of them against Invasion; and on Application of the Legislature, or of the Executive (when the Legislature cannot be convened), against domestic Violence.
210 |
211 | Article. V.
212 |
213 | The Congress, whenever two thirds of both Houses shall deem it necessary, shall propose Amendments to this Constitution, or, on the Application of the Legislatures of two thirds of the several States, shall call a Convention for proposing Amendments, which, in either Case, shall be valid to all Intents and Purposes, as Part of this Constitution, when ratified by the Legislatures of three fourths of the several States, or by Conventions in three fourths thereof, as the one or the other Mode of Ratification may be proposed by the Congress; Provided that no Amendment which may be made prior to the Year One thousand eight hundred and eight shall in any Manner affect the first and fourth Clauses in the Ninth Section of the first Article; and that no State, without its Consent, shall be deprived of its equal Suffrage in the Senate.
214 |
215 | Article. VI.
216 |
217 | All Debts contracted and Engagements entered into, before the Adoption of this Constitution, shall be as valid against the United States under this Constitution, as under the Confederation.
218 |
219 | This Constitution, and the Laws of the United States which shall be made in Pursuance thereof; and all Treaties made, or which shall be made, under the Authority of the United States, shall be the supreme Law of the Land; and the Judges in every State shall be bound thereby, any Thing in the Constitution or Laws of any State to the Contrary notwithstanding.
220 |
221 | The Senators and Representatives before mentioned, and the Members of the several State Legislatures, and all executive and judicial Officers, both of the United States and of the several States, shall be bound by Oath or Affirmation, to support this Constitution; but no religious Test shall ever be required as a Qualification to any Office or public Trust under the United States.
222 |
223 | Article. VII.
224 |
225 | The Ratification of the Conventions of nine States, shall be sufficient for the Establishment of this Constitution between the States so ratifying the Same.
226 |
227 | The Word, "the," being interlined between the seventh and eighth Lines of the first Page, the Word "Thirty" being partly written on an Erazure in the fifteenth Line of the first Page, The Words "is tried" being interlined between the thirty second and thirty third Lines of the first Page and the Word "the" being interlined between the forty third and forty fourth Lines of the second Page.
228 |
229 | Attest William Jackson Secretary
230 |
231 | done in Convention by the Unanimous Consent of the States present the Seventeenth Day of September in the Year of our Lord one thousand seven hundred and Eighty seven and of the Independance of the United States of America the Twelfth In witness whereof We have hereunto subscribed our Names,
--------------------------------------------------------------------------------
/PythonDemo/wordcloud/examples/constitution.txt:
--------------------------------------------------------------------------------
1 | We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.
2 |
3 | Article. I.
4 |
5 | Section. 1.
6 |
7 | All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives.
8 |
9 | Section. 2.
10 |
11 | The House of Representatives shall be composed of Members chosen every second Year by the People of the several States, and the Electors in each State shall have the Qualifications requisite for Electors of the most numerous Branch of the State Legislature.
12 |
13 | No Person shall be a Representative who shall not have attained to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State in which he shall be chosen.
14 |
15 | Representatives and direct Taxes shall be apportioned among the several States which may be included within this Union, according to their respective Numbers, which shall be determined by adding to the whole Number of free Persons, including those bound to Service for a Term of Years, and excluding Indians not taxed, three fifths of all other Persons. The actual Enumeration shall be made within three Years after the first Meeting of the Congress of the United States, and within every subsequent Term of ten Years, in such Manner as they shall by Law direct. The Number of Representatives shall not exceed one for every thirty Thousand, but each State shall have at Least one Representative; and until such enumeration shall be made, the State of New Hampshire shall be entitled to chuse three, Massachusetts eight, Rhode-Island and Providence Plantations one, Connecticut five, New-York six, New Jersey four, Pennsylvania eight, Delaware one, Maryland six, Virginia ten, North Carolina five, South Carolina five, and Georgia three.
16 |
17 | When vacancies happen in the Representation from any State, the Executive Authority thereof shall issue Writs of Election to fill such Vacancies.
18 |
19 | The House of Representatives shall chuse their Speaker and other Officers; and shall have the sole Power of Impeachment.
20 |
21 | Section. 3.
22 |
23 | The Senate of the United States shall be composed of two Senators from each State, chosen by the Legislature thereof for six Years; and each Senator shall have one Vote.
24 |
25 | Immediately after they shall be assembled in Consequence of the first Election, they shall be divided as equally as may be into three Classes. The Seats of the Senators of the first Class shall be vacated at the Expiration of the second Year, of the second Class at the Expiration of the fourth Year, and of the third Class at the Expiration of the sixth Year, so that one third may be chosen every second Year; and if Vacancies happen by Resignation, or otherwise, during the Recess of the Legislature of any State, the Executive thereof may make temporary Appointments until the next Meeting of the Legislature, which shall then fill such Vacancies.
26 |
27 | No Person shall be a Senator who shall not have attained to the Age of thirty Years, and been nine Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State for which he shall be chosen.
28 |
29 | The Vice President of the United States shall be President of the Senate, but shall have no Vote, unless they be equally divided.
30 |
31 | The Senate shall chuse their other Officers, and also a President pro tempore, in the Absence of the Vice President, or when he shall exercise the Office of President of the United States.
32 |
33 | The Senate shall have the sole Power to try all Impeachments. When sitting for that Purpose, they shall be on Oath or Affirmation. When the President of the United States is tried, the Chief Justice shall preside: And no Person shall be convicted without the Concurrence of two thirds of the Members present.
34 |
35 | Judgment in Cases of Impeachment shall not extend further than to removal from Office, and disqualification to hold and enjoy any Office of honor, Trust or Profit under the United States: but the Party convicted shall nevertheless be liable and subject to Indictment, Trial, Judgment and Punishment, according to Law.
36 |
37 | Section. 4.
38 |
39 | The Times, Places and Manner of holding Elections for Senators and Representatives, shall be prescribed in each State by the Legislature thereof; but the Congress may at any time by Law make or alter such Regulations, except as to the Places of chusing Senators.
40 |
41 | The Congress shall assemble at least once in every Year, and such Meeting shall be on the first Monday in December, unless they shall by Law appoint a different Day.
42 |
43 | Section. 5.
44 |
45 | Each House shall be the Judge of the Elections, Returns and Qualifications of its own Members, and a Majority of each shall constitute a Quorum to do Business; but a smaller Number may adjourn from day to day, and may be authorized to compel the Attendance of absent Members, in such Manner, and under such Penalties as each House may provide.
46 |
47 | Each House may determine the Rules of its Proceedings, punish its Members for disorderly Behaviour, and, with the Concurrence of two thirds, expel a Member.
48 |
49 | Each House shall keep a Journal of its Proceedings, and from time to time publish the same, excepting such Parts as may in their Judgment require Secrecy; and the Yeas and Nays of the Members of either House on any question shall, at the Desire of one fifth of those Present, be entered on the Journal.
50 |
51 | Neither House, during the Session of Congress, shall, without the Consent of the other, adjourn for more than three days, nor to any other Place than that in which the two Houses shall be sitting.
52 |
53 | Section. 6.
54 |
55 | The Senators and Representatives shall receive a Compensation for their Services, to be ascertained by Law, and paid out of the Treasury of the United States. They shall in all Cases, except Treason, Felony and Breach of the Peace, be privileged from Arrest during their Attendance at the Session of their respective Houses, and in going to and returning from the same; and for any Speech or Debate in either House, they shall not be questioned in any other Place.
56 |
57 | No Senator or Representative shall, during the Time for which he was elected, be appointed to any civil Office under the Authority of the United States, which shall have been created, or the Emoluments whereof shall have been encreased during such time; and no Person holding any Office under the United States, shall be a Member of either House during his Continuance in Office.
58 |
59 | Section. 7.
60 |
61 | All Bills for raising Revenue shall originate in the House of Representatives; but the Senate may propose or concur with Amendments as on other Bills.
62 |
63 | Every Bill which shall have passed the House of Representatives and the Senate, shall, before it become a Law, be presented to the President of the United States: If he approve he shall sign it, but if not he shall return it, with his Objections to that House in which it shall have originated, who shall enter the Objections at large on their Journal, and proceed to reconsider it. If after such Reconsideration two thirds of that House shall agree to pass the Bill, it shall be sent, together with the Objections, to the other House, by which it shall likewise be reconsidered, and if approved by two thirds of that House, it shall become a Law. But in all such Cases the Votes of both Houses shall be determined by yeas and Nays, and the Names of the Persons voting for and against the Bill shall be entered on the Journal of each House respectively. If any Bill shall not be returned by the President within ten Days (Sundays excepted) after it shall have been presented to him, the Same shall be a Law, in like Manner as if he had signed it, unless the Congress by their Adjournment prevent its Return, in which Case it shall not be a Law.
64 |
65 | Every Order, Resolution, or Vote to which the Concurrence of the Senate and House of Representatives may be necessary (except on a question of Adjournment) shall be presented to the President of the United States; and before the Same shall take Effect, shall be approved by him, or being disapproved by him, shall be repassed by two thirds of the Senate and House of Representatives, according to the Rules and Limitations prescribed in the Case of a Bill.
66 |
67 | Section. 8.
68 |
69 | The Congress shall have Power To lay and collect Taxes, Duties, Imposts and Excises, to pay the Debts and provide for the common Defence and general Welfare of the United States; but all Duties, Imposts and Excises shall be uniform throughout the United States;
70 |
71 | To borrow Money on the credit of the United States;
72 |
73 | To regulate Commerce with foreign Nations, and among the several States, and with the Indian Tribes;
74 |
75 | To establish an uniform Rule of Naturalization, and uniform Laws on the subject of Bankruptcies throughout the United States;
76 |
77 | To coin Money, regulate the Value thereof, and of foreign Coin, and fix the Standard of Weights and Measures;
78 |
79 | To provide for the Punishment of counterfeiting the Securities and current Coin of the United States;
80 |
81 | To establish Post Offices and post Roads;
82 |
83 | To promote the Progress of Science and useful Arts, by securing for limited Times to Authors and Inventors the exclusive Right to their respective Writings and Discoveries;
84 |
85 | To constitute Tribunals inferior to the supreme Court;
86 |
87 | To define and punish Piracies and Felonies committed on the high Seas, and Offences against the Law of Nations;
88 |
89 | To declare War, grant Letters of Marque and Reprisal, and make Rules concerning Captures on Land and Water;
90 |
91 | To raise and support Armies, but no Appropriation of Money to that Use shall be for a longer Term than two Years;
92 |
93 | To provide and maintain a Navy;
94 |
95 | To make Rules for the Government and Regulation of the land and naval Forces;
96 |
97 | To provide for calling forth the Militia to execute the Laws of the Union, suppress Insurrections and repel Invasions;
98 |
99 | To provide for organizing, arming, and disciplining, the Militia, and for governing such Part of them as may be employed in the Service of the United States, reserving to the States respectively, the Appointment of the Officers, and the Authority of training the Militia according to the discipline prescribed by Congress;
100 |
101 | To exercise exclusive Legislation in all Cases whatsoever, over such District (not exceeding ten Miles square) as may, by Cession of particular States, and the Acceptance of Congress, become the Seat of the Government of the United States, and to exercise like Authority over all Places purchased by the Consent of the Legislature of the State in which the Same shall be, for the Erection of Forts, Magazines, Arsenals, dock-Yards, and other needful Buildings;--And
102 |
103 | To make all Laws which shall be necessary and proper for carrying into Execution the foregoing Powers, and all other Powers vested by this Constitution in the Government of the United States, or in any Department or Officer thereof.
104 |
105 | Section. 9.
106 |
107 | The Migration or Importation of such Persons as any of the States now existing shall think proper to admit, shall not be prohibited by the Congress prior to the Year one thousand eight hundred and eight, but a Tax or duty may be imposed on such Importation, not exceeding ten dollars for each Person.
108 |
109 | The Privilege of the Writ of Habeas Corpus shall not be suspended, unless when in Cases of Rebellion or Invasion the public Safety may require it.
110 |
111 | No Bill of Attainder or ex post facto Law shall be passed.
112 |
113 | No Capitation, or other direct, Tax shall be laid, unless in Proportion to the Census or enumeration herein before directed to be taken.
114 |
115 | No Tax or Duty shall be laid on Articles exported from any State.
116 |
117 | No Preference shall be given by any Regulation of Commerce or Revenue to the Ports of one State over those of another; nor shall Vessels bound to, or from, one State, be obliged to enter, clear, or pay Duties in another.
118 |
119 | No Money shall be drawn from the Treasury, but in Consequence of Appropriations made by Law; and a regular Statement and Account of the Receipts and Expenditures of all public Money shall be published from time to time.
120 |
121 | No Title of Nobility shall be granted by the United States: And no Person holding any Office of Profit or Trust under them, shall, without the Consent of the Congress, accept of any present, Emolument, Office, or Title, of any kind whatever, from any King, Prince, or foreign State.
122 |
123 | Section. 10.
124 |
125 | No State shall enter into any Treaty, Alliance, or Confederation; grant Letters of Marque and Reprisal; coin Money; emit Bills of Credit; make any Thing but gold and silver Coin a Tender in Payment of Debts; pass any Bill of Attainder, ex post facto Law, or Law impairing the Obligation of Contracts, or grant any Title of Nobility.
126 |
127 | No State shall, without the Consent of the Congress, lay any Imposts or Duties on Imports or Exports, except what may be absolutely necessary for executing it's inspection Laws: and the net Produce of all Duties and Imposts, laid by any State on Imports or Exports, shall be for the Use of the Treasury of the United States; and all such Laws shall be subject to the Revision and Controul of the Congress.
128 |
129 | No State shall, without the Consent of Congress, lay any Duty of Tonnage, keep Troops, or Ships of War in time of Peace, enter into any Agreement or Compact with another State, or with a foreign Power, or engage in War, unless actually invaded, or in such imminent Danger as will not admit of delay.
130 |
131 | Article. II.
132 |
133 | Section. 1.
134 |
135 | The executive Power shall be vested in a President of the United States of America. He shall hold his Office during the Term of four Years, and, together with the Vice President, chosen for the same Term, be elected, as follows:
136 |
137 | Each State shall appoint, in such Manner as the Legislature thereof may direct, a Number of Electors, equal to the whole Number of Senators and Representatives to which the State may be entitled in the Congress: but no Senator or Representative, or Person holding an Office of Trust or Profit under the United States, shall be appointed an Elector.
138 |
139 | The Electors shall meet in their respective States, and vote by Ballot for two Persons, of whom one at least shall not be an Inhabitant of the same State with themselves. And they shall make a List of all the Persons voted for, and of the Number of Votes for each; which List they shall sign and certify, and transmit sealed to the Seat of the Government of the United States, directed to the President of the Senate. The President of the Senate shall, in the Presence of the Senate and House of Representatives, open all the Certificates, and the Votes shall then be counted. The Person having the greatest Number of Votes shall be the President, if such Number be a Majority of the whole Number of Electors appointed; and if there be more than one who have such Majority, and have an equal Number of Votes, then the House of Representatives shall immediately chuse by Ballot one of them for President; and if no Person have a Majority, then from the five highest on the List the said House shall in like Manner chuse the President. But in chusing the President, the Votes shall be taken by States, the Representation from each State having one Vote; A quorum for this purpose shall consist of a Member or Members from two thirds of the States, and a Majority of all the States shall be necessary to a Choice. In every Case, after the Choice of the President, the Person having the greatest Number of Votes of the Electors shall be the Vice President. But if there should remain two or more who have equal Votes, the Senate shall chuse from them by Ballot the Vice President.
140 |
141 | The Congress may determine the Time of chusing the Electors, and the Day on which they shall give their Votes; which Day shall be the same throughout the United States.
142 |
143 | No Person except a natural born Citizen, or a Citizen of the United States, at the time of the Adoption of this Constitution, shall be eligible to the Office of President; neither shall any Person be eligible to that Office who shall not have attained to the Age of thirty five Years, and been fourteen Years a Resident within the United States.
144 |
145 | In Case of the Removal of the President from Office, or of his Death, Resignation, or Inability to discharge the Powers and Duties of the said Office, the Same shall devolve on the Vice President, and the Congress may by Law provide for the Case of Removal, Death, Resignation or Inability, both of the President and Vice President, declaring what Officer shall then act as President, and such Officer shall act accordingly, until the Disability be removed, or a President shall be elected.
146 |
147 | The President shall, at stated Times, receive for his Services, a Compensation, which shall neither be increased nor diminished during the Period for which he shall have been elected, and he shall not receive within that Period any other Emolument from the United States, or any of them.
148 |
149 | Before he enter on the Execution of his Office, he shall take the following Oath or Affirmation:--"I do solemnly swear (or affirm) that I will faithfully execute the Office of President of the United States, and will to the best of my Ability, preserve, protect and defend the Constitution of the United States."
150 |
151 | Section. 2.
152 |
153 | The President shall be Commander in Chief of the Army and Navy of the United States, and of the Militia of the several States, when called into the actual Service of the United States; he may require the Opinion, in writing, of the principal Officer in each of the executive Departments, upon any Subject relating to the Duties of their respective Offices, and he shall have Power to grant Reprieves and Pardons for Offences against the United States, except in Cases of Impeachment.
154 |
155 | He shall have Power, by and with the Advice and Consent of the Senate, to make Treaties, provided two thirds of the Senators present concur; and he shall nominate, and by and with the Advice and Consent of the Senate, shall appoint Ambassadors, other public Ministers and Consuls, Judges of the supreme Court, and all other Officers of the United States, whose Appointments are not herein otherwise provided for, and which shall be established by Law: but the Congress may by Law vest the Appointment of such inferior Officers, as they think proper, in the President alone, in the Courts of Law, or in the Heads of Departments.
156 |
157 | The President shall have Power to fill up all Vacancies that may happen during the Recess of the Senate, by granting Commissions which shall expire at the End of their next Session.
158 |
159 | Section. 3.
160 |
161 | He shall from time to time give to the Congress Information of the State of the Union, and recommend to their Consideration such Measures as he shall judge necessary and expedient; he may, on extraordinary Occasions, convene both Houses, or either of them, and in Case of Disagreement between them, with Respect to the Time of Adjournment, he may adjourn them to such Time as he shall think proper; he shall receive Ambassadors and other public Ministers; he shall take Care that the Laws be faithfully executed, and shall Commission all the Officers of the United States.
162 |
163 | Section. 4.
164 |
165 | The President, Vice President and all civil Officers of the United States, shall be removed from Office on Impeachment for, and Conviction of, Treason, Bribery, or other high Crimes and Misdemeanors.
166 |
167 | Article III.
168 |
169 | Section. 1.
170 |
171 | The judicial Power of the United States shall be vested in one supreme Court, and in such inferior Courts as the Congress may from time to time ordain and establish. The Judges, both of the supreme and inferior Courts, shall hold their Offices during good Behaviour, and shall, at stated Times, receive for their Services a Compensation, which shall not be diminished during their Continuance in Office.
172 |
173 | Section. 2.
174 |
175 | The judicial Power shall extend to all Cases, in Law and Equity, arising under this Constitution, the Laws of the United States, and Treaties made, or which shall be made, under their Authority;--to all Cases affecting Ambassadors, other public Ministers and Consuls;--to all Cases of admiralty and maritime Jurisdiction;--to Controversies to which the United States shall be a Party;--to Controversies between two or more States;-- between a State and Citizens of another State,--between Citizens of different States,--between Citizens of the same State claiming Lands under Grants of different States, and between a State, or the Citizens thereof, and foreign States, Citizens or Subjects.
176 |
177 | In all Cases affecting Ambassadors, other public Ministers and Consuls, and those in which a State shall be Party, the supreme Court shall have original Jurisdiction. In all the other Cases before mentioned, the supreme Court shall have appellate Jurisdiction, both as to Law and Fact, with such Exceptions, and under such Regulations as the Congress shall make.
178 |
179 | The Trial of all Crimes, except in Cases of Impeachment, shall be by Jury; and such Trial shall be held in the State where the said Crimes shall have been committed; but when not committed within any State, the Trial shall be at such Place or Places as the Congress may by Law have directed.
180 |
181 | Section. 3.
182 |
183 | Treason against the United States, shall consist only in levying War against them, or in adhering to their Enemies, giving them Aid and Comfort. No Person shall be convicted of Treason unless on the Testimony of two Witnesses to the same overt Act, or on Confession in open Court.
184 |
185 | The Congress shall have Power to declare the Punishment of Treason, but no Attainder of Treason shall work Corruption of Blood, or Forfeiture except during the Life of the Person attainted.
186 |
187 | Article. IV.
188 |
189 | Section. 1.
190 |
191 | Full Faith and Credit shall be given in each State to the public Acts, Records, and judicial Proceedings of every other State. And the Congress may by general Laws prescribe the Manner in which such Acts, Records and Proceedings shall be proved, and the Effect thereof.
192 |
193 | Section. 2.
194 |
195 | The Citizens of each State shall be entitled to all Privileges and Immunities of Citizens in the several States.
196 |
197 | A Person charged in any State with Treason, Felony, or other Crime, who shall flee from Justice, and be found in another State, shall on Demand of the executive Authority of the State from which he fled, be delivered up, to be removed to the State having Jurisdiction of the Crime.
198 |
199 | No Person held to Service or Labour in one State, under the Laws thereof, escaping into another, shall, in Consequence of any Law or Regulation therein, be discharged from such Service or Labour, but shall be delivered up on Claim of the Party to whom such Service or Labour may be due.
200 |
201 | Section. 3.
202 |
203 | New States may be admitted by the Congress into this Union; but no new State shall be formed or erected within the Jurisdiction of any other State; nor any State be formed by the Junction of two or more States, or Parts of States, without the Consent of the Legislatures of the States concerned as well as of the Congress.
204 |
205 | The Congress shall have Power to dispose of and make all needful Rules and Regulations respecting the Territory or other Property belonging to the United States; and nothing in this Constitution shall be so construed as to Prejudice any Claims of the United States, or of any particular State.
206 |
207 | Section. 4.
208 |
209 | The United States shall guarantee to every State in this Union a Republican Form of Government, and shall protect each of them against Invasion; and on Application of the Legislature, or of the Executive (when the Legislature cannot be convened), against domestic Violence.
210 |
211 | Article. V.
212 |
213 | The Congress, whenever two thirds of both Houses shall deem it necessary, shall propose Amendments to this Constitution, or, on the Application of the Legislatures of two thirds of the several States, shall call a Convention for proposing Amendments, which, in either Case, shall be valid to all Intents and Purposes, as Part of this Constitution, when ratified by the Legislatures of three fourths of the several States, or by Conventions in three fourths thereof, as the one or the other Mode of Ratification may be proposed by the Congress; Provided that no Amendment which may be made prior to the Year One thousand eight hundred and eight shall in any Manner affect the first and fourth Clauses in the Ninth Section of the first Article; and that no State, without its Consent, shall be deprived of its equal Suffrage in the Senate.
214 |
215 | Article. VI.
216 |
217 | All Debts contracted and Engagements entered into, before the Adoption of this Constitution, shall be as valid against the United States under this Constitution, as under the Confederation.
218 |
219 | This Constitution, and the Laws of the United States which shall be made in Pursuance thereof; and all Treaties made, or which shall be made, under the Authority of the United States, shall be the supreme Law of the Land; and the Judges in every State shall be bound thereby, any Thing in the Constitution or Laws of any State to the Contrary notwithstanding.
220 |
221 | The Senators and Representatives before mentioned, and the Members of the several State Legislatures, and all executive and judicial Officers, both of the United States and of the several States, shall be bound by Oath or Affirmation, to support this Constitution; but no religious Test shall ever be required as a Qualification to any Office or public Trust under the United States.
222 |
223 | Article. VII.
224 |
225 | The Ratification of the Conventions of nine States, shall be sufficient for the Establishment of this Constitution between the States so ratifying the Same.
226 |
227 | The Word, "the," being interlined between the seventh and eighth Lines of the first Page, the Word "Thirty" being partly written on an Erazure in the fifteenth Line of the first Page, The Words "is tried" being interlined between the thirty second and thirty third Lines of the first Page and the Word "the" being interlined between the forty third and forty fourth Lines of the second Page.
228 |
229 | Attest William Jackson Secretary
230 |
231 | done in Convention by the Unanimous Consent of the States present the Seventeenth Day of September in the Year of our Lord one thousand seven hundred and Eighty seven and of the Independance of the United States of America the Twelfth In witness whereof We have hereunto subscribed our Names,
232 |
--------------------------------------------------------------------------------