/pych

2ch.hk API client on python

Primary LanguagePythonMIT LicenseMIT

PyCh

Codecov Travis (.com) Checked with mypy GitHub issues by-label GitHub stars

          _____                _____                    _____                    _____          
         /\    \              |\    \                  /\    \                  /\    \         
        /::\    \             |:\____\                /::\    \                /::\____\        
       /::::\    \            |::|   |               /::::\    \              /:::/    /        
      /::::::\    \           |::|   |              /::::::\    \            /:::/    /         
     /:::/\:::\    \          |::|   |             /:::/\:::\    \          /:::/    /          
    /:::/__\:::\    \         |::|   |            /:::/  \:::\    \        /:::/____/           
   /::::\   \:::\    \        |::|   |           /:::/    \:::\    \      /::::\    \           
  /::::::\   \:::\    \       |::|___|______    /:::/    / \:::\    \    /::::::\    \   _____  
 /:::/\:::\   \:::\____\      /::::::::\    \  /:::/    /   \:::\    \  /:::/\:::\    \ /\    \ 
/:::/  \:::\   \:::|    |    /::::::::::\____\/:::/____/     \:::\____\/:::/  \:::\    /::\____\
\::/    \:::\  /:::|____|   /:::/~~~~/~~      \:::\    \      \::/    /\::/    \:::\  /:::/    /
 \/_____/\:::\/:::/    /   /:::/    /          \:::\    \      \/____/  \/____/ \:::\/:::/    / 
          \::::::/    /   /:::/    /            \:::\    \                       \::::::/    /  
           \::::/    /   /:::/    /              \:::\    \                       \::::/    /   
            \::/____/    \::/    /                \:::\    \                      /:::/    /    
             ~~           \/____/                  \:::\    \                    /:::/    /     
                                                    \:::\    \                  /:::/    /      
                                                     \:::\____\                /:::/    /       
                                                      \::/    /                \::/    /        
                                                       \/____/                  \/____/         

Usage

Download pych:

$ pip install pych

First import:

>>> from pych.catalog import Catalog

Get threads list:

>>> catalog = Catalog('b')
>>> catalog.threads
[<Thread board="b" #200000001 "Тема треда">...]

Get thread info:

>>> thread = catalog.threads.pop()  # Get last thread
 
>>> thread.subject
'%%Тема треда%%'

Get thread post:

>>> thread.posts
[<Post #201306703>, <Post #201306882>, <Post #201308883>]

>>> OP = thread.posts[0]
>>> OP.comment
'Даже у него есть тян'

Get post files:

>>> OP.files

Docs

class pych.catalog.Catalog(board: str)

Threads catalog class. Accepts the name of the board.

Catalog.board

type: str

The board short name.

Catalog.threads

type: Threads[]

Threads list in specified board. (Lazy property, loads only when called.)

class pych.file.File(**kwargs)

Attachment file in post.

File.displayname

type: str

Cropped attachment display name.

File.fullname

type: str

Full attachment display name.

File.height

type: int

Height of attachment in pixels.

File.md5

type: str

MD5 hash sum of attachment.

File.name

type: str

Server file name.

File.nsfw

type: int

...

File.path

type: str

Full URL to file.

File.size

type: int

Size of attachment in bytes.

File.thumbnail

type: str

Full URL to attachment thumbnail.

File.tn_height

type: int

The attachment thumbnail height.

File.tn_width

type: int

The attachment thumbnail width.

File.type

type: int

The attachment type.

  1. jpg
  2. png
  3. webm
  4. mp4/mov

File.width

type: int

The attachment file width.

File.download(destination: str) -> None

Download and save file to specified destination.

class pych.post.Post(**kwargs)

Post.board

type: str

Post board name.

Post.banned

type: int

...

Post.closed

type: int

...

Post.comment

type: str

Post text with markdown tags.

Post.date

type: str

Datetime posted.

Post.email

type: str

Post author email.

Post.endless

type: int

...

Post.files

type: File[]

List of File instances.

Post.lasthit

type: int

...

Post.name

type: str

Post author name.

Post.num

type: int

Global post id.

Post.number

type: int

Post id regarding thread.

Post.op

type: int

Flag OP.

Post.parent

type: str

Parent thread post.

Post.sticky

type: int

...

Post.subject

type: str

Thread post subject.

Post.timestamp

type: int

Timestamp when posted.

Post.trip

type: str

...

class pych.thread.Thread(**kwargs)

Thread.board

type: str

Thread board name.

Thread.comment

type: str

Thread OP text with markdown.

Thread.lasthit

type: int

...

Thread.num

type: str

Thread OP id.

Thread.posts_count

type: int

Count of posts inside thread.

Thread.score

type: float

Score of the thread.

Thread.subject

type: str

Thread subject.

Thread.timestamp

type: int

Thread created timestamp.

Thread.views

type: int

Count of views of thread.

Thread.url

type: str

Thread full URL.

Thread.posts

type: Post[]

Get thread posts list.

def pych.info.boards() -> Dict[str, str]

returns: Dict[str, str]

Get boards. Returns dict where key is a board id and value is a board name.

For example: { "b": "Бред" }.