Giter VIP home page Giter VIP logo

line's Introduction

このライブラリについて

注意

かなり前に書いたものなのであまりいい実装が出来ていません。(動作確認はしましたが)

必要なもの

  • Python3(Python2でも動くけど動作安定しないかも)
  • Pythonのライブラリ
    • requests
    • thrift
    • simplejson

インストール方法

gitコマンドを使います。

git clone https://github.com/in9lude/line.git

その後、プロジェクトディレクトリに入り、
python setup.py install とすればインストール完了です。

使い方

from line import LineClient #LineClientをimport
# LineClientオブジェクト(これがAPIラッパーです)
client = LineClient(mail, password) #ログイン
print(client.profile.displayName) #ユーザーネームを表示

ログイン方法はいくつかあります。
URLでログインする方法

from line import LineClient #LineClientをimport
client = LineClient() #URLログイン
AUTH URL: line://au/q/P1aQ1BnZxmKEdXTsFViy43uOa4OAkSsa #このリンクをモバイル端末に踏ませてログイン完了

ログインさえできればあとは簡単です。

ここで簡単なbotのコードを紹介します。

from line import LineClient, PollManager
try:
    client = LineClient(email, password)
    print("{}:LOGIN SUCCESS".format(client.profile.name))
except:
    print("LOGIN FAILED")

poll = PollManager(client)

def sendMessage(text, to, _from, toType=0, contentMetadata=0):

    msg = Message()

    if to[0] == "c":

        msg.to = to
        msg._from = _from
        msg.toType = 2

    elif to[0] == "u":
        msg.to = _from
        msg._from = to

    if contentMetadata:
        msg.contentMetadata = contentMetadata

    msg.text = text

    client.sendMessage(msg)

def RECEIVE_MESSAGE(op):

    msg = op.message
    # print(msg)
    print(
    " TO: {}\n".format(msg.to),
    "FROM: {}\n".format(msg._from),
    "TEXT: {}\n".format(msg.text),
    "CONTENT TYPE: {}\n".format(msg.contentType),
    "METADATA: {}\n".format(msg.contentMetadata),
    "TYPE: {}\n".format(msg.toType),
    "MESSAGE ID: {}\n".format(msg.id),
    "DATE: {}\n\n".format(msg.createdTime)
    )

    if msg.contentType != 0:
        pass

    else:
        text = msg.text
        to = msg.to
        _from = msg._from

        sendMessage(msg.text, to, _from)

poll.addFunction(26, RECEIVE_MESSAGE)

while True:

    poll.start()

これは発言したことをそのまま返すエコーbotの例です。

関数一覧は追記予定です

line's People

Watchers

James Cloos avatar

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.