python 实现 自动定时发送人人状态

简介:
2013.9.20  因为人人改版,可能已无法使用
 
 
#-*- coding:UTF-8 -*-
'''
======================================
此程序根据 http://www.oschina.net/code/snippet_946076_17870 内容改编
Adapted BY: jxy
Mail:czjxy8898@gmail.com
======================================
'''
from sgmllib import SGMLParser
import sys,urllib2,urllib,cookielib
import datetime
import time
class spider(SGMLParser):
    def __init__(self,email,password):
        SGMLParser.__init__(self)
        self.h3=False
        self.h3_is_ready=False
        self.div=False
        self.h3_and_div=False
        self.a=False
        self.depth=0
        self.names=""
        self.dic={}   
         
        self.email=email
        self.password=password
        self.domain='renren.com'
        try:
            cookie=cookielib.CookieJar()
            cookieProc=urllib2.HTTPCookieProcessor(cookie)
        except:
            raise
        else:
            opener=urllib2.build_opener(cookieProc)
            urllib2.install_opener(opener)       

    def login(self):
        print 'start login'
        url='http://www.renren.com/PLogin.do'
        postdata={
                  'email':self.email,
                  'password':self.password,
                  'domain':self.domain  
                  }
        try:
          req=urllib2.Request(
                            url,
                            urllib.urlencode(postdata)
                            )
          self.file=urllib2.urlopen(req).read()
          idPos = self.file.index("'id':'")
          self.id=self.file[idPos+6:idPos+15]
          tokPos=self.file.index("get_check:'")
          self.tok=self.file[tokPos+11:tokPos+21]
          rtkPos=self.file.index("get_check_x:'")
          self.rtk=self.file[rtkPos+13:rtkPos+21]
          print 'success'
          return 1
        except:
          print 'error'
          return 0


    def publish(self,content):
        url1='http://shell.renren.com/'+self.id+'/status'
        postdata={
                  'content':content,
                  'hostid':self.id,
                  'requestToken':self.tok,
                  '_rtk':self.rtk,
                  'channel':'renren',
                  }
        req1=urllib2.Request(
                            url1,
                            urllib.urlencode(postdata)            
                            )
        self.file1=urllib2.urlopen(req1).read()
        print '%s:\n  %s have sended\n:(%s)'% (datetime.datetime.now(),self.email,postdata.get('content',''))

def tt(T=5):
  while 1:
    t = time.localtime()
    content='24小时测试:现在时间'+str(t.tm_hour)+'时'+str(t.tm_min)+'分'+str(t.tm_sec)+'秒'
    print content
    renrenspider.publish(content)
    time.sleep(60)
    T=T-1
    if T==0:
      break
user=raw_input('email or phone number:')
password=raw_input('password:')
renrenspider=spider(user,password)
if renrenspider.login() :
  #content=raw_input('please input content:')
 # renrenspider.publish(content.decode('gb2312').encode('utf-8'))

  while 1:
   if time.localtime().tm_sec==0 and time.localtime().tm_min==0:
      tt(24)
      break
   time.sleep(1)


目录
相关文章
|
7月前
|
监控 安全 机器人
通过GitHub Actions给微信公众测试号和钉钉群定时推送消息(Python)
通过GitHub Actions给微信公众测试号和钉钉群定时推送消息(Python)
127 0
|
22天前
|
运维 算法 jenkins
做一个可通过jenkins定时任务Cron表达式设置的python定时函数
用python代码,来解析jenkins定时任务表达式,并获取最近的执行任务时间戳
|
1月前
|
API Python
做一个合格的男友,用python制作每天定时给女朋友发送邮箱问候
做一个合格的男友,用python制作每天定时给女朋友发送邮箱问候
|
1月前
|
Linux Shell 调度
linux服务器定时执行python程序
linux服务器定时执行python程序
461 0
|
9月前
|
Python
用Python实现定时自动化收取蚂蚁森林能量,再也不用担心忘记收取了
用Python实现定时自动化收取蚂蚁森林能量,再也不用担心忘记收取了
314 2
用Python实现定时自动化收取蚂蚁森林能量,再也不用担心忘记收取了
|
9月前
|
Linux Shell Python
crontab定时执行python脚本不成功解决方案
crontab定时执行python脚本不成功解决方案
|
10月前
|
数据采集 Python
技巧 | python定时发送邮件(自动添加附件)针不戳
技巧 | python定时发送邮件(自动添加附件)针不戳
技巧 | python定时发送邮件(自动添加附件)针不戳
Python print() 打印两个 list ,实现中间换行
Python print() 打印两个 list ,实现中间换行
|
10月前
|
Python
女友让我每天半夜十二点给她发晚安?我用 Python 做了个定时发消息神器!怕她干嘛!
女友让我每天半夜十二点给她发晚安?我用 Python 做了个定时发消息神器!怕她干嘛!
121 0
|
jenkins 测试技术 持续交付
【实测】python模拟jenkins的定时设置时间库: 【 python_jenkins_monitor 】
【实测】python模拟jenkins的定时设置时间库: 【 python_jenkins_monitor 】

热门文章

最新文章