Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
carpedm20 committed Aug 4, 2014
1 parent 2929040 commit da01a65
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
*py[co]

#test
test.py

#thrift
*thrift

# Packages
*.egg
*.egg-info
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include LICENSE
include README.rst
Empty file added Makefile
Empty file.
52 changes: 32 additions & 20 deletions line/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from thrift.transport import TSocket
from thrift.transport import THttpClient
from thrift.protocol import TCompactProtocol

from linethrift import LineThrift

try:
import simplejson as json
except ImportError:
Expand All @@ -32,17 +35,17 @@ class LineClient(object):

LINE_DOMAIN = "http://gd2.line.naver.jp"

LINE_HTTP_URL = LINE_DOMAIN + "/api/v4/TalkService.do"
LINE_SESSION_URL = LINE_DOMAIN + "/authct/v1/keys/line"
LINE_HTTP_URL = LINE_DOMAIN + "/api/v4/TalkService.do"
LINE_SESSION_URL = LINE_DOMAIN + "/authct/v1/keys/line"
LINE_CERTIFICATE_URL = LINE_DOMAIN + "/Q"

provider = None
certificate = None
ip = "127.0.0.1"
version = "3.7.0"
comm_name = "carpedm20"
com_name = "carpedm20"

_session = requests.session()
_headers = {}

def __init__(self, id, password, is_mac=True):
"""Initialize LINE instance with provided information
Expand All @@ -53,8 +56,19 @@ def __init__(self, id, password, is_mac=True):
self.password = password
self.is_mac = is_mac

pin_code = self._login()
print pin_code
self._login()

print "Enter PinCode '%s' to your mobile phone" % self._pinCode

def get_json(self, url):
return json.loads(self._session.get(url, headers=self._headers).text)

def login(self):
j = self.get_json(self.LINE_CERTIFICATE_URL)
self.verifier = j['result']['verifier']

msg = self.client.loginWithVerifierForCertificate(self.verifier)
print msg

def _login(self):
"""Login to LINE server."""
Expand All @@ -75,8 +89,7 @@ def _login(self):
self._headers['User-Agent'] = user_agent
self._headers['X-Line-Application'] = application

r = self._session.get(self.LINE_SESSION_URL, headers=self._headers)
j = json.loads(r.text)
j = self.get_json(self.LINE_SESSION_URL)

session_key = j['session_key']
message = (chr(len(session_key)) + session_key +
Expand All @@ -86,17 +99,16 @@ def _login(self):
keyname, n, e = j['rsa_key'].split(",")
pub_key = rsa.PublicKey(int(n,16), int(e,16))
crypto = rsa.encrypt(message, pub_key).encode('hex')
print crypto
print self._header

transport = THttpClient.THttpClient(self.LINE_HTTP_URL)
transport.setCustomHeaders(self._header)

protocol = TCompactProtocol.TCompactProtocol(transport)
transport.setCustomHeaders(self._headers)

client = Line.Client(protocol)
#msg = client.loginWithIdentityCredentialForCertificate(
# user, message, keyname, crypto, False,
# ip, com_name, self.provider, "")
self.protocol = TCompactProtocol.TCompactProtocol(transport)
self.client = LineThrift.Client(self.protocol)

return msg
msg = self.client.loginWithIdentityCredentialForCertificate(
self.id, self.password, False, self.ip,
self.com_name, self.provider, crypto)

self._headers['X-Line-Access'] = msg.verifier
self._pinCode = msg.pinCode
16 changes: 16 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
base="line"
linethrift="$base/linethrift"
if [ -d "$linethrift" ]; then
echo "$linethrift already exists"
rm -rf $linethrift
mkdir $linethrift
else
mkdir $linethrift
fi

thrift -out $linethrift --gen py:new_style $base/line.thrift

rm $linethrift/__init__.py
mv $linethrift/linethrift/*.py $linethrift
rm -rf $linethrift/linethrift

0 comments on commit da01a65

Please sign in to comment.