{"id":46001,"date":"2010-11-24T13:08:29","date_gmt":"2010-11-24T05:08:29","guid":{"rendered":"\/?p=46001"},"modified":"2014-03-14T02:30:19","modified_gmt":"2014-03-13T18:30:19","slug":"python%e5%86%99%e7%9a%84%e6%a0%a1%e5%86%85%e4%ba%ba%e4%ba%ba%e8%87%aa%e5%8a%a8%e5%8f%91%e7%8a%b6%e6%80%81%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/yangzhe1991.org\/blog\/2010\/11\/python%e5%86%99%e7%9a%84%e6%a0%a1%e5%86%85%e4%ba%ba%e4%ba%ba%e8%87%aa%e5%8a%a8%e5%8f%91%e7%8a%b6%e6%80%81%e8%84%9a%e6%9c%ac\/","title":{"rendered":"python\u5199\u7684\u6821\u5185\/\u4eba\u4eba\u81ea\u52a8\u53d1\u72b6\u6001\u811a\u672c"},"content":{"rendered":"<p><span style=\"font-size: medium;\">\u5fc3\u8840\u6765\u6f6e\u5199\u4e86\u4e2a\u8fd9\u4e48\u4e00\u4e2a\u4e1c\u897f\uff0c\u5c31\u5f53\u662f\u4e3apy\u7ec3\u7ec3\u624b\u4e86\u3002\u6700\u4e0d\u4e60\u60ef\u7684\u5730\u65b9\u5c31\u662f\u5192\u53f7&hellip;&hellip;<\/span><\/p>\n<p><span style=\"font-size: medium;\">\u76ee\u524d\u5c31\u662f\u8fd9\u6837\uff0c\u6838\u5fc3\u4ee3\u7801\u5176\u5b9e\u5c3120\u591a\u884c\uff0c\u7528\u4e8e\u53d1\u72b6\u6001<\/span><\/p>\n<p><span style=\"font-size: medium;\">\uff01\uff01\uff01\u4e0d\u8bb2\u4efb\u4f55\u7f16\u7801\u89c4\u8303\uff01\uff01\uff01\u4e0d\u8bb2\u4efb\u4f55py\u4e60\u4fd7\uff01\uff01\uff01\u4e0d\u8bb2\u4efb\u4f55\u7b80\u5355\u65b9\u6cd5\uff01\uff01\uff01\u4e0d\u8bb2\u4efb\u4f55\u590d\u6742\u6d4b\u8bd5\uff01\uff01\uff01<\/span><\/p>\n<p><span style=\"font-size: medium;\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;poststatus.py&#8212;&#8212;&#8212;&#8212;-<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: python;fontsize: 100; first-line: 1; \"><span style=\"font-size: x-small;\"># coding=utf-8\n\nimport urllib\n\nimport urllib2\n\nimport cookielib\n\nimport sys\n\nxn={}\n\nxn['email']='\u4f60\u61c2\u7684'\n\nxn['password']='\u4f60\u4e5f\u61c2\u7684'\n\ncookie=cookielib.CookieJar()\n\nopener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))\n\nurllib2.install_opener(opener)\n\nzhanghao = urllib.urlencode(xn)\n\nreq=urllib2.Request('http:\/\/3g.renren.com\/login.do?fx=0&amp;autoLogin=true',zhanghao)\n\nresp=urllib2.urlopen(req)\n\n#print resp.read()\n\ndef zhuangtai(sss):\n\n\txn2={}\n\n\txn2['status']=sss\n\n\txn2['update']=\"\u53d1\u5e03\"\n\n\tzhuangtai=urllib.urlencode(xn2)\n\n\treq2=urllib2.Request('http:\/\/3g.renren.com\/status\/wUpdateStatus.do',zhuangtai)\n\n\tprint sss\n\n\tresp2=urllib2.urlopen(req2)<\/span><\/pre>\n<p><span style=\"font-size: x-small;\"><br \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: medium;\"><br \/><\/span><\/p>\n<p><span style=\"font-size: medium;\">\u4e4b\u6240\u4ee5\u75283g\u800c\u4e0d\u662fwww\u7684\u539f\u56e0\u524d\u6587\u5df2\u7ecf\u8bb2\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: medium;\"><br \/><\/span><\/p>\n<p><span style=\"font-size: medium;\">&#8212;&#8212;&#8212;&#8212;-renren.py&#8212;&#8212;&#8212;&#8212;&#8212;-\u4e3b\u7a0b\u5e8f&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: python;fontsize: 100; first-line: 1; \"><span style=\"font-size: x-small;\">#!\/usr\/bin\/python\n\n# coding=utf-8\n\nimport poststatus\n\nimport time\n\nimport hourstatus\n\nimport thread\n\nimport getstatus\n\n#poststatus.zhuangtai('test')\n\ndef hoursleep():\n\n\tt=time.localtime()\n\n\t#print t[4]\n\n\tif t[4]==59:\n\n\t\th=t[3]\n\n\t\tif h==23:\n\n\t\t\th=0\n\n\t\telse:\n\n\t\t\th+=1\n\n\t\tpoststatus.zhuangtai('\u4e0b\u9762\u662f\u673a\u5668\u4eba\u6574\u70b9\u62a5\u65f6\u65f6\u95f4\uff1a'+hourstatus.s[t[3]])\n\n\ttime.sleep(60)\n\n\thoursleep()\n\ndef rtsleep():\n\n\tgetstatus.zhuanfa()\n\n\ttime.sleep(60)\n\n\trtsleep()\n\n\n\n\n\nprint '\u6b22\u8fce\u6253\u5f00\u60a8\u7684\u673a\u5668\u4eba,\u60a8\u53ef\u4ee5\u968f\u65f6\u8f93\u5165\u547d\u4ee4\u3002exit\u9000\u51fa\uff0cpost\u53d1\u4efb\u610f\u72b6\u6001'\n\nthread.start_new_thread(hoursleep,())\n\nthread.start_new_thread(rtsleep,())\n\nprint '\u81ea\u52a8\u62a5\u65f6\u6a21\u5757\u5df2\u52a0\u8f7d'\n\nwhile 1==1:\n\n\tstdin=raw_input('shell:')\n\n\tif stdin=='exit':\n\n\t\texit()\n\n\tif stdin=='post':\n\n\t\twhile stdin!='robot' and stdin!='man':\n\n\t\t\tstdin=raw_input('\u8c01\u5728\u8bf4\u8bdd\uff1f(robot\/man)')\n\n\t\tif stdin=='robot':\n\n\t\t\tstdin=raw_input('\u6211\u60f3\u8bf4\u4ec0\u4e48\uff1f')\n\n\t\t\tpoststatus.zhuangtai(stdin)\n\n\t\telse:\n\n\t\t\tstdin=raw_input('\u60a8\u60f3\u8bf4\u561b\uff1f')\n\n\t\t\tpoststatus.zhuangtai('\u6211\u4e3b\u4eba\u8bf4\uff1a'+stdin)\n\n\t\tcontinue<\/span><\/pre>\n<p><span style=\"font-size: x-small;\"><br \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: medium;\">\u76f4\u63a5\u8fd0\u884c\u5c31\u53ef\u4ee5<\/span><\/p>\n<p><span style=\"font-size: medium;\"><br \/><\/span><\/p>\n<p><span style=\"font-size: medium;\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;getstatus.py&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush: python;fontsize: 100; first-line: 1; \"><span style=\"font-size: x-small;\"># coding=utf-8\n\nimport urllib\n\nimport urllib2\n\nimport cookielib\n\nimport sys\n\nimport poststatus\n\nimport time\n\ndef zhuanfa():\n\n\txn={}\n\n\txn['email']='\u4f60\u61c2\u7684'\n\n\txn['password']='\u4f60\u4e5f\u61c2\u7684'\n\n\tcookie=cookielib.CookieJar()\n\n\topener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))\n\n\turllib2.install_opener(opener)\n\n\tzhanghao = urllib.urlencode(xn)\n\n\treq=urllib2.Request('http:\/\/3g.renren.com\/login.do?fx=0&amp;autoLogin=true',zhanghao)\n\n\tresp=urllib2.urlopen(req)\n\n\thtml=resp.read()\n\n\t#print len(html)\n\n\tindex=html.find('\u8f6c\u81ea')\n\n\twhile index&gt;0:\n\n\t\thtml=html[index:]\n\n\t\tindex2=html.find('&lt;p')\n\n\t\tsss=html[:index2-1]\n\n\t\tfw=open('zhuanfa.db','a')\n\n\t\tfr=open('zhuanfa.db','r')\n\n\t\talllines=fr.readlines()\n\n\t\tfr.close()\n\n\t\tboo=1\n\n\t\tfor each in alllines:\n\n\t\t\tif sss.find(each[len(each)\/2:len(each)\/3*2])&gt;0:\n\n\t\t\t\tboo=0\n\n\t\tif boo&gt;0:\n\n\t\t\tpoststatus.zhuangtai('\u81ea\u52a8\u8f6c\u53d1:'+sss)\n\n\t\t\tfw.write('n'+sss+'n')\n\n\t\telse:\n\n\t\t\tprint '\u53d1\u73b0\u8f6c\u53d1\u8fc7\u7684\u72b6\u6001'\n\n\t\tindex=html.find('\u8f6c\u81ea')<\/span><\/pre>\n<p><span style=\"font-size: x-small;\"><br \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: medium;\"><br \/><\/span><\/p>\n<p><span style=\"font-size: medium;\">\u539f\u7406\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u626b\u63cf\u4e00\u904d\u624b\u673a\u4eba\u4eba\u4e3b\u9875\u7684\u7b2c\u4e00\u9875\uff0c\u53ea\u8981\u662f\u6709&ldquo;\u8f6c\u81ea&rdquo;\u5c31\u622a\u53d6\u4e0b\u6765\uff0c\u8ddf\u5b58\u50a8\u7684\u6587\u4ef6\u6bd4\u5bf9\uff0c\u5982\u679c\u6ca1\u6709\u8f6c\u53d1\u8fc7\u5c31\u8f6c\u51fa\u53bb\u5e76\u5b58\u6863\u3002\u4e0d\u5b58\u6863\u7684\u540e\u679c\u662f\u663e\u800c\u6613\u89c1\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: medium;\"><br \/><\/span><\/p>\n<p><span style=\"font-size: medium;\">\u8fd8\u6709\u4e00\u4e2ahourstatus.py\uff0c\u91cc\u9762\u5c31\u662f\u5b58\u4e8624\u4e2a\u6574\u70b9\u62a5\u65f6\u673a\u5668\u4eba\u8981\u8bf4\u7684\u8bdd\uff0c\u6ca1\u522b\u7684<\/span><\/p>\n<p><span style=\"font-size: medium;\">====================================<\/span><\/p>\n<p><span style=\"font-size: medium;\">\u63a5\u4e0b\u6765\u7684\u8ba1\u5212\u662f\u5199\u6210\u771f\u6b63\u7684\u722c\u866b\uff0c\u80fd\u6df1\u5165\u641c\u7d22\u4ec0\u4e48\u7684\u3002\u53ef\u4ee5\u5efa\u7acb\u4e00\u4e2a\u597d\u53cb\u7684\u5173\u7cfb\u7f51\u4ec0\u4e48\u7684\u3002\u90a3\u662f\u4ee5\u540e\u7684\u4e8b\u60c5\u4e86\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5fc3\u8840\u6765\u6f6e\u5199\u4e86\u4e2a\u8fd9\u4e48\u4e00\u4e2a\u4e1c\u897f\uff0c\u5c31\u5f53\u662f\u4e3apy\u7ec3\u7ec3\u624b\u4e86\u3002\u6700\u4e0d\u4e60\u60ef\u7684\u5730\u65b9\u5c31\u662f\u5192\u53f7&hellip;&hellip; \u76ee\u524d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[18],"_links":{"self":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/46001"}],"collection":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/comments?post=46001"}],"version-history":[{"count":1,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/46001\/revisions"}],"predecessor-version":[{"id":224533,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/posts\/46001\/revisions\/224533"}],"wp:attachment":[{"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/media?parent=46001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/categories?post=46001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yangzhe1991.org\/blog\/wp-json\/wp\/v2\/tags?post=46001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}