Exemple #1
0
    def tweet(self, message):
        self.load_setting()
        self.auth.set_request_token(self.setting['request_token'],
                                    self.setting['request_token_secret'])
        self.auth.set_access_token(self.setting['access_token'],
                                   self.setting['access_token_secret'])

        api = API(self.auth, parser=ModelParser())
        ret = api.tweet.add(message, clientip='127.0.0.1')

        if (ret):
            tw = api.tweet.show(ret.id)
            print('发送成功:微博ID={0.id}\n用户名={0.nick}\n内容={0.text}'.format(tw))
Exemple #2
0
    print ('You must fill API_KEY and API_SECRET!')
    webbrowser.open("http://open.t.qq.com/apps_index.php")
    raise RuntimeError('You must set API_KEY and API_SECRET')

CALLBACK_URL = 'http://fledna.duapp.com/query'

auth = AuthHandler(API_KEY, API_SECRET, CALLBACK_URL)


token = YOUR TOKEN HERE
tokenSecret = YOUR TOKEN_SECRET HERE

auth.setToken(token, tokenSecret)

# this time we use ModelParser()
api = API(auth)  # ModelParser is the default option


"""
Avaliable API:
Do to refer api.doc.rst
api.user.info
api.user.otherinfo
api.user.update
api.user.updatehead
api.user.userinfo
"""

me = api.user.info()

print (("Name: {0.name}\nNick: {0.nick}\nLocation {0.location}\n"
Exemple #3
0

def get_token():
    print a.get_authorization_url()
    verifier = raw_input('PIN: ').strip()
    print a.get_access_token(verifier)


# or directly use:
#token = 'e9fc735b76ba4e75a6ebaefe61ee66fc'
token = 'd169abff38d747cfa8bdb21123577482'
#tokenSecret = 'ec07bda1b332156d1554470893b16b6d'
tokenSecret = '25d60b4c67c488a4d5291dcb9bd43fd8'
a.setToken(token, tokenSecret)

api = API(a)

QQ_WEIBO_INFO_SOURCE_ID = 7


def search_for_new_statuses():
    previous_real_count = session.query(Status).filter(
        Status.info_source_id == QQ_WEIBO_INFO_SOURCE_ID).count()

    lasttime = session.query(Job).filter(
        Job.info_source_id == QQ_WEIBO_INFO_SOURCE_ID).order_by(
            Job.id.desc()).first()
    deltatime = lasttime.previous_executed - timedelta(hours=2)
    starttime = time.mktime(deltatime.timetuple())
    endtime = time.mktime(datetime.now().timetuple())
Exemple #4
0
try:
    input = raw_input
except:
    pass

API_KEY = secret.apiKey
API_SECRET = secret.apiSecret
CALLBACK_URL = secret.callbackUrl

auth = AuthHandler(API_KEY, API_SECRET, CALLBACK_URL)

## use get_authorization_url if you haven't got a token
url = auth.get_authorization_url()
print('Opening {:s} in your browser...'.format(url))
webbrowser.open_new(url)
verifier = input('Your CODE: ').strip()

token = auth.get_access_token(verifier)

print token
# = Save Token =

# now you have a workable api
api = API(auth, parser=JSONParser())
# or use `api = API(auth)`
print("User Infomation:")
I = api.user.info()  # or api.me()
data = I['data']
print(("Name: {name}\nNick: {nick}\nLocation {location}\n"
       "Email: {email}\n").format(**data))
API_KEY = 'your key'
API_SECRET = 'your secret'

if API_KEY.startswith('your'):
    print ('You must fill API_KEY and API_SECRET!')
    webbrowser.open("http://open.t.qq.com/apps_index.php")
    raise RuntimeError('You must set API_KEY and API_SECRET')

auth = OAuthHandler(API_KEY, API_SECRET)

token = YOUR TOKEN HERE (so called consumer)
tokenSecret = YOUR TOKEN_SECRET HERE (so called token)

auth.setToken(token, tokenSecret)

api = API(auth)

"""
Avaliable API:
Do to refer api.doc.rst
api.timeline.broadcast
api.timeline.home
api.timeline.mentions
api.timeline.public
api.timeline.special
api.timeline.topic
api.timeline.user
"""

def dumpTweet(t):
    try:
Exemple #6
0
API_SECRET = 'your secret'

if API_KEY.startswith('your'):
    print('You must fill API_KEY and API_SECRET!')
    webbrowser.open("http://open.t.qq.com/apps_index.php")
    raise RuntimeError('You must set API_KEY and API_SECRET')

auth = OAuthHandler(API_KEY, API_SECRET)

token = 'your token'
tokenSecret = 'yourr tokenSecret'

auth.setToken(token, tokenSecret)

# this time we use ModelParser()
api = API(auth, parser=ModelParser())
"""
Avaliable API:
Do to refer api.doc.rst
api.tweet.add
api.tweet.addmusic
api.tweet.addpic
api.tweet.addvideo
api.tweet.comment
api.tweet.delete
api.tweet.getvideoinfo
api.tweet.reply
"""

# you must use unicode object here
sent = []
Exemple #7
0
    return confs


def set_conf(confs):
    import os
    confile = os.path.join(os.path.dirname(__file__), 'conf.py')
    with open(confile, 'w') as f:
        for k, v in confs.items():
            if isinstance(v, int):
                format = "%s = %s\n"
            elif isinstance(v, basestring):
                format = "%s = '%s'\n"
            else:
                continue
            f.write(format % (k, v))
        return True
    return False


def get_api():
    import sys, os.path
    sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
    from qqweibo import OAuthHandler, API
    c = get_conf()
    try:
        o = OAuthHandler(c['consumer_key'], c['consumer_secret'])
        o.setToken(c['access_token_key'], c['access_token_secret'])
    except KeyError, e:
        sys.stderr.write("qq: you should run get_oauthed.py first.\n")
    return API(o)