示例#1
0
def douban_cli():
    from douban_client import DoubanClient
    client = DoubanClient(API_KEY, API_SECRET, redirect_uri, SCOPE)
    if not douban_token:
        print client.authorize_url
        # manually get auth code
    client.auth_with_code(douban_token)
    return client
示例#2
0
 def get(self,code):
     douban = DoubanClient(API_KEY, SECRET, 'http://book.douban.com',SCOPE)
     douban.auth_with_code(code)
     token = douban.access_token.token
     print token
     duser = douban.user.me
     print duser
     user = connection.User()
     user['id']=int(duser['uid'])
     user['password'] = token
     user.save()
     return token
示例#3
0
def douban_cli():
    from douban_client import DoubanClient
    API_KEY = '09e7e2ad76917ac81db7a80863b47058'
    API_SECRET = '42764a7149130882'
    redirect_uri = 'http://54.250.166.126/spam/auth'
    SCOPE = 'douban_basic_common,movie_basic_r'
    client = DoubanClient(API_KEY, API_SECRET, redirect_uri, SCOPE)
    if not douban_token:
        print client.authorize_url
        # manually get auth code
    client.auth_with_code(douban_token)
    return client
示例#4
0
def get_client():
    client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)

    token = TOKEN

    if token:
        client.auth_with_token(token) 
    else:
        print 'Go to the following link in your browser:' 
        print client.authorize_url

        code = raw_input('Enter the verification code and hit ENTER when you\'re done:')
        client.auth_with_code(code)
        print client.client.token
    return client
示例#5
0
def get_client():
    client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)

    token = TOKEN

    if token:
        client.auth_with_token(token) 
    else:
        print 'Go to the following link in your browser:' 
        print client.authorize_url

        code = raw_input('Enter the verification code and hit ENTER when you\'re done:')
        client.auth_with_code(code)
        print client.client.token
    return client
示例#6
0
def get_client():
    client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)

    token = TOKEN

    if token:
        client.auth_with_token(token)
    else:
        print "Go to the following link in your browser:"
        print client.authorize_url

        code = raw_input("Enter the verification code and hit ENTER when you're done:")
        client.auth_with_code(code)
        print "token code:", client.token_code
        print "refresh token code:", client.refresh_token_code
    return client
示例#7
0
文件: pilot.py 项目: imapollo/douthon
def main():
    key = '022e300c79c18fc7068a90256d44af55'
    secret = '11c8bcbac80e8085'
    callback = 'http://www.douban.com'
    scope = 'douban_basic_common,community_basic_user,book_basic_r'

    client = DoubanClient( key, secret, callback, scope )

    # Following is to get the token at first time
    print 'Go to the following link in your browser:'
    print client.authorize_url
    code = raw_input( 'Enter the verification code:' )
    client.auth_with_code( code )
    print client.access_token.token

    # Following is to auth with the token already got
    # client.auth_with_token( '2090de6f59fea80a61b29b4e0dfbf81e' )
    print client.user.me
示例#8
0
class Note4stDouban:
    def __init__(self, user_json_file=None):
        """douban client for note4st
              user_json_file - solved on register
        """
        self.client = None
        self.user = DoubanUser()
        self.is_login = False
        if user_json_file:
            self.user.load(open(user_json_file))

    def register(self, auth_code):
        """douban client for note4st
              user_json_file - solved on register
        """
        self.client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)
        self.client.auth_with_code(auth_code)
        self.user.registered(
            self.client.user.me,
            self.client.user.access_token.token,
            self.client.user.access_token.refresh_token,
            self.client.user.access_token.expires_in,
            self.client.user.access_token.expires_at,
        )
        self.user.save2file(self.user.name)
        self.is_login = True

    def login(self, email=None, password=None, token=None):
        if not self.client:
            self.client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)
        if token:
            self.client.auth_with_token(token)
            self.client.auth_with_token(token)
        else:
            self.client.auth_with_password(email, password)
            self.user.refresh_token = self.client.refresh_token_code
        self.user.uid = self.client.user.me['uid']
        self.is_login = True
示例#9
0
文件: app.py 项目: qingfeng/douban3ds
def new():
    client = DoubanClient(API_KEY, API_SECRET, CALLBACK, SCOPE)
    code = request.form.get('code')
    image = request.files.get('image')
    comment = request.form.get('comment', '')
    hash1 = request.form.get('hash[new1]', '')
    hash2 = request.form.get('hash[new2]', '')
    hash3 = request.form.get('hash[new3]', '')

    if image:
        fname = '/tmp/1.jpg'
        image.save(fname)
        hash_text = hash_name([hash1, hash2, hash3])
        text = "%s %s" % (comment, hash_text)
        text = text.encode("utf-8")
        #try:
        client.auth_with_code(code)
        client.miniblog.new(text, image=open(fname))
        #except DoubanError:
        #    return redirect('/login')
        return "Upload OK"
    else:
        return "Error"
示例#10
0
文件: app.py 项目: qingfeng/douban3ds
def new():
    client = DoubanClient(API_KEY, API_SECRET, CALLBACK, SCOPE)
    code = request.form.get('code')
    image = request.files.get('image')
    comment = request.form.get('comment', '')
    hash1 = request.form.get('hash[new1]', '')
    hash2 = request.form.get('hash[new2]', '')
    hash3 = request.form.get('hash[new3]', '')

    if image:
        fname = '/tmp/1.jpg'
        image.save(fname)
        hash_text = hash_name([hash1, hash2, hash3])
        text = "%s %s" % (comment, hash_text)
        text = text.encode("utf-8")
        #try:
        client.auth_with_code(code)
        client.miniblog.new(text, image=open(fname))
        #except DoubanError:
        #    return redirect('/login')
        return "Upload OK"
    else:
        return "Error"
def get_client_v2():
    client = DoubanClient(key, secret, callback, SCOPE)
    if expires_at:
        expires_time = int(expires_at)

    if token:
        now_time = int(time.time())
        remaining_seconds = expires_time - now_time
        #print 'remains: ' + str(remaining_seconds)
        if remaining_seconds > 3600:
            client.auth_with_token(token)
        else:
            client.refresh_token(refresh_token)
            config.set('INFO', 'token', client.token_code)
            config.set('INFO', 'refresh_token', client.refresh_token_code)
            config.set('INFO', 'expires_at', client.expires_at)
            with open('test_config.cfg', 'wb') as configfile:
                config.write(configfile)
    else:
        print_('Go to the following link in your browser:')
        print_(client.authorize_url)

        code = input(
            'Enter the verification code and hit ENTER when you\'re done:')
        client.auth_with_code(code)
        print_('token code:', client.token_code)
        print_('refresh token code:', client.refresh_token_code)
        print_('expires at:', client.expires_at)
        print type(client.expires_at)
        config.set('INFO', 'token', client.token_code)
        config.set('INFO', 'refresh_token', client.refresh_token_code)
        config.set('INFO', 'expires_at', client.expires_at)
        with open('test_config.cfg', 'wb') as configfile:
            config.write(configfile)
        #pdb.set_trace()

    return client
def get_client_v2():
    client = DoubanClient(key, secret, callback, SCOPE)
    if expires_at:
        expires_time = int(expires_at)

    if token:
        now_time = int(time.time())
        remaining_seconds = expires_time - now_time
        #print 'remains: ' + str(remaining_seconds)
        if remaining_seconds > 3600:
            client.auth_with_token(token)
        else:
            client.refresh_token(refresh_token)   
            config.set('INFO', 'token', client.token_code)
            config.set('INFO', 'refresh_token', client.refresh_token_code)
            config.set('INFO', 'expires_at', client.expires_at)
            with open('test_config.cfg', 'wb') as configfile:
                config.write(configfile)
    else:
        print_('Go to the following link in your browser:')
        print_(client.authorize_url)

        code = input('Enter the verification code and hit ENTER when you\'re done:')
        client.auth_with_code(code)
        print_('token code:', client.token_code)
        print_('refresh token code:', client.refresh_token_code)
        print_('expires at:', client.expires_at)
        print type(client.expires_at)
        config.set('INFO', 'token', client.token_code)
        config.set('INFO', 'refresh_token', client.refresh_token_code)
        config.set('INFO', 'expires_at', client.expires_at)
        with open('test_config.cfg', 'wb') as configfile:
            config.write(configfile)
        #pdb.set_trace()

    return client
示例#13
0
from six.moves import input
from douban_client import DoubanClient

KEY = ''
SECRET = ''
CALLBACK = ''

SCOPE = 'douban_basic_common,community_basic_user'
client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)

print client.authorize_url
code = input('Enter the verification code:')

client.auth_with_code(code)
print client.user.me
示例#14
0
文件: scapy.py 项目: handelxh/python
from douban_client import DoubanClient
import requests
API_KEY = '01674b2cf3fb7e9d0435e186dbf27bd7'
API_SECRET = '5fc3e181565091c7'
SCOPE = 'douban_basic_common,shuo_basic_r,shuo_basic_w'
your_redirect_uri = 'http://bbs.csdn.net/topics/370247707.com'
client = DoubanClient(API_KEY, API_SECRET, your_redirect_uri, SCOPE)
# print 'Go to the following link in your browser:'
print client.authorize_url
r = requests.post(client.authorize_url)
code = r.json()['code']
client.auth_with_code(110)
print client.user.me
示例#15
0
def autopraise(id0):

    # 需要申请一个豆瓣API KEY, 在这里申请 http://developers.douban.com/apikey/apply
    API_KEY = ""
    API_SECRET = ""

    # 在 OAuth 2.0 中,
    # 获取权限需要指定相应的 scope,请注意!!
    SCOPE = "shuo_basic_r,shuo_basic_w,miniblog_basic_r,miniblog_basic_w"
    callback = "http://www.XXXX.com/callback"  # 填你申请时候的回调地址,有没有网站都无所谓
    client = DoubanClient(API_KEY, API_SECRET, callback, SCOPE)

    # 存储授权地址
    authurl = client.authorize_url
    # print authurl
    f = open("c:/authurl.txt", "w")

    # # 读取页面源代码
    br = mechanize.Browser()

    # Cookie Jar
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)

    # Browser options
    br.set_handle_equiv(True)
    br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)
    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

    # 模拟浏览器行为
    br.addheaders = [
        (
            "User-agent",
            "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/4.0.0",
        )
    ]
    r2 = br.open(authurl)

    br.select_form(nr=1)
    br["user_email"] = ""  # 你的豆瓣用户名和密码
    br["user_passwd"] = ""
    r3 = br.submit()

    c = r3.geturl()
    f.write(c)

    # 从请求页面回调地址中查找code
    m = re.findall("(?<=code\=).*", c)
    code = m[0]
    print code

    # 用code授权client
    client.auth_with_code(code)

    # 获取最近广播数据

    r4 = br.open("http://api.douban.com/shuo/v2/statuses/home_timeline?count=5")  # Count这里可以修改获取的广播数量,5比较多
    caststr = r4.read()
    id1 = re.findall('(?<=id"\:)\d+', caststr)

    # 友邻白名单
    def whitelist():
        r1 = br.open("http://api.douban.com/shuo/v2/statuses/user_timeline/XXXX")  # XXXX处 填写你不想赞的友邻用户名
        cast1 = r1.read()
        id1 = re.findall('(?<=id"\:)\d+', cast1)
        id = id1

        return id

    f.write(caststr)  # 存储广播列表

    for id in id1:
        if id in id0:
            break
        if id in whitelist():
            break

        client.miniblog.like(id)  # 赞
        print "liked"
        if hour > 2 and hour < 7:
            client.miniblog.comment.new(id, "Yo,watch body young man")  # 提醒友邻睡觉啦
            pass

    return id1
示例#16
0
#!/usr/bin/env python3
from douban_client import DoubanClient

API_KEY = '0c39dde0317db0f024ad99a0947912d0'
API_SEC = 'e30f500ed75a3a4f'
REDIRECT_URL = 'http://blog.unionx.me/callback'

SCOPE = 'book_basic_r, book_basic_w, shuo_basic_r, douban_basic_common'

client = DoubanClient(API_KEY, API_SEC, REDIRECT_URL, SCOPE)

print('Go to the following link in your browser:')
print(client.authorize_url)
code = input('Enter the verification code:\n')
client.auth_with_code(code)

# 2. 如果有之前有 token,则可以
# client.auth_with_token(token)

# Token Code
token_code = client.token_code
print(token_code)

book = client.book.get(26372794)
print(book)

# Refresh Token
# 请注意:`refresh_token_code` 值仅可在授权完成时获取(即在 `auth_with_code`, `auth_with_password` 之后)
refresh_token_code = client.refresh_token_code
client.refresh_token(refresh_token_code) # refresh token
示例#17
0
    def get(self, *args):

        KEY = "08e0dfb50c90b0991aa29f1f25b211cb"
        SECRET = "378ed0dadf96de47"
        CALLBACK = conf["url"] + "/dback"
        SCOPE = "douban_basic_common,community_basic_user,community_basic_note"

        client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)
        code = self.get_argument("code")

        if code:
            client.auth_with_code(code)
            auth = client.user.me
            if auth:
                accounts = conf["db"].accounts
                account = {
                    "_id": Kid.kid(),
                    "id": auth.get("id"),
                    "name": auth.get("name"),
                    "avatar": auth.get("avatar"),
                    "loc_name": auth.get("loc_name"),
                    "desc": auth.get("desc"),
                }

                try:
                    exist = Account.get_by_id(auth.get("id"))

                    if exist is None:
                        accounts.save(account)
                    else:
                        accounts.update({"id": auth.get("id")}, {"$set": account})

                except Exception as e:
                    print str(e)

                diary = client.note.list(auth.get("id"), 0, 20)
                diaries = conf["db"].diaries
                diary_notes = diary.get("notes")
                for i in diary_notes:

                    # re-summary content from douban
                    summary = i.get("content")[0:80] + "..."

                    diary = {
                        "_id": Kid.kid(),
                        "update_time": i.get("update_time"),
                        "publish_time": i.get("publish_time"),
                        "photos": i.get("photos"),
                        "comments_count": i.get("comments_count"),
                        "liked_count": i.get("liked_count"),
                        "recs_count": i.get("recs_count"),
                        "id": i.get("id"),
                        "alt": i.get("alt"),
                        "can_reply": i.get("can_reply"),
                        "title": i.get("title"),
                        "privacy": i.get("privacy"),
                        "summary": summary,
                        "content": client.note.get(i.get("id"), format="html_full").get("content"),
                    }
                    try:
                        exist = Diary.get_by_id(i.get("id"))

                        if exist is None:
                            diaries.save(diary)
                        else:
                            diaries.update({"id": i.get("id")}, {"$set": diary})

                    except Exception as e:
                        print str(e)

                self.redirect("/")
        else:
            print "douban_callback code missing"
示例#18
0
def autopraise(id0):

    #需要申请一个豆瓣API KEY, 在这里申请 http://developers.douban.com/apikey/apply
    API_KEY = ''
    API_SECRET = ''

    # 在 OAuth 2.0 中,
    # 获取权限需要指定相应的 scope,请注意!!
    SCOPE = 'shuo_basic_r,shuo_basic_w,miniblog_basic_r,miniblog_basic_w'
    callback = "http://www.XXXX.com/callback"  #填你申请时候的回调地址,有没有网站都无所谓
    client = DoubanClient(API_KEY, API_SECRET, callback, SCOPE)

    # 存储授权地址
    authurl = client.authorize_url
    # print authurl
    f = open("c:/authurl.txt", "w")

    # # 读取页面源代码
    br = mechanize.Browser()

    # Cookie Jar
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)

    # Browser options
    br.set_handle_equiv(True)
    br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)
    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

    #模拟浏览器行为
    br.addheaders = [(
        'User-agent',
        'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/4.0.0'
    )]
    r2 = br.open(authurl)

    br.select_form(nr=1)
    br['user_email'] = ''  #你的豆瓣用户名和密码
    br['user_passwd'] = ''
    r3 = br.submit()

    c = r3.geturl()
    f.write(c)

    #从请求页面回调地址中查找code
    m = re.findall("(?<=code\=).*", c)
    code = m[0]
    print code

    # 用code授权client
    client.auth_with_code(code)

    #获取最近广播数据

    r4 = br.open("http://api.douban.com/shuo/v2/statuses/home_timeline?count=5"
                 )  #Count这里可以修改获取的广播数量,5比较多
    caststr = r4.read()
    id1 = re.findall("(?<=id\"\:)\d+", caststr)

    #友邻白名单
    def whitelist():
        r1 = br.open(
            "http://api.douban.com/shuo/v2/statuses/user_timeline/XXXX"
        )  #XXXX处 填写你不想赞的友邻用户名
        cast1 = r1.read()
        id1 = re.findall("(?<=id\"\:)\d+", cast1)
        id = id1

        return id

    f.write(caststr)  #存储广播列表

    for id in id1:
        if id in id0:
            break
        if id in whitelist():
            break

        client.miniblog.like(id)  #赞
        print "liked"
        if hour > 2 and hour < 7:
            client.miniblog.comment.new(id,
                                        "Yo,watch body young man")  #提醒友邻睡觉啦
            pass

    return id1