Code Monkey home page Code Monkey logo

x2ch's Introduction

x2ch

Description

x2chは2chのダウンローダとパーサを備えたライブラリです。 このライブラリを使うとRubyで簡単に2chにアクセスできます。

Install

gem install x2ch

Examples

2chのカテゴリーと板一覧を取得する。 なおサーバからのダウンロードはgzipに対応しています。

require 'x2ch'
include X2CH

bbs = Bbs.load
bbs.each{|category|
  puts '- ' + category.name
  category.each{|board|
    puts ' - ' + board.name
  }
}

カテゴリー「趣味」の「アクアリウム」板のスレッド一覧を取得する。

require 'x2ch'
include X2CH

bbs = Bbs.load
bbs['趣味']['アクアリウム'].each{|thread|
  puts thread.name + '(' + thread.num.to_s + ')'
}

アクアリウム板の最初のスレッドの投稿を取得する。

require 'x2ch'
include X2CH

bbs = Bbs.load
bbs['趣味']['アクアリウム'].threads.first.each{|post|
  puts "#{post.name} <> #{post.mail} <> #{post.metadata} <> #{post.body}"
}

posts等の返却値はX2CH::Responseモジュールにより拡張されているため、レスポンスの情報を取得できます。 これによりLast-Modifiedに基づいて、If-Modified-Sinceによる更新確認が行えます。

require 'x2ch'
include X2CH

bbs = Bbs.load
res = bbs['趣味']['アクアリウム'].threads.first.posts
puts res.status
puts res.last_modified
puts res.content_encoding
puts res.body_size

begin
  res = bbs['趣味']['アクアリウム'].threads.first.posts(res.last_modified.httpdate)
  puts res.status
  puts res.last_modified
  puts res.content_encoding
  puts res.body_size
rescue DownloadError => e
  puts e.message
end

Author

License

This library is distributed under the MIT license.

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.