Skip to content

Instantly share code, notes, and snippets.

@Answeror
Last active July 14, 2017 11:51

Revisions

  1. Answeror revised this gist Oct 6, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion main.json
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    "@json_decode[headers]": {
    "@jinja2": {
    "template": { "text<": "headers.json" },
    "kargs": { "chii_auth": {{ chii_auth }} }
    "kargs": { "chii_auth": "{{ chii_auth }}" }
    }
    }
    },
  2. Answeror revised this gist Oct 6, 2014. 3 changed files with 34 additions and 79 deletions.
    2 changes: 1 addition & 1 deletion headers.json
    Original file line number Diff line number Diff line change
    @@ -7,5 +7,5 @@
    "Cookie": "chii_auth={{ chii_auth }}; chii_cookietime=2592000",
    "Host": "bgm.tv",
    "Referer": "http://bgm.tv/",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0"
    }
    33 changes: 33 additions & 0 deletions main.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    {
    "@all": [
    {
    "@json_decode[headers]": {
    "@jinja2": {
    "template": { "text<": "headers.json" },
    "kargs": { "chii_auth": {{ chii_auth }} }
    }
    }
    },
    {
    "@request[login]": {
    "context": "bangumi",
    "uri": "http://bgm.tv",
    "headers": { "&": "headers" }
    }
    },
    {
    "@xslt": {
    "html_encoded": {
    "[body]": {
    "@request/login": {
    "context": "bangumi",
    "uri": "http://bgm.tv/pm",
    "headers": { "&": "headers" }
    }
    }
    },
    "xslt": { "text<": "bgm_pm.xslt" }
    }
    }
    ]
    }
    78 changes: 0 additions & 78 deletions torabot.json
    Original file line number Diff line number Diff line change
    @@ -1,78 +0,0 @@
    {
    "@": "all",
    "args": [
    {
    "@": "json_decode",
    "name": "headers",
    "args": [
    {
    "@": "jinja2",
    "kargs": {
    "template": {
    "@": "read",
    "kargs": {
    "name": "headers.json",
    "type": "text"
    }
    },
    "kargs": {
    "chii_auth": "{{ chii_auth }}"
    }
    }
    }
    ]
    },
    {
    "@": "request",
    "name": "update_cookie",
    "args": [
    {
    "uri": "http://bgm.tv",
    "headers": {"&": "headers"}
    }
    ]
    },
    {
    "@": "set_cookie",
    "name": "set_cookie",
    "kargs": {
    "request": {
    "uri": "http://bgm.tv/pm",
    "headers": {"&": "headers"}
    },
    "set_cookie": {
    "[]": [
    {"&": "update_cookie"},
    "headers",
    "Set-Cookie"
    ]
    }
    }
    },
    {
    "@": "request",
    "name": "get_html",
    "args": [{"&": "set_cookie"}]
    },
    {
    "@": "base64_decode",
    "name": "decode",
    "args": [
    {"[]": [{"&": "get_html"}, "body"]}
    ]
    },
    {
    "@": "xslt",
    "kargs": {
    "html": {"&": "decode"},
    "xslt": {
    "@": "read",
    "kargs": {
    "name": "bgm_pm.xslt",
    "type": "text"
    }
    }
    }
    }
    ]
    }
  3. Answeror revised this gist Jul 5, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@

    **注意: 公开你的cookie是一件危险的事情. 别人可能利用它来滥用你的Bangumi账户! Torabot的作者保证不会使用你的cookie做这个gist功能以外的事情. 如果你不信任torabot, 请忽略这个gist.**

    例子: `http://torabot.com/m/gist/34fd6a535090ca85a2fc?chii_auth=<chii_auth_in_your_cookie>`
    例子: `http://torabot.com/api/source/34fd6a535090ca85a2fc.atom?chii_auth=<chii_auth_in_your_cookie>`

    其中"chii_auth_in_your_cookie"是你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的"chii_auth"对应的值替换"chii_auth_in_your_cookie"即可. **注意: 如果你的chii_auth里包含`%`, 必须将其全部替换成`%25`.**

  4. Answeror revised this gist Jun 30, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@

    例子: `http://torabot.com/m/gist/34fd6a535090ca85a2fc?chii_auth=<chii_auth_in_your_cookie>`

    其中"chii_auth_in_your_cookie"是你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的"chii_auth"对应的值替换"chii_auth_in_your_cookie"即可.
    其中"chii_auth_in_your_cookie"是你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的"chii_auth"对应的值替换"chii_auth_in_your_cookie"即可. **注意: 如果你的chii_auth里包含`%`, 必须将其全部替换成`%25`.**

    然后将上述地址填入[torabot的feed订阅](http://torabot.com/help/feed). Bangumi收到私信后一般10分钟内即可收到torabot发来的通知邮件.

  5. Answeror revised this gist Jun 29, 2014. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,9 @@

    **注意: 公开你的cookie是一件危险的事情. 别人可能利用它来滥用你的Bangumi账户! Torabot的作者保证不会使用你的cookie做这个gist功能以外的事情. 如果你不信任torabot, 请忽略这个gist.**

    例子: `http://torabot.com/m/gist/<gist_id>?chii_auth=<chii_auth_in_your_cookie>`
    例子: `http://torabot.com/m/gist/34fd6a535090ca85a2fc?chii_auth=<chii_auth_in_your_cookie>`

    其中"gist_id"是你fork的gist编号, 比如 https://gist.github.com/Answeror/34fd6a535090ca85a2fc 的编号就是 `34fd6a535090ca85a2fc`

    "chii_auth_in_your_cookie"是你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的`chii_auth`对应的值替换"chii_auth_in_your_cookie"即可.
    其中"chii_auth_in_your_cookie"是你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的"chii_auth"对应的值替换"chii_auth_in_your_cookie"即可.

    然后将上述地址填入[torabot的feed订阅](http://torabot.com/help/feed). Bangumi收到私信后一般10分钟内即可收到torabot发来的通知邮件.

  6. Answeror revised this gist Jun 29, 2014. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,14 @@

    ## 使用方法

    **注意: 请确保你fork之后的gist是private的. 公开你的cookie是一件危险的事情. 别人可能利用它来滥用你的Bangumi账户! Torabot的作者保证不会使用你的cookie做这个gist功能以外的事情. 如果你不信任torabot, 请忽略这个gist.**
    **注意: 公开你的cookie是一件危险的事情. 别人可能利用它来滥用你的Bangumi账户! Torabot的作者保证不会使用你的cookie做这个gist功能以外的事情. 如果你不信任torabot, 请忽略这个gist.**

    Fork这个gist, 修改`headers.json`里的"please_change_this_value"为你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的`chii_auth`对应的值替换"please_change_this_value"即可.
    例子: `http://torabot.com/m/gist/<gist_id>?chii_auth=<chii_auth_in_your_cookie>`

    然后将 `http://torabot.com/m/gist/<gist_id>` 填入[torabot的feed订阅](http://torabot.com/help/feed). Bangumi收到私信后一般10分钟内即可收到torabot发来的通知邮件. 其中`gist_id`是你fork的gist编号, 比如 https://gist.github.com/Answeror/34fd6a535090ca85a2fc 的编号就是 `34fd6a535090ca85a2fc`
    其中"gist_id"是你fork的gist编号, 比如 https://gist.github.com/Answeror/34fd6a535090ca85a2fc 的编号就是 `34fd6a535090ca85a2fc`

    如果你不想使用torabot, 也可以直接用你喜欢的rss阅读器订阅 `http://torabot.com/m/gist/<gist_id>`
    "chii_auth_in_your_cookie"是你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的`chii_auth`对应的值替换"chii_auth_in_your_cookie"即可.

    然后将上述地址填入[torabot的feed订阅](http://torabot.com/help/feed). Bangumi收到私信后一般10分钟内即可收到torabot发来的通知邮件.

    如果你不想使用torabot, 也可以直接用你喜欢的rss阅读器订阅该地址.
  7. Answeror renamed this gist Jun 29, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. Answeror revised this gist Jun 29, 2014. 2 changed files with 55 additions and 24 deletions.
    2 changes: 1 addition & 1 deletion headers.json
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    "Accept-Language": "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2,ja;q=0.2",
    "Cache-Control": "max-age=0",
    "Connection": "keep-alive",
    "Cookie": "chii_auth=please_change_this_value; chii_cookietime=2592000",
    "Cookie": "chii_auth={{ chii_auth }}; chii_cookietime=2592000",
    "Host": "bgm.tv",
    "Referer": "http://bgm.tv/",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
    77 changes: 54 additions & 23 deletions torabot.json
    Original file line number Diff line number Diff line change
    @@ -1,46 +1,77 @@
    {
    "targets": [
    "@": "all",
    "args": [
    {
    "@": "json_decode",
    "name": "headers",
    "args": [
    {
    "@": "jinja2",
    "kargs": {
    "template": {
    "@": "read",
    "kargs": {
    "name": "headers.json",
    "type": "text"
    }
    },
    "kargs": {
    "chii_auth": "{{ chii_auth }}"
    }
    }
    }
    ]
    },
    {
    "@": "request",
    "name": "update_cookie",
    "type": "request",
    "input": {
    "request": {
    "args": [
    {
    "uri": "http://bgm.tv",
    "headers": "{{ target['@files'].read_json('headers.json') }}"
    "headers": {"&": "headers"}
    }
    }
    ]
    },
    {
    "@": "set_cookie",
    "name": "set_cookie",
    "type": "set_cookie",
    "input": {
    "kargs": {
    "request": {
    "uri": "http://bgm.tv/pm",
    "headers": "{{ target['@files'].read_json('headers.json') }}"
    "headers": {"&": "headers"}
    },
    "set_cookie": "{{ target.update_cookie.headers['Set-Cookie'] }}"
    "set_cookie": {
    "[]": [
    {"&": "update_cookie"},
    "headers",
    "Set-Cookie"
    ]
    }
    }
    },
    {
    "@": "request",
    "name": "get_html",
    "type": "request",
    "input": {
    "request": "{{ target.set_cookie }}"
    }
    "args": [{"&": "set_cookie"}]
    },
    {
    "@": "base64_decode",
    "name": "decode",
    "type": "base64_decode",
    "input": {
    "text": "{{ target.get_html.body }}"
    }
    "args": [
    {"[]": [{"&": "get_html"}, "body"]}
    ]
    },
    {
    "name": "transform",
    "type": "xslt",
    "input": {
    "html": "{{ target.decode }}",
    "xslt": "{{ target['@files'].read_text('bgm.xslt') }}"
    "@": "xslt",
    "kargs": {
    "html": {"&": "decode"},
    "xslt": {
    "@": "read",
    "kargs": {
    "name": "bgm_pm.xslt",
    "type": "text"
    }
    }
    }
    }
    ]
  9. Answeror revised this gist Jun 29, 2014. 1 changed file with 4 additions and 14 deletions.
    18 changes: 4 additions & 14 deletions torabot.json
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,12 @@
    {
    "targets": [
    {
    "name": "request_headers",
    "type": "json_file",
    "input": {
    "name": "headers.json"
    }
    },
    {
    "name": "update_cookie",
    "type": "request",
    "input": {
    "request": {
    "uri": "http://bgm.tv",
    "headers": "{{ target.request_headers }}"
    "headers": "{{ target['@files'].read_json('headers.json') }}"
    }
    }
    },
    @@ -23,7 +16,7 @@
    "input": {
    "request": {
    "uri": "http://bgm.tv/pm",
    "headers": "{{ target.request_headers }}"
    "headers": "{{ target['@files'].read_json('headers.json') }}"
    },
    "set_cookie": "{{ target.update_cookie.headers['Set-Cookie'] }}"
    }
    @@ -45,12 +38,9 @@
    {
    "name": "transform",
    "type": "xslt",
    "options": {
    "xslt": "bgm.xslt"
    },
    "input": {
    "text": "{{ target.decode }}",
    "type": "html"
    "html": "{{ target.decode }}",
    "xslt": "{{ target['@files'].read_text('bgm.xslt') }}"
    }
    }
    ]
  10. Answeror revised this gist Jun 29, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -10,4 +10,4 @@ Fork这个gist, 修改`headers.json`里的"please_change_this_value"为你的coo

    然后将 `http://torabot.com/m/gist/<gist_id>` 填入[torabot的feed订阅](http://torabot.com/help/feed). Bangumi收到私信后一般10分钟内即可收到torabot发来的通知邮件. 其中`gist_id`是你fork的gist编号, 比如 https://gist.github.com/Answeror/34fd6a535090ca85a2fc 的编号就是 `34fd6a535090ca85a2fc`

    注意你必须使用torabot订阅该feed, 才能保证feed持续更新. 如果你不想使用torabot, 也可以在订阅后使用你喜欢的rss阅读器订阅 `http://torabot.com/m/gist/<gist_id>`
    如果你不想使用torabot, 也可以直接用你喜欢的rss阅读器订阅 `http://torabot.com/m/gist/<gist_id>`
  11. Answeror revised this gist Jun 28, 2014. 1 changed file with 0 additions and 10 deletions.
    10 changes: 0 additions & 10 deletions torabot.json
    Original file line number Diff line number Diff line change
    @@ -53,15 +53,5 @@
    "type": "html"
    }
    }
    ],
    "files": [
    {
    "name": "bgm.xslt",
    "path": "../targets/test/bgm.xslt"
    },
    {
    "name": "headers.json",
    "path": "./headers.json"
    }
    ]
    }
  12. Answeror revised this gist Jun 28, 2014. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,8 @@

    **注意: 请确保你fork之后的gist是private的. 公开你的cookie是一件危险的事情. 别人可能利用它来滥用你的Bangumi账户! Torabot的作者保证不会使用你的cookie做这个gist功能以外的事情. 如果你不信任torabot, 请忽略这个gist.**

    Fork这个gist, 修改`headers.json`里的"please_change_this_value"为你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的`chii_auth`对应的值替换"please_change_this_value"即可.
    Fork这个gist, 修改`headers.json`里的"please_change_this_value"为你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的`chii_auth`对应的值替换"please_change_this_value"即可.

    然后将 `http://torabot.com/m/gist/<gist_id>` 填入[torabot的feed订阅](http://torabot.com/help/feed). Bangumi收到私信后一般10分钟内即可收到torabot发来的通知邮件. 其中`gist_id`是你fork的gist编号, 比如 https://gist.github.com/Answeror/34fd6a535090ca85a2fc 的编号就是 `34fd6a535090ca85a2fc`

    注意你必须使用torabot订阅该feed, 才能保证feed持续更新. 如果你不想使用torabot, 也可以在订阅后使用你喜欢的rss阅读器订阅 `http://torabot.com/m/gist/<gist_id>`
  13. Answeror created this gist Jun 28, 2014.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # Bangumi私信订阅

    这个gist由[torabot](http://torabot.com)自动抓取并生成[Atom feed](http://en.wikipedia.org/wiki/Atom_(standard)).

    ## 使用方法

    **注意: 请确保你fork之后的gist是private的. 公开你的cookie是一件危险的事情. 别人可能利用它来滥用你的Bangumi账户! Torabot的作者保证不会使用你的cookie做这个gist功能以外的事情. 如果你不信任torabot, 请忽略这个gist.**

    Fork这个gist, 修改`headers.json`里的"please_change_this_value"为你的cookie里的对应值. 如果你使用Chrome, 可以按下<kbd>CTRL+SHIFT+J</kbd>, 然后在Resources选项卡中找到Cookies项, 用其中的`chii_auth`对应的值替换"please_change_this_value"即可.
    44 changes: 44 additions & 0 deletions bgm.xslt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    <?xml version='1.0' encoding='UTF-8'?>
    <xsl:stylesheet
    version='1.0'
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
    xmlns:re='http://exslt.org/regular-expressions'
    extension-element-prefixes='re'
    >
    <xsl:output method='xml' encoding='UTF-8'/>
    <xsl:template match='/'>
    <feed xml:lang='zh-CN' xmlns='http://www.w3.org/2005/Atom'>
    <id>bgm.tv/pm</id>
    <link rel='alternate' type='text/html' href='http://bgm.tv/pm'/>
    <title>bgm.tv/pm</title>
    <xsl:apply-templates select='//table[@class="topic_list"]'/>
    </feed>
    </xsl:template>
    <xsl:template match='table'>
    <xsl:for-each select='.//tr[td[contains(@class, "pm_")]]'>
    <xsl:variable name='date' select='.//small[@class="grey"]'/>
    <xsl:variable name='year' select='re:replace($date, "(\d+)-(\d+)-(\d+)", "", "\1")'/>
    <xsl:variable name='month' select='re:replace($date, "(\d+)-(\d+)-(\d+)", "", "\2")'/>
    <xsl:variable name='day' select='re:replace($date, "(\d+)-(\d+)-(\d+)", "", "\3")'/>
    <xsl:variable name='time' select='concat($year, "-", format-number($month, "00"), "-", format-number($day, "00"), "T00:00:00Z")'/>
    <xsl:variable name='content' select='.//span[@class="tip"]'/>
    <entry>
    <id><xsl:value-of select='.//input[@type="checkbox"]/@value'/></id>
    <published><xsl:value-of select='$time'/></published>
    <updated><xsl:value-of select='$time'/></updated>
    <link rel='alternate' type='text/html'>
    <xsl:attribute name='href'>
    <xsl:value-of select='.//a[1]/@href'/>
    </xsl:attribute>
    </link>
    <title><xsl:value-of select='normalize-space(.//a[1])'/></title>
    <summary><xsl:value-of select='$content'/></summary>
    <content type='text'><xsl:value-of select='$content'/></content>
    <author>
    <name><xsl:value-of select='.//a[2]'/></name>
    <url><xsl:value-of select='.//a[2]/@href'/></url>
    </author>
    </entry>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    11 changes: 11 additions & 0 deletions headers.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "Accept-Encoding": "gzip,deflate,sdch",
    "Accept-Language": "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2,ja;q=0.2",
    "Cache-Control": "max-age=0",
    "Connection": "keep-alive",
    "Cookie": "chii_auth=please_change_this_value; chii_cookietime=2592000",
    "Host": "bgm.tv",
    "Referer": "http://bgm.tv/",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
    }
    67 changes: 67 additions & 0 deletions torabot.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    {
    "targets": [
    {
    "name": "request_headers",
    "type": "json_file",
    "input": {
    "name": "headers.json"
    }
    },
    {
    "name": "update_cookie",
    "type": "request",
    "input": {
    "request": {
    "uri": "http://bgm.tv",
    "headers": "{{ target.request_headers }}"
    }
    }
    },
    {
    "name": "set_cookie",
    "type": "set_cookie",
    "input": {
    "request": {
    "uri": "http://bgm.tv/pm",
    "headers": "{{ target.request_headers }}"
    },
    "set_cookie": "{{ target.update_cookie.headers['Set-Cookie'] }}"
    }
    },
    {
    "name": "get_html",
    "type": "request",
    "input": {
    "request": "{{ target.set_cookie }}"
    }
    },
    {
    "name": "decode",
    "type": "base64_decode",
    "input": {
    "text": "{{ target.get_html.body }}"
    }
    },
    {
    "name": "transform",
    "type": "xslt",
    "options": {
    "xslt": "bgm.xslt"
    },
    "input": {
    "text": "{{ target.decode }}",
    "type": "html"
    }
    }
    ],
    "files": [
    {
    "name": "bgm.xslt",
    "path": "../targets/test/bgm.xslt"
    },
    {
    "name": "headers.json",
    "path": "./headers.json"
    }
    ]
    }