Created
November 20, 2012 09:25
-
-
Save Wizmann/4116938 to your computer and use it in GitHub Desktop.
Renren Timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #coding=utf-8 | |
| import urllib | |
| import urllib2 | |
| import cookielib | |
| import re | |
| import time | |
| import os,sys | |
| import socket | |
| import sqlite3 | |
| def getCookieToken(): | |
| sql_query='SELECT value FROM cookies WHERE host_key=\'.renren.com\' and name=\'t\' and length(value)=33;' | |
| sql_path=os.path.join(os.path.expanduser('~'),'.config/google-chrome/Default/Cookies') | |
| conn=sqlite3.connect(sql_path) | |
| cursor=conn.cursor() | |
| cursor.execute(sql_query) | |
| return cursor.fetchall()[0][0] | |
| def status(status,token,rtk,myid,cookie): | |
| #发布状态 | |
| params = {'content':status,'hostid':myid,'requestToken':token,'channel':'renren','_rtk':rtk} | |
| # 进行编码,并请求 | |
| req = urllib2.Request( | |
| 'http://shell.renren.com/'+myid+'/status', | |
| urllib.urlencode(params) | |
| ) | |
| req.add_header('Cookie', cookie) | |
| content = urllib2.urlopen(req,timeout=10).read() | |
| def show(now_time): | |
| with open("renren_log.txt",'a') as MrLog: | |
| MrLog.write('-'*80+'\n'+now_time+'\n') | |
| try: | |
| cookie = "t="+getCookieToken()+";" | |
| except: | |
| MrLog.write("Chrome Sqlite Database Load Error\n") | |
| exit(0) | |
| try: | |
| opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) | |
| urllib2.install_opener(opener) | |
| req = urllib2.Request("http://friend.renren.com/myfriendlistx.do#item_0") | |
| req.add_header('Cookie', cookie) | |
| content = urllib2.urlopen(req).read() | |
| myid = "330844449" | |
| token = re.findall('get_check:\'[\d-]*\'?',content)[0].split(':')[1].strip('\'') | |
| rtk = re.findall('get_check_x:\'.*?\'',content)[0].split(':')[1].strip('\'') | |
| except: | |
| MrLog.write("Renren Page Load Error\n") | |
| exit(0) | |
| #with open("page.html", "w") as f: | |
| # f.write(content) | |
| try: | |
| status(now_time,token,rtk,myid,cookie) | |
| except: | |
| MrLog.write("Send Status Error") | |
| exit(0) | |
| MrLog.write('OK') | |
| def get_now_time(): | |
| return time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time())) | |
| if(__name__=='__main__'): | |
| show(get_now_time()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment