Esempio n. 1
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")
Esempio n. 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'測試': ['失敗',
                              '不用測啦,早點洗洗睡了比較實際'],
Esempio n. 3
0
    -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', {
        'content': content,
Esempio n. 4
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. 5
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)
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')