Giter Club home page Giter Club logo

doubansaver's Introduction

枝江存档姬

该项目已停止维护。其衍生项目为【豆瓣魂组数据镜像】

本仓库的源代码的默认分支【mobileAPI】并不完善,尽管完成了六成的功能代码,带并没有将它们成熟地组织起来。

原始的枝江存档姬源码请查阅分支【main】。

doubansaver's People

Contributors

wendaolee avatar

Stargazers

四月薰香满樱落 avatar  avatar

Watchers

 avatar

doubansaver's Issues

TODO:添加对于报错的逻辑处理

目前偶尔会因为API的mail lock导致查询时出现错误。
等到之后有空添加这一部分报错的逻辑处理。预计返回一个几秒后刷新原页面的404页面。

豆瓣移动端api示例

import asyncio
import aiohttp
import hmac
import base64
import time
from urllib.parse import urlparse, quote, urlencode

headers = {
    "User-Agent": "api-client/1 com.douban.frodo/7.27.0.6(231) Android/25 product/DT1901A vendor/smartisan model/DT1901A brand/smartisan  rom/android  network/wifi  udid/5fe86d1e414d8417ff3ec84c369e28c97a7d9d45  platform/AndroidPad",
}

dm = {
    "channel": "Douban",
    "os_rom": "android",
}

def encrypt(api, method, data):
    path = urlparse(api).path
    secret = b"bf7dddc7c9cfe6f7"
    timestamp = int(time.time())
    message = ("&".join([method, quote(path, safe=""), str(timestamp)]))
    h = hmac.new(secret, message.encode(), digestmod="sha1")
    b = base64.b64encode(h.digest())
    return {
        **data,
        "apikey": "0dad551ec0f84ed02907ff5c42e8ec70",
        "_ts": timestamp,
        "_sig": b.decode(),
    }
# 生成签名函数


async def get(api, params=None):
    async with aiohttp.ClientSession() as session:
        async with session.get(api, params=params, headers=headers) as resp:
            data = await resp.json()
            return data


async def getTopic(tid):
    api = "https://frodo.douban.com/api/v2/group/topic/{}".format(tid)
    params = encrypt(api, "GET", dm)
    return await get(api, params)
# 获取主贴内容


async def getComment(tid, start=0, count=20):
    api = "https://frodo.douban.com/api/v2/group/topic/{}/comments".format(tid)
    params = encrypt(api, "GET", {**dm, "start": start, "count": count})
    return await get(api, params)
# 获取评论(一次最多20条)


async def getAllComments(tid):
    comments = []
    i = 0
    r = await getComment(tid)
    while r["comments"]:
        i += 20
        comments += r["comments"]
        r = await getComment(tid, i)
        print(i)
        await asyncio.sleep(0.5)
    return comments
# 获取全部评论

仅供参考

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.