Esempio n. 1
0
    if searchCmd.match(content):
        search_key = re.search(searchCmd, content)
        search_req = 'https://www.google.com/search?q=' +\
            str(search_key.group(1)).replace(' ', '+')
        plurk.callAPI('/APP/Responses/responseAdd',
                      {'plurk_id': pid,
                       'content': search_req, 
                       'qualifier': 'says' })
        print 'responsed to', msg.get('owner_id'),\
            'with search result: ', search_req 




#def main():
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:
Esempio n. 2
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')
    
Esempio n. 3
0
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', {
        'content': content,
        'qualifier': qualifier
    })
Esempio n. 4
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')
Esempio n. 5
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'地震': ['該減肥啦~', 
Esempio n. 6
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' : ':'})
Esempio n. 7
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')
Esempio n. 8
0
    '''

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', {
        'content': content,
        'qualifier': qualifier } )