Пример #1
0
    def __init__(self , ApiKey , DebugLevel=0):

        self._BaseUrl = 'http://www.plurk.com/API'

        self._ApiUrl = {
            'login'             :   '/Users/login',
            'logout'            :   '/Users/logout',
            'getPlurk'          :   '/Timeline/getPlurk',
            'getPlurks'         :   '/Timeline/getPlurks',
            'addPlurk'          :   '/Timeline/plurkAdd',
            'getResponses'      :   '/Responses/get',
            'getCompletionFriendsFans':'/FriendsFans/getCompletion',
            'getOwnProfile'     :   '/Profile/getOwnProfile',
            'getPublicProfile'  :   '/Profile/getPublicProfile'
        }

        PlurkAPI.__init__( self , ApiKey , self._BaseUrl , self._ApiUrl , DebugLevel )

        self.Logined = False
Пример #2
0
#!/usr/bin/python
# -*- coding:utf-8 -*-
 
import re
import json
import urllib2
import sys
import random
from PlurkAPI import PlurkAPI

plurk = PlurkAPI('4XsTJdmLB2pZ', '8XB4SEKx0SuK2HKNkUBYIavHnsQoHb88')
plurk.authorize('rGmQvgpN9PfQ', 'W2mmQtMccqzo211DsuI0eGotWwLLfMEf')
 
def simpleResp(content, pid):
    respDic = dict({u'吃甚麼': ['吃屎', 
                                '吃自己吧你'], 
                    u'好餓': ['吃屎阿',
                              '去吃大便'], 

                    u'為什麼': ['因為你腦袋有洞', 
                                '因為愛',
                                'http://www.youtube.com/watch?v=t0xXpQLQAT0'],
                                
                    u'地震': ['該減肥啦~', 
                              '你剛剛跳了一下對不對', 
                              '塊陶阿~~'],

                    u'快完成了': ['如果在最後一步失敗那就太好了'],

                    u'測試': ['失敗',
                              '不用測啦,早點洗洗睡了比較實際'],
Пример #3
0
#!/usr/bin/python
# -*- encoding:utf8 -*-

import re
import json
import urllib2
import os
from PlurkAPI import PlurkAPI

plurk = PlurkAPI('', '')
plurk.authorize('', '')


def bot ():
    j = plurk.callAPI('/APP/Timeline/plurkAdd', 
            {'content' : '今日氣象 http://emos.plurk.com/b02203682d2fee5d2869e20a03c05907_w48_h48.gif ', 
             'qualifier' : ':'})

    pid = j['plurk_id']

    if pid is None:
        return

    os.system('w3m -dump http://tw.weather.yahoo.com/today.html | '
              'awk \'{print $1 $2 $3 $4}\' | grep -P "\[\d\d\]" | '
              'sed -e \'s/\[..\]/ /\'> w')

    c = 0
    s = ""
    f = open("w")
Пример #4
0
def usage():
    print '''Help Information:
    -h: Show help information
    '''


if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
    except getopt.GetoptError, err:
        print str(err)  # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    file = open('API.keys', 'r+')
    data = json.load(file)
    plurk = PlurkAPI(data["CONSUMER_KEY"], data["CONSUMER_SECRET"])
    if data.get('ACCESS_TOKEN'):
        plurk.authorize(data["ACCESS_TOKEN"], data["ACCESS_TOKEN_SECRET"])
    else:
        plurk.authorize()
        data["ACCESS_TOKEN"] = plurk._oauth.oauth_token['oauth_token']
        data["ACCESS_TOKEN_SECRET"] = plurk._oauth.oauth_token[
            'oauth_token_secret']
        json.dump(data, file)

    content = 'Test from Plurk OAuth API'
    if len(sys.argv) > 1:
        content = sys.argv[1]
    qualifier = 'says'
    if len(sys.argv) > 2:
        qualifier = sys.argv[2]
Пример #5
0
sys.path.append('plurk_oauth/')
from PlurkAPI import PlurkAPI
import getopt
import json

def usage():
    print '''Help Information:
    -h: Show help information
    '''

if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
    except getopt.GetoptError, err:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    file = open('API.keys', 'r+')
    data = json.load(file)
    plurk = PlurkAPI(data["CONSUMER_KEY"], data["CONSUMER_SECRET"])
    if data.get('ACCESS_TOKEN'):
        plurk.authorize(data["ACCESS_TOKEN"],data["ACCESS_TOKEN_SECRET"])
    else:
        plurk.authorize()
        data["ACCESS_TOKEN"] = plurk._oauth.oauth_token['oauth_token']
        data["ACCESS_TOKEN_SECRET"] = plurk._oauth.oauth_token['oauth_token_secret']
        json.dump(data,file)

    print plurk.callAPI('/APP/Profile/getOwnProfile')
    
Пример #6
0
import getopt
import json


def usage():
    print '''Help Information:
    -h: Show help information
    '''


if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
    except getopt.GetoptError, err:
        print str(err)  # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    file = open('API.keys', 'r+')
    data = json.load(file)
    plurk = PlurkAPI(data["CONSUMER_KEY"], data["CONSUMER_SECRET"])
    if data.get('ACCESS_TOKEN'):
        plurk.authorize(data["ACCESS_TOKEN"], data["ACCESS_TOKEN_SECRET"])
    else:
        plurk.authorize()
        data["ACCESS_TOKEN"] = plurk._oauth.oauth_token['oauth_token']
        data["ACCESS_TOKEN_SECRET"] = plurk._oauth.oauth_token[
            'oauth_token_secret']
        json.dump(data, file)

    print plurk.callAPI('/APP/Profile/getOwnProfile')
Пример #7
0
#!/usr/bin/python
# -*- coding:utf-8 -*-
 
import re
import json
import urllib2
import sys
import random
from PlurkAPI import PlurkAPI
 
plurk = PlurkAPI('4XsTJdmLB2pZ', '8XB4SEKx0SuK2HKNkUBYIavHnsQoHb88')
plurk.authorize('rGmQvgpN9PfQ', 'W2mmQtMccqzo211DsuI0eGotWwLLfMEf')
 
comet = plurk.callAPI('/APP/Realtime/getUserChannel')
comet_channel = comet.get('comet_server') + "&new_offset=%d"
jsonp_re = re.compile('CometChannel.scriptCallback\((.+)\);\s*');
new_offset = -1

simpleResp = dict({u'吃甚麼': ['吃屎', 
                            '吃自己吧你'], 
                u'好餓': ['吃屎阿',
                          '去吃大便'], 

                u'許浩': ['許浩很帥,但輸慘@WeselyOng',
                          '許浩很強,但侯博才是真的神'],

                u'為什麼': ['因為你腦袋有洞', 
                            '因為愛',
                            'http://www.youtube.com/watch?v=t0xXpQLQAT0'],
                            
                u'地震': ['該減肥啦~', 
Пример #8
0
	r = json.load(f)
	f.close()
	return r

def getResp(cont):
	flag = 0
	for resp in resps:
		if type(resp) != list:
			if re.compile(resp).search(cont) != None:
				flag = 1
		elif flag == 1:
			return random.choice(resp).encode('utf-8')
	return None 


p = PlurkAPI()

comet = p.call("/Realtime/getUserChannel")
comet_channel = comet.get("comet_server") + "&new_offset=%d"

jsonp_re = re.compile('CometChannel.scriptCallback\((.+)\);\s*')
new_offset = -1

count = 0

while True:
	try:
		p.call("/Alerts/addAllAsFriends")
		if count == 0:
			resps = loadResp()
		count = (count + 1) % 30
Пример #9
0
#!/usr/bin/python

# the example from Dada's Blog
# http://blog.urdada.net/2011/10/28/426/

import re
import json
import urllib2
from PlurkAPI import PlurkAPI

# my plurk OAuth keys
plurk = PlurkAPI("", "")
plurk.authorize("", "")


def bot():
    # listen uer channel
    comet = plurk.callAPI("/APP/Realtime/getUserChannel")
    comet_channel = comet.get("comet_server") + "&new_offset=%d"
    jsonp_re = re.compile("CometChannel.scriptCallback\((.+)\);\s*")
    new_offset = -1

    while True:
        try:
            # get data in my channel
            req = urllib2.urlopen(comet_channel % new_offset, timeout=80)
            rawdata = req.read()
            match = jsonp_re.match(rawdata)

            if match:
                rawdata = match.group(1)
Пример #10
0
key = json.load(key_file)
key_file.close()

def get_quote_from_wikiquote():
	
	wikiapi = "http://%s.wikiquote.org/w/api.php?format=%s&action=%s&page=%s"
	today = date.today()
	
	request = urllib2.urlopen(wikiapi % 
				(
					"zh",
					"json",
					"parse",
					"Wikiquote:每日名言/%s月%s日" % (today.month, today.day)
				),
				timeout = 80)
	data = request.read()
	data = json.loads(data)
	data = remove_tags(data["parse"]["text"]["*"])
	data = data[:-6]

	return data + "\n\nvia Wikiquote"

if __name__ == "__main__":
	data = get_quote_from_wikiquote()

	plurk = PlurkAPI(key["APP_KEY"], key["APP_SECRET"])
	plurk.authorize(key["ACCESS_TOKEN"], key["ACCESS_TOKEN_SECRET"])

	plurk.callAPI("/APP/Timeline/plurkAdd", {'content' : data.encode("UTF-8"), 'qualifier' : ':'})
Пример #11
0
#!/usr/bin/python
# -*- coding:utf-8 -*-
 
import re
import json
import urllib2
 
from PlurkAPI import PlurkAPI
 
plurk = PlurkAPI('khAJMYUl812R', 'FQhBjxhszGESKiM0FaoTsVzFoDZOL1OA')
plurk.authorize('poWyWHtNnD92', 'Vg6HCEqy0XPCKW0WSNaVZRamUwoH0poa')
 
comet = plurk.callAPI('/APP/Realtime/getUserChannel')
comet_channel = comet.get('comet_server') + "&new_offset=%d"
jsonp_re = re.compile('CometChannel.scriptCallback\((.+)\);\s*');
new_offset = -1
while True:
    plurk.callAPI('/APP/Alerts/addAllAsFriends')
    req = urllib2.urlopen(comet_channel % new_offset, timeout=80)
    rawdata = req.read()
    match = jsonp_re.match(rawdata)
    if match:
        rawdata = match.group(1)
    data = json.loads(rawdata)
    new_offset = data.get('new_offset', -1)
    msgs = data.get('data')
    if not msgs:
        continue
    for msg in msgs:
        if msg.get('type') == 'new_plurk':
            pid = msg.get('plurk_id')
Пример #12
0
def usage():
    print '''Help Information:
    -h: Show help information
    '''

if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
    except getopt.GetoptError, err:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    file = open('API.keys', 'r+')
    data = json.load(file)
    plurk = PlurkAPI(data["CONSUMER_KEY"], data["CONSUMER_SECRET"])
    if data.get('ACCESS_TOKEN'):
        plurk.authorize(data["ACCESS_TOKEN"],data["ACCESS_TOKEN_SECRET"])
    else:
        plurk.authorize()
        data["ACCESS_TOKEN"] = plurk._oauth.oauth_token['oauth_token']
        data["ACCESS_TOKEN_SECRET"] = plurk._oauth.oauth_token['oauth_token_secret']
        json.dump(data,file)

    content = 'Test from Plurk OAuth API'
    if len(sys.argv) > 1:  
        content = sys.argv[1]
    qualifier = 'says'
    if len(sys.argv) > 2:  
        qualifier = sys.argv[2]
    print plurk.callAPI('/APP/Timeline/plurkAdd', {