Beispiel #1
0
def run():
		#调用initclietn模块创建授权的client对象
	client = initclient.get_client(APP_KEY, APP_SECRET, CALL_BACK)
	if not client:
			return

	UID = [1698194380, 1038819010] #ffice weibo stefwoo=1038819010
	since_id = 0 # message which is catch  must late than since_id 
	# message_id = 0
	#COUNT = 10 #count is the max of message
	loop = 1
	while True:
		r = []
		# try:
		r = client.statuses.friends_timeline.get(trim_user = 1, since_id = since_id)
        #, count = COUNT)
		if r.statuses:
			since_id = r.statuses[0].id
			for message in r.statuses:
				if message.uid in UID:# and (message.id > message_id):
					# try:
					send_mail(mailto_list,"weibo has a new blog",message.text.encode('gb2312'))
					print "A new message found!"
					# except:
						# print "send mail failed : ", sys.exc_info()
					break            
		# except:
		# 	print "Unexpected error:", sys.exc_info()
		print "Loop  : %d, Time : %s , since_id : %d " % (loop, str(time.ctime()), since_id)
		loop = loop + 1
		time.sleep(60)
Beispiel #2
0
def run():
    # 调用initclietn模块创建授权的client对象
    client = initclient.get_client(APP_KEY, APP_SECRET, CALL_BACK)
    reload(sys)
    sys.setdefaultencoding('utf8')
    if not client:
        print 'client 不存在!!!!'
        return

        # 根据用户输入内容发微博
    while True:
        #print "Ready! Do you want to send a new weibo?(y/n)"
        #choice = raw_input()
        #time.sleep(600)
        choice = 'y'
        if choice == 'y' or choice == 'Y':
            #content = raw_input('input the your new weibo content : ')
            spider = qiubai.Spider_QSBK()
            temStr = spider.start()
            content = '[糗事百科]%s 现在北京时间是:%s  ---自动发送 [黑线]' % (
                temStr, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
            if len(content) > 140:
                content = content[0:139]
            if content:
                client.statuses.update.post(
                    status=content
                )  #,pic= open('/Users/hukezhu/PycharmProjects/python/sendweibo/123.jpeg' ,'rb'))
                print "Send succesfully!"
                break
                #continue
            else:
                print "Error! Empty content!"
        if choice == 'n' or choice == 'N':
            break
Beispiel #3
0
def fetch_user_timeline():
    client = initclient.get_client()
    if not client:
        print 'Get client Error!'
        return
    r = client.statuses.user_timeline.get()
    for st in r.statuses:
        print st.text
Beispiel #4
0
def fetch_public_timeline():
    client = initclient.get_client()
    if not client:
        print 'Get client Error!'
        return
    r = client.statuses.public_timeline.get(count=20)
    for st in r.statuses:
        print st.text
Beispiel #5
0
def fetch_user_timeline():
    client = initclient.get_client()
    if not client:
        print 'Get client Error!'
        return
    r = client.statuses.user_timeline.get()
    for st in r.statuses:
        print st.text
Beispiel #6
0
def fetch_public_timeline():
    client = initclient.get_client()
    if not client:
        print 'Get client Error!'
        return  
    r = client.statuses.public_timeline.get(count=20)
    for st in r.statuses:
        print st.text       
def run():
    client = initclient.get_client(APP_KEY, APP_SECRET, CALL_BACK)

    while True:
        print "Ready! Do you want to send a new weibo?(y/n)"
        choice = raw_input()
        if choice == 'y' or choice == 'Y':
            content = raw_input('input the your new weibo content : ')
            if content:
                client.statuses.update.post(status=content)
                print "Send succesfully!"
                break
            else:
                print "Error! Empty content!"
        if choice == 'n' or choice == 'N':
            break
def run():
    client = initclient.get_client(APP_KEY, APP_SECRET, CALL_BACK)

    while True:
        print "Ready! Do you want to send a new weibo?(y/n)"
        choice = raw_input()
        if choice == 'y' or choice == 'Y':
            content = raw_input('input the your new weibo content : ')
            if content:
                client.statuses.update.post(status=content)
                print "Send succesfully!"
                break
            else:
                print "Error! Empty content!"
        if choice == 'n' or choice == 'N':
            break
Beispiel #9
0
def getClient():
     
    sina_weibo_config = ConfigParser.ConfigParser()
    try:
        sina_weibo_config.readfp(open('/home/property/sina_weibo_config.ini'))
    except ConfigParser.Error:
        print ('read sina_weibo_config.ini failed.')
    APP_KEY = sina_weibo_config.get('appinfo','APP_KEY')
    APP_SECRET = sina_weibo_config.get('appinfo','APP_SECRET')
    CALLBACK_URL = sina_weibo_config.get('appinfo','CALLBACK_URL')

    user = sina_weibo_config.get('userinfo','user')
    pwd = sina_weibo_config.get('userinfo','password')
    
    client = initclient.get_client(APP_KEY,APP_SECRET,CALLBACK_URL)
    if not client:
        print 'Get client Error!'
        return
    return client
Beispiel #10
0
def getClient():

    sina_weibo_config = ConfigParser.ConfigParser()
    try:
        sina_weibo_config.readfp(open('/home/property/sina_weibo_config.ini'))
    except ConfigParser.Error:
        print('read sina_weibo_config.ini failed.')
    APP_KEY = sina_weibo_config.get('appinfo', 'APP_KEY')
    APP_SECRET = sina_weibo_config.get('appinfo', 'APP_SECRET')
    CALLBACK_URL = sina_weibo_config.get('appinfo', 'CALLBACK_URL')

    user = sina_weibo_config.get('userinfo', 'user')
    pwd = sina_weibo_config.get('userinfo', 'password')

    client = initclient.get_client(APP_KEY, APP_SECRET, CALLBACK_URL)
    if not client:
        print 'Get client Error!'
        return
    return client
Beispiel #11
0
def postweibo():
    client = initclient.get_client()
    if not client:
        print 'Get client Error!'
        return

    # 发微博
    while True:
        print 'Do you want to send a new weibo?(y/n):',
        choice = raw_input()
        if choice in ['y', 'Y']:
            content = raw_input('Input new weibo content:')
            if content:
                client.statuses.update.post(status=content)
                print 'Send succesfully!'
                break
            else:
                print 'Error! Empty content!'
        if choice in ['n', 'N']:
            break
Beispiel #12
0
def postweibo():
    client = initclient.get_client()
    if not client:
        print 'Get client Error!'
        return

    # 发微博
    while True:
        print 'Do you want to send a new weibo?(y/n):',
        choice = raw_input()
        if choice in ['y','Y']:
            content = raw_input('Input new weibo content:')
            if content:
                client.statuses.update.post(status = content)
                print 'Send succesfully!'
                break;
            else:
                print 'Error! Empty content!'
        if choice in ['n', 'N']:
            break
Beispiel #13
0
def run():
		#调用initclietn模块创建授权的client对象
	client = initclient.get_client(APP_KEY, APP_SECRET, CALL_BACK)
	if not client:
			return

	UID = [1698194380, 1038819010, 1732523361, ]
	since_id = 0
	loop = 1
	while True:
		r = []
		r = client.statuses.friends_timeline.get(since_id = since_id)
		if r.statuses:
			since_id = r.statuses[0].id
			for message in r.statuses:
				if message.user.id in UID:
					# print message.text.encode()
					msg = message.user.screen_name+":"+message.text
					# print type(msg)
					send_mail(mailto_list,message.user.screen_name+" has a new blog",msg.encode('gb2312'))
		print "Loop  : %d, Time : %s , since_id : %d " % (loop, str(time.ctime()), since_id)
		loop = loop + 1
		time.sleep(60)
Beispiel #14
0
def run():
	client = initclient.get_client(APP_KEY, APP_SECRET, CALL_BACK)
	print "===> creat client successfully, authorised uid is : ", client.uid
	get_friends(client,1104219382);