├── .gitignore ├── LINEPY ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-36.pyc │ ├── auth.cpython-36.pyc │ ├── call.cpython-36.pyc │ ├── callback.cpython-36.pyc │ ├── channel.cpython-36.pyc │ ├── client.cpython-36.pyc │ ├── config.cpython-36.pyc │ ├── models.cpython-36.pyc │ ├── object.cpython-36.pyc │ ├── oepoll.cpython-36.pyc │ ├── server.cpython-36.pyc │ ├── session.cpython-36.pyc │ ├── square.cpython-36.pyc │ ├── talk.cpython-36.pyc │ └── timeline.cpython-36.pyc ├── auth.py ├── call.py ├── callback.py ├── channel.py ├── client.py ├── config.py ├── models.py ├── object.py ├── oepoll.py ├── server.py ├── session.py ├── square.py ├── talk.py └── timeline.py ├── README.md ├── akad ├── AccountSupervisorService.py ├── AgeCheckService.py ├── AuthService.py ├── BotService.py ├── BuddyManagementService.py ├── BuddyService.py ├── CallService.py ├── ChannelApplicationProvidedService.py ├── ChannelService.py ├── MessageService.py ├── ShopService.py ├── SnsAdaptorService.py ├── SpotService.py ├── SquareService.py ├── TalkService.py ├── UniversalNotificationService.py ├── __init__.py ├── __pycache__ │ ├── AccountSupervisorService.cpython-36.pyc │ ├── AgeCheckService.cpython-36.pyc │ ├── AuthService.cpython-36.pyc │ ├── BotService.cpython-36.pyc │ ├── BuddyManagementService.cpython-36.pyc │ ├── BuddyService.cpython-36.pyc │ ├── CallService.cpython-36.pyc │ ├── ChannelApplicationProvidedService.cpython-36.pyc │ ├── ChannelService.cpython-36.pyc │ ├── MessageService.cpython-36.pyc │ ├── ShopService.cpython-36.pyc │ ├── SnsAdaptorService.cpython-36.pyc │ ├── SpotService.cpython-36.pyc │ ├── SquareService.cpython-36.pyc │ ├── TalkService.cpython-36.pyc │ ├── UniversalNotificationService.cpython-36.pyc │ ├── __init__.cpython-36.pyc │ ├── constants.cpython-36.pyc │ └── ttypes.cpython-36.pyc ├── constants.py └── ttypes.py ├── protectpy3.py └── st2__b.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /LINEPY/__init__.py: -------------------------------------------------------------------------------- 1 | from .client import LINE 2 | from .call import Call 3 | from .channel import Channel 4 | from .oepoll import OEPoll 5 | from akad.ttypes import OpType 6 | 7 | __copyright__ = 'Copyright 2018 by Fadhiil Rachman' 8 | __version__ = '3.0.8' 9 | __license__ = 'BSD-3-Clause' 10 | __author__ = 'Fadhiil Rachman' 11 | __author_email__ = 'fadhiilrachman@gmail.com' 12 | __url__ = 'http://github.com/fadhiilrachman/line-py' 13 | 14 | __all__ = ['LINE', 'Channel', 'OEPoll', 'OpType', 'Call'] -------------------------------------------------------------------------------- /LINEPY/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/auth.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/auth.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/call.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/call.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/callback.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/callback.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/channel.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/channel.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/client.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/client.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/config.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/config.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/models.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/models.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/object.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/object.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/oepoll.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/oepoll.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/server.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/server.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/session.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/session.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/square.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/square.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/talk.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/talk.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/__pycache__/timeline.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/LINEPY/__pycache__/timeline.cpython-36.pyc -------------------------------------------------------------------------------- /LINEPY/auth.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from akad.ttypes import IdentityProvider, LoginResultType, LoginRequest, LoginType 3 | from .server import Server 4 | from .session import Session 5 | from .callback import Callback 6 | 7 | import rsa, os 8 | 9 | class Auth(object): 10 | isLogin = False 11 | authToken = "" 12 | certificate = "" 13 | 14 | def __init__(self): 15 | self.server = Server() 16 | self.callback = Callback(self.__defaultCallback) 17 | self.server.setHeadersWithDict({ 18 | 'User-Agent': self.server.USER_AGENT, 19 | 'X-Line-Application': self.server.APP_NAME, 20 | 'X-Line-Carrier': self.server.CARRIER 21 | }) 22 | 23 | def __loadSession(self): 24 | self.talk = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_API_QUERY_PATH_FIR).Talk() 25 | self.poll = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_POLL_QUERY_PATH_FIR).Talk() 26 | self.call = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_CALL_QUERY_PATH).Call() 27 | self.channel = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_CHAN_QUERY_PATH).Channel() 28 | self.square = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_SQUARE_QUERY_PATH).Square() 29 | 30 | self.revision = self.poll.getLastOpRevision() 31 | self.isLogin = True 32 | 33 | def __loginRequest(self, type, data): 34 | lReq = LoginRequest() 35 | if type == '0': 36 | lReq.type = LoginType.ID_CREDENTIAL 37 | lReq.identityProvider = data['identityProvider'] 38 | lReq.identifier = data['identifier'] 39 | lReq.password = data['password'] 40 | lReq.keepLoggedIn = data['keepLoggedIn'] 41 | lReq.accessLocation = data['accessLocation'] 42 | lReq.systemName = data['systemName'] 43 | lReq.certificate = data['certificate'] 44 | lReq.e2eeVersion = data['e2eeVersion'] 45 | elif type == '1': 46 | lReq.type = LoginType.QRCODE 47 | lReq.keepLoggedIn = data['keepLoggedIn'] 48 | if 'identityProvider' in data: 49 | lReq.identityProvider = data['identityProvider'] 50 | if 'accessLocation' in data: 51 | lReq.accessLocation = data['accessLocation'] 52 | if 'systemName' in data: 53 | lReq.systemName = data['systemName'] 54 | lReq.verifier = data['verifier'] 55 | lReq.e2eeVersion = data['e2eeVersion'] 56 | else: 57 | lReq=False 58 | return lReq 59 | 60 | def loginWithCredential(self, _id, passwd, certificate=None, systemName=None, appName=None, keepLoggedIn=True): 61 | if systemName is None: 62 | systemName=self.server.SYSTEM_NAME 63 | if self.server.EMAIL_REGEX.match(_id): 64 | self.provider = IdentityProvider.LINE # LINE 65 | else: 66 | self.provider = IdentityProvider.NAVER_KR # NAVER 67 | 68 | if appName is None: 69 | appName=self.server.APP_NAME 70 | self.server.setHeaders('X-Line-Application', appName) 71 | self.tauth = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_AUTH_QUERY_PATH).Talk(isopen=False) 72 | 73 | rsaKey = self.tauth.getRSAKeyInfo(self.provider) 74 | 75 | message = (chr(len(rsaKey.sessionKey)) + rsaKey.sessionKey + 76 | chr(len(_id)) + _id + 77 | chr(len(passwd)) + passwd).encode('utf-8') 78 | pub_key = rsa.PublicKey(int(rsaKey.nvalue, 16), int(rsaKey.evalue, 16)) 79 | crypto = rsa.encrypt(message, pub_key).hex() 80 | 81 | try: 82 | with open(_id + '.crt', 'r') as f: 83 | self.certificate = f.read() 84 | except: 85 | if certificate is not None: 86 | self.certificate = certificate 87 | if os.path.exists(certificate): 88 | with open(certificate, 'r') as f: 89 | self.certificate = f.read() 90 | 91 | self.auth = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_LOGIN_QUERY_PATH).Auth(isopen=False) 92 | 93 | lReq = self.__loginRequest('0', { 94 | 'identityProvider': self.provider, 95 | 'identifier': rsaKey.keynm, 96 | 'password': crypto, 97 | 'keepLoggedIn': keepLoggedIn, 98 | 'accessLocation': self.server.IP_ADDR, 99 | 'systemName': systemName, 100 | 'certificate': self.certificate, 101 | 'e2eeVersion': 0 102 | }) 103 | 104 | result = self.auth.loginZ(lReq) 105 | 106 | if result.type == LoginResultType.REQUIRE_DEVICE_CONFIRM: 107 | self.callback.PinVerified(result.pinCode) 108 | 109 | self.server.setHeaders('X-Line-Access', result.verifier) 110 | getAccessKey = self.server.getJson(self.server.parseUrl(self.server.LINE_CERTIFICATE_PATH), allowHeader=True) 111 | 112 | self.auth = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_LOGIN_QUERY_PATH).Auth(isopen=False) 113 | 114 | try: 115 | lReq = self.__loginRequest('1', { 116 | 'keepLoggedIn': keepLoggedIn, 117 | 'verifier': getAccessKey['result']['verifier'], 118 | 'e2eeVersion': 0 119 | }) 120 | result = self.auth.loginZ(lReq) 121 | except: 122 | raise Exception('Login failed') 123 | 124 | if result.type == LoginResultType.SUCCESS: 125 | if result.certificate is not None: 126 | with open(_id + '.crt', 'w') as f: 127 | f.write(result.certificate) 128 | self.certificate = result.certificate 129 | if result.authToken is not None: 130 | self.loginWithAuthToken(result.authToken, appName) 131 | else: 132 | return False 133 | else: 134 | raise Exception('Login failed') 135 | 136 | elif result.type == LoginResultType.REQUIRE_QRCODE: 137 | self.loginWithQrCode(keepLoggedIn, systemName, appName) 138 | pass 139 | 140 | elif result.type == LoginResultType.SUCCESS: 141 | self.certificate = result.certificate 142 | self.loginWithAuthToken(result.authToken, appName) 143 | 144 | def loginWithQrCode(self, keepLoggedIn=True, systemName=None, appName=None, showQr=False): 145 | if systemName is None: 146 | systemName=self.server.SYSTEM_NAME 147 | if appName is None: 148 | appName=self.server.APP_NAME 149 | self.server.setHeaders('X-Line-Application', appName) 150 | 151 | self.tauth = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_AUTH_QUERY_PATH).Talk(isopen=False) 152 | qrCode = self.tauth.getAuthQrcode(keepLoggedIn, systemName) 153 | 154 | self.callback.QrUrl('line://au/q/' + qrCode.verifier, showQr) 155 | self.server.setHeaders('X-Line-Access', qrCode.verifier) 156 | 157 | getAccessKey = self.server.getJson(self.server.parseUrl(self.server.LINE_CERTIFICATE_PATH), allowHeader=True) 158 | 159 | self.auth = Session(self.server.LINE_HOST_DOMAIN, self.server.Headers, self.server.LINE_LOGIN_QUERY_PATH).Auth(isopen=False) 160 | 161 | try: 162 | lReq = self.__loginRequest('1', { 163 | 'keepLoggedIn': keepLoggedIn, 164 | 'systemName': systemName, 165 | 'identityProvider': IdentityProvider.LINE, 166 | 'verifier': getAccessKey['result']['verifier'], 167 | 'accessLocation': self.server.IP_ADDR, 168 | 'e2eeVersion': 0 169 | }) 170 | result = self.auth.loginZ(lReq) 171 | except: 172 | raise Exception('Login failed') 173 | 174 | if result.type == LoginResultType.SUCCESS: 175 | if result.authToken is not None: 176 | self.loginWithAuthToken(result.authToken, appName) 177 | else: 178 | return False 179 | else: 180 | raise Exception('Login failed') 181 | 182 | def loginWithAuthToken(self, authToken=None, appName=None): 183 | if authToken is None: 184 | raise Exception('Please provide Auth Token') 185 | if appName is None: 186 | appName=self.server.APP_NAME 187 | self.server.setHeadersWithDict({ 188 | 'X-Line-Application': appName, 189 | 'X-Line-Access': authToken 190 | }) 191 | self.authToken = authToken 192 | self.__loadSession() 193 | 194 | def __defaultCallback(self, str): 195 | print(str) 196 | 197 | def logout(self): 198 | self.auth.logoutZ() 199 | -------------------------------------------------------------------------------- /LINEPY/call.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from akad.ttypes import MediaType 3 | from types import * 4 | 5 | def loggedIn(func): 6 | def checkLogin(*args, **kwargs): 7 | if args[0].isLogin: 8 | return func(*args, **kwargs) 9 | else: 10 | args[0].callback.other('You want to call the function, you must login to LINE') 11 | return checkLogin 12 | 13 | class Call(object): 14 | isLogin = False 15 | 16 | def __init__(self): 17 | self.isLogin = True 18 | 19 | @loggedIn 20 | def acquireCallRoute(self, to): 21 | return self.call.acquireCallRoute(to) 22 | 23 | @loggedIn 24 | def acquireGroupCallRoute(self, groupId, mediaType=MediaType.AUDIO): 25 | return self.call.acquireGroupCallRoute(groupId, mediaType) 26 | 27 | @loggedIn 28 | def getGroupCall(self, ChatMid): 29 | return self.call.getGroupCall(ChatMid) 30 | 31 | @loggedIn 32 | def inviteIntoGroupCall(self, chatId, contactIds=[], mediaType=MediaType.AUDIO): 33 | return self.call.inviteIntoGroupCall(chatId, contactIds, mediaType) -------------------------------------------------------------------------------- /LINEPY/callback.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | class Callback(object): 3 | 4 | def __init__(self, callback): 5 | self.callback = callback 6 | 7 | def PinVerified(self, pin): 8 | self.callback("Input this PIN code '" + pin + "' on your LINE for smartphone in 2 minutes") 9 | 10 | def QrUrl(self, url, showQr=True): 11 | if showQr: 12 | notice='or scan this QR ' 13 | else: 14 | notice='' 15 | self.callback('Open this link ' + notice + 'on your LINE for smartphone in 2 minutes\n' + url) 16 | if showQr: 17 | try: 18 | import pyqrcode 19 | url = pyqrcode.create(url) 20 | self.callback(url.terminal('green', 'white', 1)) 21 | except: 22 | pass 23 | 24 | def default(self, str): 25 | self.callback(str) -------------------------------------------------------------------------------- /LINEPY/channel.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | def loggedIn(func): 4 | def checkLogin(*args, **kwargs): 5 | if args[0].isLogin: 6 | return func(*args, **kwargs) 7 | else: 8 | args[0].callback.other('You want to call the function, you must login to LINE') 9 | return checkLogin 10 | 11 | class Channel(object): 12 | isLogin = False 13 | channelId = None 14 | channelResult = None 15 | 16 | def __init__(self, client, channelId, showSuccess=True): 17 | self.client = client 18 | self.channelId = channelId 19 | self.showSuccess = showSuccess 20 | self.__loginChannel() 21 | 22 | def __logChannel(self, text): 23 | self.client.log('[%s] : Success login to %s' % (self.client.profile.displayName, text)) 24 | 25 | def __loginChannel(self): 26 | self.isLogin = True 27 | self.channelResult = self.approveChannelAndIssueChannelToken(self.channelId) 28 | self.__createChannelSession() 29 | 30 | @loggedIn 31 | def getChannelResult(self): 32 | return self.channelResult 33 | 34 | def __createChannelSession(self): 35 | channelInfo = self.getChannelInfo(self.channelId) 36 | if self.showSuccess: 37 | self.__logChannel(channelInfo.name) 38 | 39 | @loggedIn 40 | def approveChannelAndIssueChannelToken(self, channelId): 41 | return self.client.approveChannelAndIssueChannelToken(channelId) 42 | 43 | @loggedIn 44 | def issueChannelToken(self, channelId): 45 | return self.client.issueChannelToken(channelId) 46 | 47 | @loggedIn 48 | def getChannelInfo(self, channelId, locale='EN'): 49 | return self.client.getChannelInfo(channelId, locale) 50 | 51 | @loggedIn 52 | def revokeChannel(self, channelId): 53 | return self.client.revokeChannel(channelId) -------------------------------------------------------------------------------- /LINEPY/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from akad.ttypes import Message 3 | from .auth import Auth 4 | from .models import Models 5 | from .talk import Talk 6 | from .square import Square 7 | from .call import Call 8 | from .timeline import Timeline 9 | 10 | class LINE(Auth, Models, Talk, Square, Call, Timeline): 11 | 12 | def __init__(self, idOrAuthToken=None, passwd=None, certificate=None, systemName=None, appName=None, showQr=False, keepLoggedIn=True): 13 | 14 | Auth.__init__(self) 15 | if not (idOrAuthToken or idOrAuthToken and passwd): 16 | self.loginWithQrCode(keepLoggedIn=keepLoggedIn, systemName=systemName, appName=appName, showQr=showQr) 17 | if idOrAuthToken and passwd: 18 | self.loginWithCredential(_id=idOrAuthToken, passwd=passwd, certificate=certificate, systemName=systemName, appName=appName, keepLoggedIn=keepLoggedIn) 19 | elif idOrAuthToken and not passwd: 20 | self.loginWithAuthToken(authToken=idOrAuthToken, appName=appName) 21 | 22 | self.__initAll() 23 | 24 | def __initAll(self): 25 | 26 | self.profile = self.talk.getProfile() 27 | self.groups = self.talk.getGroupIdsJoined() 28 | 29 | Models.__init__(self) 30 | Talk.__init__(self) 31 | Square.__init__(self) 32 | Call.__init__(self) 33 | Timeline.__init__(self) 34 | 35 | -------------------------------------------------------------------------------- /LINEPY/config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from akad.ttypes import ApplicationType 3 | import re 4 | 5 | class Config(object): 6 | LINE_HOST_DOMAIN = 'https://gd2.line.naver.jp' 7 | LINE_OBS_DOMAIN = 'https://obs-sg.line-apps.com' 8 | LINE_TIMELINE_API = 'https://gd2.line.naver.jp/mh/api' 9 | LINE_TIMELINE_MH = 'https://gd2.line.naver.jp/mh' 10 | 11 | LINE_LOGIN_QUERY_PATH = '/api/v4p/rs' 12 | LINE_AUTH_QUERY_PATH = '/api/v4/TalkService.do' 13 | 14 | LINE_API_QUERY_PATH_FIR = '/S4' 15 | LINE_POLL_QUERY_PATH_FIR = '/P4' 16 | LINE_CALL_QUERY_PATH = '/V4' 17 | LINE_CERTIFICATE_PATH = '/Q' 18 | LINE_CHAN_QUERY_PATH = '/CH4' 19 | LINE_SQUARE_QUERY_PATH = '/SQS1' 20 | 21 | CHANNEL_ID = { 22 | 'LINE_TIMELINE': '1341209850', 23 | 'LINE_WEBTOON': '1401600689', 24 | 'LINE_TODAY': '1518712866', 25 | 'LINE_STORE': '1376922440', 26 | 'LINE_MUSIC': '1381425814', 27 | 'LINE_SERVICES': '1459630796' 28 | } 29 | 30 | APP_TYPE = ApplicationType._VALUES_TO_NAMES[368] 31 | APP_VER = '8.0.3' 32 | CARRIER = '51089, 1-0' 33 | SYSTEM_NAME = 'CHROMEOS' 34 | SYSTEM_VER = '10.12.0' 35 | IP_ADDR = '8.8.8.8' 36 | EMAIL_REGEX = re.compile(r"[^@]+@[^@]+\.[^@]+") 37 | 38 | def __init__(self): 39 | self.APP_NAME = '%s\t%s\t%s\t%s' % (self.APP_TYPE, self.APP_VER, self.SYSTEM_NAME, self.SYSTEM_VER) 40 | self.USER_AGENT = 'Line/%s' % self.APP_VER 41 | -------------------------------------------------------------------------------- /LINEPY/models.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from datetime import datetime 3 | from .object import Object 4 | from random import randint 5 | 6 | import json, shutil, time, os, base64, tempfile 7 | 8 | class Models(Object): 9 | 10 | def __init__(self): 11 | Object.__init__(self) 12 | 13 | """Text""" 14 | 15 | def log(self, text): 16 | print("[%s] %s" % (str(datetime.now()), text)) 17 | 18 | """File""" 19 | 20 | def saveFile(self, path, raw): 21 | with open(path, 'wb') as f: 22 | shutil.copyfileobj(raw, f) 23 | 24 | def deleteFile(self, path): 25 | if os.path.exists(path): 26 | os.remove(path) 27 | return True 28 | else: 29 | return False 30 | 31 | def downloadFileURL(self, fileUrl, returnAs='path', saveAs='', headers=None): 32 | if returnAs not in ['path','bool','bin']: 33 | raise Exception('Invalid returnAs value') 34 | if saveAs == '': 35 | saveAs = self.genTempFile() 36 | r = self.server.getContent(fileUrl, headers=headers) 37 | if r.status_code != 404: 38 | self.saveFile(saveAs, r.raw) 39 | if returnAs == 'path': 40 | return saveAs 41 | elif returnAs == 'bool': 42 | return True 43 | elif returnAs == 'bin': 44 | return r.raw 45 | else: 46 | raise Exception('Download file failure.') 47 | 48 | """Generator""" 49 | 50 | def genTempFile(self, returnAs='path'): 51 | try: 52 | if returnAs not in ['file','path']: 53 | raise Exception('Invalid returnAs value') 54 | fName, fPath = 'linepy-%s-%i.bin' % (int(time.time()), randint(0, 9)), tempfile.gettempdir() 55 | if returnAs == 'file': 56 | return fName 57 | elif returnAs == 'path': 58 | return os.path.join(fPath, fName) 59 | except: 60 | raise Exception('tempfile is required') 61 | 62 | def genOBSParams(self, newList, returnAs='json'): 63 | oldList = {'name': self.genTempFile('file'),'ver': '1.0'} 64 | if returnAs not in ['json','b64','default']: 65 | raise Exception('Invalid parameter returnAs') 66 | oldList.update(newList) 67 | if 'range' in oldList: 68 | new_range='bytes 0-%s\/%s' % ( str(oldList['range']-1), str(oldList['range']) ) 69 | oldList.update({'range': new_range}) 70 | if returnAs == 'json': 71 | oldList=json.dumps(oldList) 72 | return oldList 73 | elif returnAs == 'b64': 74 | oldList=json.dumps(oldList) 75 | return base64.b64encode(oldList.encode('utf-8')) 76 | elif returnAs == 'default': 77 | return oldList -------------------------------------------------------------------------------- /LINEPY/object.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from datetime import datetime 3 | import json, time, ntpath 4 | 5 | def loggedIn(func): 6 | def checkLogin(*args, **kwargs): 7 | if args[0].isLogin: 8 | return func(*args, **kwargs) 9 | else: 10 | args[0].callback.other('You want to call the function, you must login to LINE') 11 | return checkLogin 12 | 13 | class Object(object): 14 | 15 | def __init__(self): 16 | if self.isLogin == True: 17 | self.log("[%s] : Login success" % self.profile.displayName) 18 | 19 | """Group""" 20 | 21 | @loggedIn 22 | def updateGroupPicture(self, groupId, path): 23 | files = {'file': open(path, 'rb')} 24 | data = {'params': self.genOBSParams({'oid': groupId,'type': 'image'})} 25 | r = self.server.postContent(self.server.LINE_OBS_DOMAIN + '/talk/g/upload.nhn', data=data, files=files) 26 | if r.status_code != 201: 27 | raise Exception('Update group picture failure.') 28 | return True 29 | 30 | """Personalize""" 31 | 32 | @loggedIn 33 | def updateProfilePicture(self, path, type='p'): 34 | files = {'file': open(path, 'rb')} 35 | params = {'oid': self.profile.mid,'type': 'image'} 36 | if type == 'vp': 37 | params.update({'ver': '2.0', 'cat': 'vp.mp4'}) 38 | data = {'params': self.genOBSParams(params)} 39 | r = self.server.postContent(self.server.LINE_OBS_DOMAIN + '/talk/p/upload.nhn', data=data, files=files) 40 | if r.status_code != 201: 41 | raise Exception('Update profile picture failure.') 42 | return True 43 | 44 | @loggedIn 45 | def updateProfileVideoPicture(self, path): 46 | try: 47 | from ffmpy import FFmpeg 48 | files = {'file': open(path, 'rb')} 49 | data = {'params': self.genOBSParams({'oid': self.profile.mid,'ver': '2.0','type': 'video','cat': 'vp.mp4'})} 50 | r_vp = self.server.postContent(self.server.LINE_OBS_DOMAIN + '/talk/vp/upload.nhn', data=data, files=files) 51 | if r_vp.status_code != 201: 52 | raise Exception('Update profile video picture failure.') 53 | path_p = self.genTempFile('path') 54 | ff = FFmpeg(inputs={'%s' % path: None}, outputs={'%s' % path_p: ['-ss', '00:00:2', '-vframes', '1']}) 55 | ff.run() 56 | self.updateProfilePicture(path_p, 'vp') 57 | except: 58 | raise Exception('You should install FFmpeg and ffmpy from pypi') 59 | 60 | @loggedIn 61 | def updateProfileCover(self, path, returnAs='bool'): 62 | if returnAs not in ['objId','bool']: 63 | raise Exception('Invalid returnAs value') 64 | objId = self.uploadObjHome(path, type='image', returnAs='objId') 65 | home = self.updateProfileCoverById(objId) 66 | if returnAs == 'objId': 67 | return objId 68 | elif returnAs == 'bool': 69 | return True 70 | 71 | """Object""" 72 | 73 | @loggedIn 74 | def uploadObjSquare(self, squareChatMid, path, type='image', returnAs='bool'): 75 | if returnAs not in ['bool']: 76 | raise Exception('Invalid returnAs value') 77 | if type not in ['image','gif','video','audio','file']: 78 | raise Exception('Invalid type value') 79 | data = open(path, 'rb').read() 80 | params = { 81 | 'oid': 'reqseq', 82 | 'reqseq': '%s' % str(self.revision), 83 | 'tomid': '%s' % str(squareChatMid), 84 | 'size': '%s' % str(len(data)), 85 | 'range': len(data), 86 | 'type': '%s' % str(type) 87 | } 88 | if type == 'image': 89 | contentType = 'image/jpeg' 90 | elif type == 'gif': 91 | contentType = 'image/gif' 92 | elif type == 'video': 93 | params.update({'duration': '60000'}) 94 | contentType = 'video/mp4' 95 | elif type == 'audio': 96 | params.update({'duration': '0'}) 97 | contentType = 'audio/mp3' 98 | headers = self.server.additionalHeaders(self.server.Headers, { 99 | 'content-type': contentType, 100 | 'Content-Length': str(len(data)), 101 | 'x-obs-params': self.genOBSParams(params,'b64'), 102 | 'X-Line-Access': self.squareObsToken 103 | }) 104 | r = self.server.postContent(self.server.LINE_OBS_DOMAIN + '/r/g2/m/reqseq', data=data, headers=headers) 105 | if r.status_code != 201: 106 | raise Exception('Upload %s failure.' % type) 107 | if returnAs == 'bool': 108 | return True 109 | 110 | @loggedIn 111 | def uploadObjTalk(self, path, type='image', returnAs='bool', objId=None, to=None): 112 | if returnAs not in ['objId','bool']: 113 | raise Exception('Invalid returnAs value') 114 | if type not in ['image','gif','video','audio','file']: 115 | raise Exception('Invalid type value') 116 | headers=None 117 | files = {'file': open(path, 'rb')} 118 | if type == 'image' or type == 'video' or type == 'audio' or type == 'file': 119 | e_p = self.server.LINE_OBS_DOMAIN + '/talk/m/upload.nhn' 120 | data = {'params': self.genOBSParams({'oid': objId,'size': len(open(path, 'rb').read()),'type': type})} 121 | elif type == 'gif': 122 | e_p = self.server.LINE_OBS_DOMAIN + '/r/talk/m/reqseq' 123 | files = None 124 | data = open(path, 'rb').read() 125 | params = { 126 | 'oid': 'reqseq', 127 | 'reqseq': '%s' % str(self.revision), 128 | 'tomid': '%s' % str(to), 129 | 'size': '%s' % str(len(data)), 130 | 'range': len(data), 131 | 'type': 'image' 132 | } 133 | headers = self.server.additionalHeaders(self.server.Headers, { 134 | 'Content-Type': 'image/gif', 135 | 'Content-Length': str(len(data)), 136 | 'x-obs-params': self.genOBSParams(params,'b64') 137 | }) 138 | r = self.server.postContent(e_p, data=data, headers=headers, files=files) 139 | if r.status_code != 201: 140 | raise Exception('Upload %s failure.' % type) 141 | if returnAs == 'objId': 142 | return objId 143 | elif returnAs == 'bool': 144 | return True 145 | 146 | @loggedIn 147 | def uploadObjHome(self, path, type='image', returnAs='bool', objId=None): 148 | if returnAs not in ['objId','bool']: 149 | raise Exception('Invalid returnAs value') 150 | if type not in ['image','video','audio']: 151 | raise Exception('Invalid type value') 152 | if type == 'image': 153 | contentType = 'image/jpeg' 154 | elif type == 'video': 155 | contentType = 'video/mp4' 156 | elif type == 'audio': 157 | contentType = 'audio/mp3' 158 | if not objId: 159 | objId = int(time.time()) 160 | file = open(path, 'rb').read() 161 | params = { 162 | 'userid': '%s' % self.profile.mid, 163 | 'oid': '%s' % str(objId), 164 | 'range': len(file), 165 | 'type': type 166 | } 167 | hr = self.server.additionalHeaders(self.server.timelineHeaders, { 168 | 'Content-Type': contentType, 169 | 'Content-Length': str(len(file)), 170 | 'x-obs-params': self.genOBSParams(params,'b64') 171 | }) 172 | r = self.server.postContent(self.server.LINE_OBS_DOMAIN + '/myhome/c/upload.nhn', headers=hr, data=file) 173 | if r.status_code != 201: 174 | raise Exception('Upload object home failure.') 175 | if returnAs == 'objId': 176 | return objId 177 | elif returnAs == 'bool': 178 | return True 179 | 180 | @loggedIn 181 | def downloadObjectMsg(self, messageId, returnAs='path', saveAs=''): 182 | if saveAs == '': 183 | saveAs = self.genTempFile('path') 184 | if returnAs not in ['path','bool','bin']: 185 | raise Exception('Invalid returnAs value') 186 | params = {'oid': messageId} 187 | url = self.server.urlEncode(self.server.LINE_OBS_DOMAIN, '/talk/m/download.nhn', params) 188 | r = self.server.getContent(url) 189 | if r.status_code == 200: 190 | self.saveFile(saveAs, r.raw) 191 | if returnAs == 'path': 192 | return saveAs 193 | elif returnAs == 'bool': 194 | return True 195 | elif returnAs == 'bin': 196 | return r.raw 197 | else: 198 | raise Exception('Download object failure.') 199 | 200 | @loggedIn 201 | def forwardObjectMsg(self, to, msgId, contentType='image'): 202 | if contentType not in ['image','video','audio']: 203 | raise Exception('Type not valid.') 204 | data = self.genOBSParams({'oid': 'reqseq','reqseq': self.revision,'type': contentType,'copyFrom': '/talk/m/%s' % msgId},'default') 205 | r = self.server.postContent(self.server.LINE_OBS_DOMAIN + '/talk/m/copy.nhn', data=data) 206 | if r.status_code != 200: 207 | raise Exception('Forward object failure.') 208 | return True -------------------------------------------------------------------------------- /LINEPY/oepoll.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from .client import LINE 3 | from types import * 4 | 5 | import os, sys, threading, time 6 | 7 | class OEPoll(object): 8 | OpInterrupt = {} 9 | client = None 10 | __squareSubId = {} 11 | __squareSyncToken = {} 12 | 13 | def __init__(self, client): 14 | if type(client) is not LINE: 15 | raise Exception("You need to set LINE instance to initialize LinePoll") 16 | self.client = client 17 | 18 | def fetchOperation(self, revision, count=1): 19 | return self.client.poll.fetchOperations(revision, count) 20 | 21 | def addOpInterruptWithDict(self, OpInterruptDict): 22 | self.OpInterrupt.update(OpInterruptDict) 23 | 24 | def addOpInterrupt(self, OperationType, DisposeFunc): 25 | self.OpInterrupt[OperationType] = DisposeFunc 26 | 27 | def execute(self, op, thread): 28 | try: 29 | if thread == True: 30 | _td = threading.Thread(target=self.OpInterrupt[op.type], args=(op,)) 31 | _td.daemon = False 32 | _td.start() 33 | else: 34 | self.OpInterrupt[op.type](op) 35 | except Exception as e: 36 | self.client.log(e) 37 | 38 | def setRevision(self, revision): 39 | self.client.revision = max(revision, self.client.revision) 40 | 41 | def singleTrace(self, count=2): 42 | try: 43 | operations = self.fetchOperation(self.client.revision, count=count) 44 | except KeyboardInterrupt: 45 | exit() 46 | except: 47 | return 48 | 49 | if operations is None: 50 | self.client.log('No operation available now.') 51 | else: 52 | return operations 53 | 54 | def trace(self, thread=False): 55 | try: 56 | operations = self.fetchOperation(self.client.revision) 57 | except KeyboardInterrupt: 58 | exit() 59 | except: 60 | return 61 | 62 | for op in operations: 63 | if op.type in self.OpInterrupt.keys(): 64 | self.execute(op, thread) 65 | self.setRevision(op.revision) 66 | -------------------------------------------------------------------------------- /LINEPY/server.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from .config import Config 3 | import json, requests, urllib 4 | 5 | class Server(Config): 6 | _session = requests.session() 7 | timelineHeaders = {} 8 | Headers = {} 9 | 10 | def __init__(self): 11 | self.Headers = {} 12 | self.channelHeaders = {} 13 | Config.__init__(self) 14 | 15 | def parseUrl(self, path): 16 | return self.LINE_HOST_DOMAIN + path 17 | 18 | def urlEncode(self, url, path, params=[]): 19 | return url + path + '?' + urllib.parse.urlencode(params) 20 | 21 | def getJson(self, url, allowHeader=False): 22 | if allowHeader is False: 23 | return json.loads(self._session.get(url).text) 24 | else: 25 | return json.loads(self._session.get(url, headers=self.Headers).text) 26 | 27 | def setHeadersWithDict(self, headersDict): 28 | self.Headers.update(headersDict) 29 | 30 | def setHeaders(self, argument, value): 31 | self.Headers[argument] = value 32 | 33 | def setTimelineHeadersWithDict(self, headersDict): 34 | self.timelineHeaders.update(headersDict) 35 | 36 | def setTimelineHeaders(self, argument, value): 37 | self.timelineHeaders[argument] = value 38 | 39 | def additionalHeaders(self, source, newSource): 40 | headerList={} 41 | headerList.update(source) 42 | headerList.update(newSource) 43 | return headerList 44 | 45 | def optionsContent(self, url, data=None, headers=None): 46 | if headers is None: 47 | headers=self.Headers 48 | return self._session.options(url, headers=headers, data=data) 49 | 50 | def postContent(self, url, data=None, files=None, headers=None): 51 | if headers is None: 52 | headers=self.Headers 53 | return self._session.post(url, headers=headers, data=data, files=files) 54 | 55 | def getContent(self, url, headers=None): 56 | if headers is None: 57 | headers=self.Headers 58 | return self._session.get(url, headers=headers, stream=True) 59 | 60 | def deleteContent(self, url, data=None, headers=None): 61 | if headers is None: 62 | headers=self.Headers 63 | return self._session.delete(url, headers=headers, data=data) 64 | 65 | def putContent(self, url, data=None, headers=None): 66 | if headers is None: 67 | headers=self.Headers 68 | return self._session.put(url, headers=headers, data=data) -------------------------------------------------------------------------------- /LINEPY/session.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from thrift.transport import THttpClient 3 | from thrift.protocol import TCompactProtocol 4 | from akad import AuthService, TalkService, ChannelService, CallService, SquareService 5 | 6 | class Session: 7 | 8 | def __init__(self, url, headers, path=''): 9 | self.host = url + path 10 | self.headers = headers 11 | 12 | def Auth(self, isopen=True): 13 | self.transport = THttpClient.THttpClient(self.host) 14 | self.transport.setCustomHeaders(self.headers) 15 | 16 | self.protocol = TCompactProtocol.TCompactProtocol(self.transport) 17 | self._auth = AuthService.Client(self.protocol) 18 | 19 | if isopen: 20 | self.transport.open() 21 | 22 | return self._auth 23 | 24 | def Talk(self, isopen=True): 25 | self.transport = THttpClient.THttpClient(self.host) 26 | self.transport.setCustomHeaders(self.headers) 27 | 28 | self.protocol = TCompactProtocol.TCompactProtocol(self.transport) 29 | self._talk = TalkService.Client(self.protocol) 30 | 31 | if isopen: 32 | self.transport.open() 33 | 34 | return self._talk 35 | 36 | def Channel(self, isopen=True): 37 | self.transport = THttpClient.THttpClient(self.host) 38 | self.transport.setCustomHeaders(self.headers) 39 | 40 | self.protocol = TCompactProtocol.TCompactProtocol(self.transport) 41 | self._channel = ChannelService.Client(self.protocol) 42 | 43 | if isopen: 44 | self.transport.open() 45 | 46 | return self._channel 47 | 48 | def Call(self, isopen=True): 49 | self.transport = THttpClient.THttpClient(self.host) 50 | self.transport.setCustomHeaders(self.headers) 51 | 52 | self.protocol = TCompactProtocol.TCompactProtocol(self.transport) 53 | self._call = CallService.Client(self.protocol) 54 | 55 | if isopen: 56 | self.transport.open() 57 | 58 | return self._call 59 | 60 | def Square(self, isopen=True): 61 | self.transport = THttpClient.THttpClient(self.host) 62 | self.transport.setCustomHeaders(self.headers) 63 | 64 | self.protocol = TCompactProtocol.TCompactProtocol(self.transport) 65 | self._square = SquareService.Client(self.protocol) 66 | 67 | if isopen: 68 | self.transport.open() 69 | 70 | return self._square -------------------------------------------------------------------------------- /LINEPY/square.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from akad.ttypes import * 3 | from random import randint 4 | 5 | def loggedIn(func): 6 | def checkLogin(*args, **kwargs): 7 | if args[0].isSupportSquare: 8 | if args[0].isLogin: 9 | return func(*args, **kwargs) 10 | else: 11 | args[0].callback.other('You want to call the function, you must login to LINE') 12 | else: 13 | args[0].callback.other('Your LINE account is not support Square') 14 | return checkLogin 15 | 16 | class Square(object): 17 | isSupportSquare = False 18 | isLogin = False 19 | 20 | def __init__(self): 21 | self.isLogin = True 22 | try: 23 | self.isSupportSquare = True 24 | self.squares = self.getJoinedSquares().squares 25 | self.squareObsToken = self.acquireEncryptedAccessToken(2).split('\x1e')[1] 26 | except: 27 | self.isSupportSquare = False 28 | self.log('Your LINE account is not support Square') 29 | 30 | """Object""" 31 | 32 | @loggedIn 33 | def sendSquareImage(self, squareChatMid, path): # Under development 34 | return self.uploadObjSquare(squareChatMid=squareChatMid, path=path, type='image', returnAs='bool') 35 | 36 | @loggedIn 37 | def sendSquareImageWithURL(self, squareChatMid, url): # Under development 38 | path = self.downloadFileURL(url, 'path') 39 | return self.sendSquareImage(squareChatMid, path) 40 | 41 | @loggedIn 42 | def sendSquareGIF(self, squareChatMid, path): # Under development 43 | return self.uploadObjSquare(squareChatMid=squareChatMid, path=path, type='gif', returnAs='bool') 44 | 45 | @loggedIn 46 | def sendSquareGIFWithURL(self, squareChatMid, url): # Under development 47 | path = self.downloadFileURL(url, 'path') 48 | return self.sendSquareGIF(squareChatMid, path) 49 | 50 | @loggedIn 51 | def sendSquareVideo(self, squareChatMid, path): # Under development 52 | return self.uploadObjSquare(squareChatMid=squareChatMid, path=path, type='video', returnAs='bool') 53 | 54 | @loggedIn 55 | def sendSquareVideoWithURL(self, squareChatMid, url): # Under development 56 | path = self.downloadFileURL(url, 'path') 57 | return self.sendSquareVideo(squareChatMid, path) 58 | 59 | @loggedIn 60 | def sendSquareAudio(self, squareChatMid, path): # Under development 61 | return self.uploadObjSquare(squareChatMid=squareChatMid, path=path, type='audio', returnAs='bool') 62 | 63 | @loggedIn 64 | def sendSquareAudioWithURL(self, squareChatMid, url): # Under development 65 | path = self.downloadFileURL(url, 'path') 66 | return self.sendSquareAudio(squareChatMid, path) 67 | 68 | @loggedIn 69 | def sendSquareFile(self, squareChatMid, path): # Under development 70 | return self.uploadObjSquare(squareChatMid=squareChatMid, path=path, type='file', returnAs='bool') 71 | 72 | @loggedIn 73 | def sendSquareFileWithURL(self, squareChatMid, url, fileName=''): # Under development 74 | path = self.downloadFileURL(url, 'path') 75 | return self.sendSquareFile(squareChatMid, path, fileName) 76 | 77 | """Square Message""" 78 | 79 | @loggedIn 80 | def sendSquareMessage(self, squareChatMid, text, contentMetadata={}, contentType=0): 81 | rq = SendMessageRequest() 82 | rq.squareChatMid = squareChatMid 83 | rq.squareMessage = SquareMessage() 84 | msg = Message() 85 | msg.to = squareChatMid 86 | msg.text = text 87 | msg.contentType, msg.contentMetadata = contentType, contentMetadata 88 | rq.squareMessage.message = msg 89 | rq.squareMessage.fromType = 4 90 | if squareChatMid not in self._messageReq: 91 | self._messageReq[squareChatMid] = -1 92 | self._messageReq[squareChatMid] += 1 93 | rq.squareMessage.squareMessageRevision = self._messageReq[squareChatMid] 94 | return self.square.sendMessage(rq) 95 | 96 | @loggedIn 97 | def sendSquareSticker(self, squareChatMid, packageId, stickerId): 98 | contentMetadata = { 99 | 'STKVER': '100', 100 | 'STKPKGID': packageId, 101 | 'STKID': stickerId 102 | } 103 | return self.sendSquareMessage(squareChatMid, '', contentMetadata, 7) 104 | 105 | @loggedIn 106 | def sendSquareContact(self, squareChatMid, mid): 107 | contentMetadata = {'mid': mid} 108 | return self.sendSquareMessage(squareChatMid, '', contentMetadata, 13) 109 | 110 | @loggedIn 111 | def sendSquareGift(self, squareChatMid, productId, productType): 112 | if productType not in ['theme','sticker']: 113 | raise Exception('Invalid productType value') 114 | contentMetadata = { 115 | 'MSGTPL': str(randint(0, 10)), 116 | 'PRDTYPE': productType.upper(), 117 | 'STKPKGID' if productType == 'sticker' else 'PRDID': productId 118 | } 119 | return self.sendSquareMessage(squareChatMid, '', contentMetadata, 9) 120 | 121 | @loggedIn 122 | def destroySquareMessage(self, squareChatMid, messageId): 123 | rq = DestroyMessageRequest() 124 | rq.squareChatMid = squareChatMid 125 | rq.messageId = messageId 126 | return self.square.destroyMessage(rq) 127 | 128 | """Square""" 129 | 130 | @loggedIn 131 | def searchSquareMembers(self, squareMid, continuationToken=None, limit=50): 132 | rq = SearchSquareMembersRequest() 133 | rq.squareMid = squareMid 134 | rq.searchOption = SquareMemberSearchOption() 135 | rq.continuationToken = continuationToken 136 | rq.limit = limit 137 | return self.square.searchSquareMembers(rq) 138 | 139 | @loggedIn 140 | def findSquareByInvitationTicket(self, invitationTicket): 141 | rq = FindSquareByInvitationTicketRequest() 142 | rq.invitationTicket = invitationTicket 143 | return self.square.findSquareByInvitationTicket(rq) 144 | 145 | @loggedIn 146 | def approveSquareMembers(self, squareMid, requestedMemberMids=[]): 147 | rq = ApproveSquareMembersRequest() 148 | rq.squareMid = squareMid 149 | rq.requestedMemberMids = requestedMemberMids 150 | return self.square.approveSquareMembers(rq) 151 | 152 | @loggedIn 153 | def deleteSquare(self, mid): 154 | rq = DeleteSquareRequest() 155 | rq.mid = mid 156 | rq.revision = self.revision 157 | return self.square.deleteSquare(rq) 158 | 159 | @loggedIn 160 | def deleteSquareChat(self, squareChatMid): 161 | rq = DeleteSquareChatRequest() 162 | rq.squareChatMid = squareChatMid 163 | rq.revision = self.revision 164 | return self.square.deleteSquareChat(request) 165 | 166 | @loggedIn 167 | def createSquare(self, name, categoryID, welcomeMessage='', profileImageObsHash='', desc='', searchable=True, type=1, ableToUseInvitationTicket=True): 168 | rq = CreateSquareRequest() 169 | rq.square = Square() 170 | rq.square.name = name 171 | rq.square.categoryID = categoryID 172 | rq.square.welcomeMessage = welcomeMessage 173 | rq.square.profileImageObsHash = profileImageObsHash 174 | rq.square.desc = desc 175 | rq.square.searchable = searchable 176 | rq.square.type = type 177 | rq.square.ableToUseInvitationTicket = ableToUseInvitationTicket 178 | rq.creator = SquareMember() 179 | return self.square.createSquare(rq) 180 | 181 | @loggedIn 182 | def createSquareChat(self, squareMid, name, squareMemberMids): 183 | rq = CreateSquareChatRequest() 184 | rq.reqSeq = self.revision 185 | rq.squareChat = SquareChat() 186 | rq.squareChat.squareMid = squareMid 187 | rq.squareChat.name = name 188 | rq.squareMemberMids = squareMemberMids 189 | return self.square.createSquareChat(request) 190 | 191 | @loggedIn 192 | def fetchSquareChatEvents(self, squareChatMid, subscriptionId=0, syncToken='', limit=50, direction=2): 193 | rq = FetchSquareChatEventsRequest() 194 | rq.squareChatMid = squareChatMid 195 | rq.subscriptionId = subscriptionId 196 | rq.syncToken = syncToken 197 | rq.limit = limit 198 | rq.direction = direction 199 | return self.square.fetchSquareChatEvents(rq) 200 | 201 | @loggedIn 202 | def fetchMyEvents(self, subscriptionId=0, syncToken='', continuationToken=None, limit=50): 203 | rq = FetchMyEventsRequest() 204 | rq.subscriptionId = subscriptionId 205 | rq.syncToken = syncToken 206 | rq.continuationToken = continuationToken 207 | rq.limit = limit 208 | return self.square.fetchMyEvents(rq) 209 | 210 | @loggedIn 211 | def markAsRead(self, squareChatMid, messageId): 212 | rq = MarkAsReadRequest() 213 | rq.squareChatMid = squareChatMid 214 | rq.messageId = messageId 215 | return self.square.markAsRead(rq) 216 | 217 | @loggedIn 218 | def getSquareAuthority(self, squareMid): 219 | rq = GetSquareAuthorityRequest() 220 | rq.squareMid = squareMid 221 | return self.square.getSquareAuthority(rq) 222 | 223 | @loggedIn 224 | def leaveSquare(self, squareMid): 225 | rq = LeaveSquareRequest() 226 | rq.squareMid = squareMid 227 | return self.square.leaveSquare(rq) 228 | 229 | @loggedIn 230 | def leaveSquareChat(self, squareChatMid, squareChatMemberRevision, sayGoodbye=True): 231 | rq = LeaveSquareChatRequest() 232 | rq.squareChatMid = squareChatMid 233 | rq.sayGoodbye = sayGoodbye 234 | rq.squareChatMemberRevision = squareChatMemberRevision 235 | return self.square.leaveSquareChat(rq) 236 | 237 | @loggedIn 238 | def joinSquareChat(self, squareChatMid): 239 | rq = JoinSquareChatRequest() 240 | rq.squareChatMid = squareChatMid 241 | return self.square.joinSquareChat(rq) 242 | 243 | @loggedIn 244 | def joinSquare(self, squareMid, displayName, profileImageObsHash): 245 | rq = JoinSquareRequest() 246 | rq.squareMid = squareMid 247 | rq.member = SquareMember() 248 | rq.member.squareMid = squareMid 249 | rq.member.displayName = displayName 250 | rq.member.profileImageObsHash = profileImageObsHash 251 | return self.square.joinSquare(rq) 252 | 253 | @loggedIn 254 | def inviteToSquare(self, squareMid, squareChatMid, invitees=[]): 255 | rq = InviteToSquareRequest() 256 | rq.squareMid = squareMid 257 | rq.invitees = invitees 258 | rq.squareChatMid = squareChatMid 259 | return self.square.inviteToSquare(rq) 260 | 261 | @loggedIn 262 | def inviteToSquareChat(self, squareChatMid, inviteeMids=[]): 263 | rq = InviteToSquareChatRequest() 264 | rq.inviteeMids = inviteeMids 265 | rq.squareChatMid = squareChatMid 266 | return self.square.inviteToSquareChat(rq) 267 | 268 | @loggedIn 269 | def getSquareMember(self, squareMemberMid): 270 | rq = GetSquareMemberRequest() 271 | rq.squareMemberMid = squareMemberMid 272 | return self.square.getSquareMember(rq) 273 | 274 | @loggedIn 275 | def getSquareMembers(self, mids=[]): 276 | rq = GetSquareMembersRequest() 277 | rq.mids = mids 278 | return self.square.getSquareMembers(rq) 279 | 280 | @loggedIn 281 | def getSquareMemberRelation(self, squareMid, targetSquareMemberMid): 282 | rq = GetSquareMemberRelationRequest() 283 | rq.squareMid = squareMid 284 | rq.targetSquareMemberMid = targetSquareMemberMid 285 | return self.square.getSquareMemberRelation(rq) 286 | 287 | @loggedIn 288 | def getSquareMemberRelations(self, state=1, continuationToken=None, limit=50): 289 | rq = GetSquareMemberRelationsRequest() 290 | rq.state = state # 1 NONE, 2 BLOCKED 291 | rq.continuationToken = continuationToken 292 | rq.limit = limit 293 | return self.square.getSquareMemberRelations(rq) 294 | 295 | @loggedIn 296 | def getSquareChatMembers(self, squareChatMid, continuationToken=None, limit=50): 297 | rq = GetSquareChatMembersRequest() 298 | rq.squareChatMid = squareChatMid 299 | rq.continuationToken = continuationToken 300 | rq.limit = limit 301 | return self.square.getSquareChatMembers(rq) 302 | 303 | @loggedIn 304 | def getSquareChatStatus(self, squareChatMid): 305 | rq = GetSquareChatStatusRequest() 306 | rq.squareChatMid = squareChatMid 307 | return self.square.getSquareChatStatus(rq) 308 | 309 | @loggedIn 310 | def getSquareChat(self, squareChatMid): 311 | rq = GetSquareChatRequest() 312 | rq.squareChatMid = squareChatMid 313 | return self.square.getSquareChat(rq) 314 | 315 | @loggedIn 316 | def getSquare(self, mid): 317 | rq = GetSquareRequest() 318 | rq.mid = mid 319 | return self.square.getSquare(rq) 320 | 321 | @loggedIn 322 | def getSquareChatAnnouncements(self, squareChatMid): 323 | rq = GetSquareChatAnnouncementsRequest() 324 | rq.squareChatMid = squareChatMid 325 | return self.square.getSquareChatAnnouncements(rq) 326 | 327 | @loggedIn 328 | def deleteSquareChatAnnouncement(self, squareChatMid, announcementSeq): 329 | rq = DeleteSquareChatAnnouncementRequest() 330 | rq.squareChatMid = squareChatMid 331 | rq.squareChatMid = announcementSeq 332 | return self.square.deleteSquareChatAnnouncement(rq) 333 | 334 | @loggedIn 335 | def createSquareChatAnnouncement(self, squareChatMid, text, messageId='', senderSquareMemberMid=''): 336 | rq = CreateSquareChatAnnouncementRequest() 337 | rq.reqSeq = 0 338 | rq.squareChatMid = squareChatMid 339 | rq.squareChatAnnouncement = SquareChatAnnouncement() 340 | rq.squareChatAnnouncement.announcementSeq = 0 341 | rq.squareChatAnnouncement.type = 0 342 | rq.squareChatAnnouncement.contents = SquareChatAnnouncementContents() 343 | rq.squareChatAnnouncement.contents.textMessageAnnouncementContents = TextMessageAnnouncementContents() 344 | rq.squareChatAnnouncement.contents.textMessageAnnouncementContents.messageId = messageId 345 | rq.squareChatAnnouncement.contents.textMessageAnnouncementContents.text = text 346 | rq.squareChatAnnouncement.contents.textMessageAnnouncementContents.senderSquareMemberMid = senderSquareMemberMid 347 | return self.square.createSquareChatAnnouncement(rq) 348 | 349 | @loggedIn 350 | def getJoinedSquares(self, continuationToken=None, limit=50): 351 | rq = GetJoinedSquaresRequest() 352 | rq.continuationToken = continuationToken 353 | rq.limit = limit 354 | return self.square.getJoinedSquares(rq) 355 | 356 | @loggedIn 357 | def getJoinedSquareChats(self, continuationToken=None, limit=50): 358 | rq = GetJoinedSquareChatsRequest() 359 | rq.continuationToken = continuationToken 360 | rq.limit = limit 361 | return self.square.getJoinedSquareChats(rq) 362 | 363 | @loggedIn 364 | def getJoinableSquareChats(self, squareMid, continuationToken=None, limit=50): 365 | rq = GetJoinableSquareChatsRequest() 366 | rq.squareMid = squareMid 367 | rq.continuationToken = continuationToken 368 | rq.limit = limit 369 | return self.square.getJoinableSquareChats(rq) 370 | 371 | @loggedIn 372 | def getInvitationTicketUrl(self, mid): 373 | rq = GetInvitationTicketUrlRequest() 374 | rq.mid = mid 375 | return self.square.getInvitationTicketUrl(rq) 376 | 377 | @loggedIn 378 | def getSquareStatus(self, squareMid): 379 | rq = GetSquareStatusRequest() 380 | rq.squareMid = squareMid 381 | return self.square.getSquareStatus(rq) 382 | 383 | @loggedIn 384 | def getNoteStatus(self, squareMid): 385 | rq = GetNoteStatusRequest() 386 | rq.squareMid = squareMid 387 | return self.square.getNoteStatus(rq) 388 | 389 | @loggedIn 390 | def searchSquares(self, query, continuationToken=None, limit=50): 391 | rq = SearchSquaresRequest() 392 | rq.query = query 393 | rq.continuationToken = continuationToken 394 | rq.limit = limit 395 | return self.square.searchSquares(rq) 396 | 397 | @loggedIn 398 | def refreshSubscriptions(self, subscriptions=[]): 399 | rq = RefreshSubscriptionsRequest() 400 | rq.subscriptions = subscriptions 401 | return self.square.refreshSubscriptions(rq) 402 | 403 | @loggedIn 404 | def removeSubscriptions(self, unsubscriptions=[]): 405 | rq = RemoveSubscriptionsRequest() 406 | rq.unsubscriptions = unsubscriptions 407 | return self.square.removeSubscriptions(rq) -------------------------------------------------------------------------------- /LINEPY/talk.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from akad.ttypes import Message 3 | from random import randint 4 | 5 | import json, ntpath 6 | 7 | def loggedIn(func): 8 | def checkLogin(*args, **kwargs): 9 | if args[0].isLogin: 10 | return func(*args, **kwargs) 11 | else: 12 | args[0].callback.other('You want to call the function, you must login to LINE') 13 | return checkLogin 14 | 15 | class Talk(object): 16 | isLogin = False 17 | _messageReq = {} 18 | _unsendMessageReq = 0 19 | 20 | def __init__(self): 21 | self.isLogin = True 22 | 23 | """User""" 24 | 25 | @loggedIn 26 | def acquireEncryptedAccessToken(self, featureType=2): 27 | return self.talk.acquireEncryptedAccessToken(featureType) 28 | 29 | @loggedIn 30 | def getProfile(self): 31 | return self.talk.getProfile() 32 | 33 | @loggedIn 34 | def getSettings(self): 35 | return self.talk.getSettings() 36 | 37 | @loggedIn 38 | def getUserTicket(self): 39 | return self.talk.getUserTicket() 40 | 41 | @loggedIn 42 | def updateProfile(self, profileObject): 43 | return self.talk.updateProfile(0, profileObject) 44 | 45 | @loggedIn 46 | def updateSettings(self, settingObject): 47 | return self.talk.updateSettings(0, settingObject) 48 | 49 | @loggedIn 50 | def updateProfileAttribute(self, attrId, value): 51 | return self.talk.updateProfileAttribute(0, attrId, value) 52 | 53 | """Operation""" 54 | 55 | @loggedIn 56 | def fetchOperation(self, revision, count): 57 | return self.talk.fetchOperations(revision, count) 58 | 59 | @loggedIn 60 | def getLastOpRevision(self): 61 | return self.talk.getLastOpRevision() 62 | 63 | """Message""" 64 | 65 | @loggedIn 66 | def sendMessage(self, to, text, contentMetadata={}, contentType=0): 67 | msg = Message() 68 | msg.to, msg._from = to, self.profile.mid 69 | msg.text = text 70 | msg.contentType, msg.contentMetadata = contentType, contentMetadata 71 | if to not in self._messageReq: 72 | self._messageReq[to] = -1 73 | self._messageReq[to] += 1 74 | return self.talk.sendMessage(self._messageReq[to], msg) 75 | 76 | """ Usage: 77 | @to Integer 78 | @text String 79 | @dataMid List of user Mid 80 | """ 81 | 82 | @loggedIn 83 | def sendText(self, Tomid, text): 84 | msg = Message() 85 | msg.to = Tomid 86 | msg.text = text 87 | 88 | return self.talk.sendMessage(0, msg) 89 | 90 | @loggedIn 91 | def sendMessageWithMention(self, to, mid, firstmessage, lastmessage): 92 | try: 93 | arrData = "" 94 | text = "%s " %(str(firstmessage)) 95 | arr = [] 96 | mention = "@x " 97 | slen = str(len(text)) 98 | elen = str(len(text) + len(mention) - 1) 99 | arrData = {'S':slen, 'E':elen, 'M':mid} 100 | arr.append(arrData) 101 | text += mention + str(lastmessage) 102 | self.sendMessage(to,text, {'MENTION': str('{"MENTIONEES":' + json.dumps(arr) + '}')}, 0) 103 | except Exception as error: 104 | print(error) 105 | 106 | @loggedIn 107 | def sendSticker(self, to, packageId, stickerId): 108 | contentMetadata = { 109 | 'STKVER': '100', 110 | 'STKPKGID': packageId, 111 | 'STKID': stickerId 112 | } 113 | return self.sendMessage(to, '', contentMetadata, 7) 114 | 115 | @loggedIn 116 | def sendContact(self, to, mid): 117 | contentMetadata = {'mid': mid} 118 | return self.sendMessage(to, '', contentMetadata, 13) 119 | 120 | @loggedIn 121 | def sendGift(self, to, productId, productType): 122 | if productType not in ['theme','sticker']: 123 | raise Exception('Invalid productType value') 124 | contentMetadata = { 125 | 'MSGTPL': str(randint(0, 12)), 126 | 'PRDTYPE': productType.upper(), 127 | 'STKPKGID' if productType == 'sticker' else 'PRDID': productId 128 | } 129 | return self.sendMessage(to, '', contentMetadata, 9) 130 | 131 | @loggedIn 132 | def sendMessageAwaitCommit(self, to, text, contentMetadata={}, contentType=0): 133 | msg = Message() 134 | msg.to, msg._from = to, self.profile.mid 135 | msg.text = text 136 | msg.contentType, msg.contentMetadata = contentType, contentMetadata 137 | if to not in self._messageReq: 138 | self._messageReq[to] = -1 139 | self._messageReq[to] += 1 140 | return self.talk.sendMessageAwaitCommit(self._messageReq[to], msg) 141 | 142 | @loggedIn 143 | def unsendMessage(self, messageId): 144 | self._unsendMessageReq += 1 145 | return self.talk.unsendMessage(self._unsendMessageReq, messageId) 146 | 147 | @loggedIn 148 | def requestResendMessage(self, senderMid, messageId): 149 | return self.talk.requestResendMessage(0, senderMid, messageId) 150 | 151 | @loggedIn 152 | def respondResendMessage(self, receiverMid, originalMessageId, resendMessage, errorCode): 153 | return self.talk.respondResendMessage(0, receiverMid, originalMessageId, resendMessage, errorCode) 154 | 155 | @loggedIn 156 | def removeMessage(self, messageId): 157 | return self.talk.removeMessage(messageId) 158 | 159 | @loggedIn 160 | def removeAllMessages(self, lastMessageId): 161 | return self.talk.removeAllMessages(0, lastMessageId) 162 | 163 | @loggedIn 164 | def removeMessageFromMyHome(self, messageId): 165 | return self.talk.removeMessageFromMyHome(messageId) 166 | 167 | @loggedIn 168 | def destroyMessage(self, chatId, messageId): 169 | return self.talk.destroyMessage(0, chatId, messageId, sessionId) 170 | 171 | @loggedIn 172 | def sendChatChecked(self, consumer, messageId): 173 | return self.talk.sendChatChecked(0, consumer, messageId) 174 | 175 | @loggedIn 176 | def sendEvent(self, messageObject): 177 | return self.talk.sendEvent(0, messageObject) 178 | 179 | @loggedIn 180 | def getLastReadMessageIds(self, chatId): 181 | return self.talk.getLastReadMessageIds(0, chatId) 182 | 183 | @loggedIn 184 | def getPreviousMessagesV2WithReadCount(self, messageBoxId, endMessageId, messagesCount=50): 185 | return self.talk.getPreviousMessagesV2WithReadCount(messageBoxId, endMessageId, messagesCount) 186 | 187 | """Object""" 188 | 189 | @loggedIn 190 | def sendImage(self, to, path): 191 | objectId = self.sendMessage(to=to, text=None, contentType = 1).id 192 | return self.uploadObjTalk(path=path, type='image', returnAs='bool', objId=objectId) 193 | 194 | @loggedIn 195 | def sendImageWithURL(self, to, url): 196 | path = self.downloadFileURL(url, 'path') 197 | return self.sendImage(to, path) 198 | 199 | @loggedIn 200 | def sendGIF(self, to, path): 201 | return self.uploadObjTalk(path=path, type='gif', returnAs='bool', to=to) 202 | 203 | @loggedIn 204 | def sendGIFWithURL(self, to, url): 205 | path = self.downloadFileURL(url, 'path') 206 | return self.sendGIF(to, path) 207 | 208 | @loggedIn 209 | def sendVideo(self, to, path): 210 | objectId = self.sendMessage(to=to, text=None, contentMetadata={'VIDLEN': '60000','DURATION': '60000'}, contentType = 2).id 211 | return self.uploadObjTalk(path=path, type='video', returnAs='bool', objId=objectId) 212 | 213 | @loggedIn 214 | def sendVideoWithURL(self, to, url): 215 | path = self.downloadFileURL(url, 'path') 216 | return self.sendVideo(to, path) 217 | 218 | @loggedIn 219 | def sendAudio(self, to, path): 220 | objectId = self.sendMessage(to=to, text=None, contentType = 3).id 221 | return self.uploadObjTalk(path=path, type='audio', returnAs='bool', objId=objectId) 222 | 223 | @loggedIn 224 | def sendAudioWithURL(self, to, url): 225 | path = self.downloadFileURL(url, 'path') 226 | return self.sendAudio(to, path) 227 | 228 | @loggedIn 229 | def sendFile(self, to, path, file_name=''): 230 | if file_name == '': 231 | file_name = ntpath.basename(path) 232 | file_size = len(open(path, 'rb').read()) 233 | objectId = self.sendMessage(to=to, text=None, contentMetadata={'FILE_NAME': str(file_name),'FILE_SIZE': str(file_size)}, contentType = 14).id 234 | return self.uploadObjTalk(path=path, type='file', returnAs='bool', objId=objectId) 235 | 236 | @loggedIn 237 | def sendFileWithURL(self, to, url, fileName=''): 238 | path = self.downloadFileURL(url, 'path') 239 | return self.sendFile(to, path, fileName) 240 | 241 | """Contact""" 242 | 243 | @loggedIn 244 | def blockContact(self, mid): 245 | return self.talk.blockContact(0, mid) 246 | 247 | @loggedIn 248 | def unblockContact(self, mid): 249 | return self.talk.unblockContact(0, mid) 250 | 251 | @loggedIn 252 | def findAndAddContactByMetaTag(self, userid, reference): 253 | return self.talk.findAndAddContactByMetaTag(0, userid, reference) 254 | 255 | @loggedIn 256 | def findAndAddContactsByMid(self, mid): 257 | return self.talk.findAndAddContactsByMid(0, mid, 0, '') 258 | 259 | @loggedIn 260 | def findAndAddContactsByEmail(self, emails=[]): 261 | return self.talk.findAndAddContactsByEmail(0, emails) 262 | 263 | @loggedIn 264 | def findAndAddContactsByUserid(self, userid): 265 | return self.talk.findAndAddContactsByUserid(0, userid) 266 | 267 | @loggedIn 268 | def findContactsByUserid(self, userid): 269 | return self.talk.findContactByUserid(userid) 270 | 271 | @loggedIn 272 | def findContactByTicket(self, ticketId): 273 | return self.talk.findContactByUserTicket(ticketId) 274 | 275 | @loggedIn 276 | def getAllContactIds(self): 277 | return self.talk.getAllContactIds() 278 | 279 | @loggedIn 280 | def getBlockedContactIds(self): 281 | return self.talk.getBlockedContactIds() 282 | 283 | @loggedIn 284 | def getContact(self, mid): 285 | return self.talk.getContact(mid) 286 | 287 | @loggedIn 288 | def getContacts(self, midlist): 289 | return self.talk.getContacts(midlist) 290 | 291 | @loggedIn 292 | def getFavoriteMids(self): 293 | return self.talk.getFavoriteMids() 294 | 295 | @loggedIn 296 | def getHiddenContactMids(self): 297 | return self.talk.getHiddenContactMids() 298 | 299 | @loggedIn 300 | def tryFriendRequest(self, midOrEMid, friendRequestParams, method=1): 301 | return self.talk.tryFriendRequest(midOrEMid, method, friendRequestParams) 302 | 303 | @loggedIn 304 | def makeUserAddMyselfAsContact(self, contactOwnerMid): 305 | return self.talk.makeUserAddMyselfAsContact(contactOwnerMid) 306 | 307 | @loggedIn 308 | def getContactWithFriendRequestStatus(self, id): 309 | return self.talk.getContactWithFriendRequestStatus(id) 310 | 311 | @loggedIn 312 | def reissueUserTicket(self, expirationTime=100, maxUseCount=100): 313 | return self.talk.reissueUserTicket(expirationTime, maxUseCount) 314 | 315 | @loggedIn 316 | def cloneContactProfile(self, mid): 317 | contact = self.getContact(mid) 318 | profile = self.profile 319 | profile.displayName = contact.displayName 320 | profile.statusMessage = contact.statusMessage 321 | profile.pictureStatus = contact.pictureStatus 322 | if self.getProfileCoverId(mid) is not None: 323 | self.updateProfileCoverById(self.getProfileCoverId(mid)) 324 | self.updateProfileAttribute(8, profile.pictureStatus) 325 | return self.updateProfile(profile) 326 | 327 | """Group""" 328 | 329 | @loggedIn 330 | def getChatRoomAnnouncementsBulk(self, chatRoomMids): 331 | return self.talk.getChatRoomAnnouncementsBulk(chatRoomMids) 332 | 333 | @loggedIn 334 | def getChatRoomAnnouncements(self, chatRoomMid): 335 | return self.talk.getChatRoomAnnouncements(chatRoomMid) 336 | 337 | @loggedIn 338 | def createChatRoomAnnouncement(self, chatRoomMid, type, contents): 339 | return self.talk.createChatRoomAnnouncement(0, chatRoomMid, type, contents) 340 | 341 | @loggedIn 342 | def removeChatRoomAnnouncement(self, chatRoomMid, announcementSeq): 343 | return self.talk.removeChatRoomAnnouncement(0, chatRoomMid, announcementSeq) 344 | 345 | @loggedIn 346 | def getGroupWithoutMembers(self, groupId): 347 | return self.talk.getGroupWithoutMembers(groupId) 348 | 349 | @loggedIn 350 | def findGroupByTicket(self, ticketId): 351 | return self.talk.findGroupByTicket(ticketId) 352 | 353 | @loggedIn 354 | def acceptGroupInvitation(self, groupId): 355 | return self.talk.acceptGroupInvitation(0, groupId) 356 | 357 | @loggedIn 358 | def acceptGroupInvitationByTicket(self, groupId, ticketId): 359 | return self.talk.acceptGroupInvitationByTicket(0, groupId, ticketId) 360 | 361 | @loggedIn 362 | def cancelGroupInvitation(self, groupId, contactIds): 363 | return self.talk.cancelGroupInvitation(0, groupId, contactIds) 364 | 365 | @loggedIn 366 | def createGroup(self, name, midlist): 367 | return self.talk.createGroup(0, name, midlist) 368 | 369 | @loggedIn 370 | def getGroup(self, groupId): 371 | return self.talk.getGroup(groupId) 372 | 373 | @loggedIn 374 | def getGroups(self, groupIds): 375 | return self.talk.getGroups(groupIds) 376 | 377 | @loggedIn 378 | def getGroupsV2(self, groupIds): 379 | return self.talk.getGroupsV2(groupIds) 380 | 381 | @loggedIn 382 | def getCompactGroup(self, groupId): 383 | return self.talk.getCompactGroup(groupId) 384 | 385 | @loggedIn 386 | def getCompactRoom(self, roomId): 387 | return self.talk.getCompactRoom(roomId) 388 | 389 | @loggedIn 390 | def getGroupIdsByName(self, groupName): 391 | gIds = [] 392 | for gId in self.getGroupIdsJoined(): 393 | g = self.getCompactGroup(gId) 394 | if groupName in g.name: 395 | gIds.append(gId) 396 | return gIds 397 | 398 | @loggedIn 399 | def getGroupIdsInvited(self): 400 | return self.talk.getGroupIdsInvited() 401 | 402 | @loggedIn 403 | def getGroupIdsJoined(self): 404 | return self.talk.getGroupIdsJoined() 405 | 406 | @loggedIn 407 | def updateGroupPreferenceAttribute(self, groupMid, updatedAttrs): 408 | return self.talk.updateGroupPreferenceAttribute(0, groupMid, updatedAttrs) 409 | 410 | @loggedIn 411 | def inviteIntoGroup(self, groupId, midlist): 412 | return self.talk.inviteIntoGroup(0, groupId, midlist) 413 | 414 | @loggedIn 415 | def kickoutFromGroup(self, groupId, midlist): 416 | return self.talk.kickoutFromGroup(0, groupId, midlist) 417 | 418 | @loggedIn 419 | def leaveGroup(self, groupId): 420 | return self.talk.leaveGroup(0, groupId) 421 | 422 | @loggedIn 423 | def rejectGroupInvitation(self, groupId): 424 | return self.talk.rejectGroupInvitation(0, groupId) 425 | 426 | @loggedIn 427 | def reissueGroupTicket(self, groupId): 428 | return self.talk.reissueGroupTicket(groupId) 429 | 430 | @loggedIn 431 | def updateGroup(self, groupObject): 432 | return self.talk.updateGroup(0, groupObject) 433 | 434 | """Room""" 435 | 436 | @loggedIn 437 | def createRoom(self, midlist): 438 | return self.talk.createRoom(0, midlist) 439 | 440 | @loggedIn 441 | def getRoom(self, roomId): 442 | return self.talk.getRoom(roomId) 443 | 444 | @loggedIn 445 | def inviteIntoRoom(self, roomId, midlist): 446 | return self.talk.inviteIntoRoom(0, roomId, midlist) 447 | 448 | @loggedIn 449 | def leaveRoom(self, roomId): 450 | return self.talk.leaveRoom(0, roomId) 451 | 452 | """Call""" 453 | 454 | @loggedIn 455 | def acquireCallTalkRoute(self, to): 456 | return self.talk.acquireCallRoute(to) 457 | 458 | """Report""" 459 | 460 | @loggedIn 461 | def reportSpam(self, chatMid, memberMids=[], spammerReasons=[], senderMids=[], spamMessageIds=[], spamMessages=[]): 462 | return self.talk.reportSpam(chatMid, memberMids, spammerReasons, senderMids, spamMessageIds, spamMessages) 463 | 464 | @loggedIn 465 | def reportSpammer(self, spammerMid, spammerReasons=[], spamMessageIds=[]): 466 | return self.talk.reportSpammer(spammerMid, spammerReasons, spamMessageIds) -------------------------------------------------------------------------------- /LINEPY/timeline.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from datetime import datetime 3 | from .channel import Channel 4 | 5 | import json, time, base64 6 | 7 | def loggedIn(func): 8 | def checkLogin(*args, **kwargs): 9 | if args[0].isLogin: 10 | return func(*args, **kwargs) 11 | else: 12 | args[0].callback.other('You want to call the function, you must login to LINE') 13 | return checkLogin 14 | 15 | class Timeline(Channel): 16 | 17 | def __init__(self): 18 | Channel.__init__(self, self.channel, self.server.CHANNEL_ID['LINE_TIMELINE'], False) 19 | self.tl = self.getChannelResult() 20 | self.__loginTimeline() 21 | 22 | def __loginTimeline(self): 23 | self.server.setTimelineHeadersWithDict({ 24 | 'Content-Type': 'application/json', 25 | 'User-Agent': self.server.USER_AGENT, 26 | 'X-Line-Mid': self.profile.mid, 27 | 'X-Line-Carrier': self.server.CARRIER, 28 | 'X-Line-Application': self.server.APP_NAME, 29 | 'X-Line-ChannelToken': self.tl.channelAccessToken 30 | }) 31 | self.profileDetail = self.getProfileDetail() 32 | 33 | """Timeline""" 34 | 35 | @loggedIn 36 | def getFeed(self, postLimit=10, commentLimit=1, likeLimit=1, order='TIME'): 37 | params = {'postLimit': postLimit, 'commentLimit': commentLimit, 'likeLimit': likeLimit, 'order': order} 38 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/feed/list.json', params) 39 | r = self.server.getContent(url, headers=self.server.timelineHeaders) 40 | return r.json() 41 | 42 | @loggedIn 43 | def getHomeProfile(self, mid=None, postLimit=10, commentLimit=1, likeLimit=1): 44 | if mid is None: 45 | mid = self.profile.mid 46 | params = {'homeId': mid, 'postLimit': postLimit, 'commentLimit': commentLimit, 'likeLimit': likeLimit, 'sourceType': 'LINE_PROFILE_COVER'} 47 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/post/list.json', params) 48 | r = self.server.getContent(url, headers=self.server.timelineHeaders) 49 | return r.json() 50 | 51 | @loggedIn 52 | def getProfileDetail(self, mid=None): 53 | if mid is None: 54 | mid = self.profile.mid 55 | params = {'userMid': mid} 56 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v1/userpopup/getDetail.json', params) 57 | r = self.server.getContent(url, headers=self.server.timelineHeaders) 58 | return r.json() 59 | 60 | @loggedIn 61 | def updateProfileCoverById(self, objId): 62 | params = {'coverImageId': objId} 63 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/home/updateCover.json', params) 64 | r = self.server.getContent(url, headers=self.server.timelineHeaders) 65 | return r.json() 66 | 67 | @loggedIn 68 | def getProfileCoverId(self, mid=None): 69 | if mid is None: 70 | mid = self.profile.mid 71 | home = self.getProfileDetail(mid) 72 | return home['result']['objectId'] 73 | 74 | @loggedIn 75 | def getProfileCoverURL(self, mid=None): 76 | if mid is None: 77 | mid = self.profile.mid 78 | home = self.getProfileDetail(mid) 79 | params = {'userid': mid, 'oid': home['result']['objectId']} 80 | return self.server.urlEncode(self.server.LINE_OBS_DOMAIN, '/myhome/c/download.nhn', params) 81 | 82 | """Post""" 83 | 84 | @loggedIn 85 | def createPost(self, text, holdingTime=None): 86 | params = {'homeId': self.profile.mid, 'sourceType': 'TIMELINE'} 87 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/post/create.json', params) 88 | payload = {'postInfo': {'readPermission': {'type': 'ALL'}}, 'sourceType': 'TIMELINE', 'contents': {'text': text}} 89 | if holdingTime != None: 90 | payload["postInfo"]["holdingTime"] = holdingTime 91 | data = json.dumps(payload) 92 | r = self.server.postContent(url, data=data, headers=self.server.timelineHeaders) 93 | return r.json() 94 | 95 | @loggedIn 96 | def sendPostToTalk(self, mid, postId): 97 | if mid is None: 98 | mid = self.profile.mid 99 | params = {'receiveMid': mid, 'postId': postId} 100 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/post/sendPostToTalk.json', params) 101 | r = self.server.getContent(url, data=data, headers=self.server.timelineHeaders) 102 | return r.json() 103 | 104 | @loggedIn 105 | def createComment(self, mid, postId, text): 106 | if mid is None: 107 | mid = self.profile.mid 108 | params = {'homeId': mid, 'sourceType': 'TIMELINE'} 109 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/comment/create.json', params) 110 | data = {'commentText': text, 'activityExternalId': postId, 'actorId': mid} 111 | r = self.server.postContent(url, data=data, headers=self.server.timelineHeaders) 112 | return r.json() 113 | 114 | @loggedIn 115 | def deleteComment(self, mid, postId, commentId): 116 | if mid is None: 117 | mid = self.profile.mid 118 | params = {'homeId': mid, 'sourceType': 'TIMELINE'} 119 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/comment/delete.json', params) 120 | data = {'commentId': commentId, 'activityExternalId': postId, 'actorId': mid} 121 | r = self.server.postContent(url, data=data, headers=self.server.timelineHeaders) 122 | return r.json() 123 | 124 | @loggedIn 125 | def likePost(self, mid, postId, likeType=1001): 126 | if mid is None: 127 | mid = self.profile.mid 128 | if likeType not in [1001,1002,1003,1004,1005,1006]: 129 | raise Exception('Invalid parameter likeType') 130 | params = {'homeId': mid, 'sourceType': 'TIMELINE'} 131 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/like/create.json', params) 132 | data = {'likeType': likeType, 'activityExternalId': postId, 'actorId': mid} 133 | r = self.server.postContent(url, data=data, headers=self.server.timelineHeaders) 134 | return r.json() 135 | 136 | @loggedIn 137 | def unlikePost(self, mid, postId): 138 | if mid is None: 139 | mid = self.profile.mid 140 | params = {'homeId': mid, 'sourceType': 'TIMELINE'} 141 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/like/cancel.json', params) 142 | data = {'activityExternalId': postId, 'actorId': mid} 143 | r = self.server.postContent(url, data=data, headers=self.server.timelineHeaders) 144 | return r.json() 145 | 146 | """Group Post""" 147 | 148 | @loggedIn 149 | def createGroupPost(self, mid, text): 150 | payload = {'postInfo': {'readPermission': {'homeId': mid}}, 'sourceType': 'TIMELINE', 'contents': {'text': text}} 151 | data = json.dumps(payload) 152 | r = self.server.postContent(self.server.LINE_TIMELINE_API + '/v39/post/create.json', data=data, headers=self.server.timelineHeaders) 153 | return r.json() 154 | 155 | @loggedIn 156 | def createGroupAlbum(self, mid, name): 157 | data = json.dumps({'title': name, 'type': 'image'}) 158 | params = {'homeId': mid,'count': '1','auto': '0'} 159 | url = self.server.urlEncode(self.server.LINE_TIMELINE_MH, '/album/v3/album.json', params) 160 | r = self.server.postContent(url, data=data, headers=self.server.timelineHeaders) 161 | if r.status_code != 201: 162 | raise Exception('Create a new album failure.') 163 | return True 164 | 165 | @loggedIn 166 | def deleteGroupAlbum(self, mid, albumId): 167 | params = {'homeId': mid} 168 | url = self.server.urlEncode(self.server.LINE_TIMELINE_MH, '/album/v3/album/%s' % albumId, params) 169 | r = self.server.deleteContent(url, headers=self.server.timelineHeaders) 170 | if r.status_code != 201: 171 | raise Exception('Delete album failure.') 172 | return True 173 | 174 | @loggedIn 175 | def getGroupPost(self, mid, postLimit=10, commentLimit=1, likeLimit=1): 176 | params = {'homeId': mid, 'commentLimit': commentLimit, 'likeLimit': likeLimit, 'sourceType': 'TALKROOM'} 177 | url = self.server.urlEncode(self.server.LINE_TIMELINE_API, '/v39/post/list.json', params) 178 | r = self.server.getContent(url, headers=self.server.timelineHeaders) 179 | return r.json() 180 | 181 | """Group Album""" 182 | 183 | @loggedIn 184 | def getGroupAlbum(self, mid): 185 | params = {'homeId': mid, 'type': 'g', 'sourceType': 'TALKROOM'} 186 | url = self.server.urlEncode(self.server.LINE_TIMELINE_MH, '/album/v3/albums.json', params) 187 | r = self.server.getContent(url, headers=self.server.timelineHeaders) 188 | return r.json() 189 | 190 | @loggedIn 191 | def changeGroupAlbumName(self, mid, albumId, name): 192 | data = json.dumps({'title': name}) 193 | params = {'homeId': mid} 194 | url = self.server.urlEncode(self.server.LINE_TIMELINE_MH, '/album/v3/album/%s' % albumId, params) 195 | r = self.server.putContent(url, data=data, headers=self.server.timelineHeaders) 196 | if r.status_code != 201: 197 | raise Exception('Change album name failure.') 198 | return True 199 | 200 | @loggedIn 201 | def addImageToAlbum(self, mid, albumId, path): 202 | file = open(path, 'rb').read() 203 | params = { 204 | 'oid': int(time.time()), 205 | 'quality': '90', 206 | 'range': len(file), 207 | 'type': 'image' 208 | } 209 | hr = self.server.additionalHeaders(self.server.timelineHeaders, { 210 | 'Content-Type': 'image/jpeg', 211 | 'X-Line-Mid': mid, 212 | 'X-Line-Album': albumId, 213 | 'x-obs-params': self.genOBSParams(params,'b64') 214 | }) 215 | r = self.server.getContent(self.server.LINE_OBS_DOMAIN + '/album/a/upload.nhn', data=file, headers=hr) 216 | if r.status_code != 201: 217 | raise Exception('Add image to album failure.') 218 | return r.json() 219 | 220 | @loggedIn 221 | def getImageGroupAlbum(self, mid, albumId, objId, returnAs='path', saveAs=''): 222 | if saveAs == '': 223 | saveAs = self.genTempFile('path') 224 | if returnAs not in ['path','bool','bin']: 225 | raise Exception('Invalid returnAs value') 226 | hr = self.server.additionalHeaders(self.server.timelineHeaders, { 227 | 'Content-Type': 'image/jpeg', 228 | 'X-Line-Mid': mid, 229 | 'X-Line-Album': albumId 230 | }) 231 | params = {'ver': '1.0', 'oid': objId} 232 | url = self.server.urlEncode(self.server.LINE_OBS_DOMAIN, '/album/a/download.nhn', params) 233 | r = self.server.getContent(url, headers=hr) 234 | if r.status_code == 200: 235 | self.saveFile(saveAs, r.raw) 236 | if returnAs == 'path': 237 | return saveAs 238 | elif returnAs == 'bool': 239 | return True 240 | elif returnAs == 'bin': 241 | return r.raw 242 | else: 243 | raise Exception('Download image album failure.') 244 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Protect Self ProtectPy3 2 | Fungsinya? 3 | Kelebihan : 4 | 1. Protect Group Line Pastinya 5 | 2. Command Bisa Dipakai oleh Orang Admin/Self 6 | 3. Bot Tidak Saling Kick Ketika Ada Yang Terkick 7 | 4. Jika Ingin lebih dari 1 bot bisa ditambahkan sendiri 8 | 9 | - Kelemahan: 10 | - BOT Tidak Aktif Ketika Bot Induk Tidak ada di Dalam Group 11 | 12 | Cara Instal di termux: 13 | - pkg install python3 14 | - pkg install pip3 15 | - pkg install git 16 | - git clone https://github.com/wongmu/protectpy3 17 | - pip3 install rsa 18 | - pip3 install thrift==0.11.0 19 | - pip3 install humanfriendly 20 | - pip3 install requests 21 | - cd protectpy3 22 | - python3 protectpy3.py 23 | 24 | 25 | Cara Install Self ProtectPy3 di c9: 26 | - apt update 27 | - apt install git 28 | - apt install python3 29 | - apt install pip3==python3 30 | - pip3 install rsa 31 | - pip3 install thrift 32 | - pip3 install requests 33 | - pip3 install humanfriendly 34 | - git clone https://github.com/wongmu/protectpy3 35 | - cd protectpy3 36 | - python3 protectpy3.py 37 | 38 | 39 | Credit By Eva. 40 | - Add My ID LINE : https://line.me/ti/p/~mamanggd 41 | 42 | 43 | Thx To : 44 | - LINE-TCR TEAM 45 | - HELLO-WORLD 46 | - Nadya Sutjiadi 47 | - iiipuuul 48 | -------------------------------------------------------------------------------- /akad/BotService.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.11.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException 10 | from thrift.protocol.TProtocol import TProtocolException 11 | from thrift.TRecursive import fix_spec 12 | 13 | import sys 14 | import logging 15 | from .ttypes import * 16 | from thrift.Thrift import TProcessor 17 | from thrift.transport import TTransport 18 | all_structs = [] 19 | 20 | 21 | class Iface(object): 22 | def notifyLeaveGroup(self, groupMid): 23 | """ 24 | Parameters: 25 | - groupMid 26 | """ 27 | pass 28 | 29 | def notifyLeaveRoom(self, roomMid): 30 | """ 31 | Parameters: 32 | - roomMid 33 | """ 34 | pass 35 | 36 | def getBotUseInfo(self, botMid): 37 | """ 38 | Parameters: 39 | - botMid 40 | """ 41 | pass 42 | 43 | def sendChatCheckedByWatermark(self, seq, mid, watermark, sessionId): 44 | """ 45 | Parameters: 46 | - seq 47 | - mid 48 | - watermark 49 | - sessionId 50 | """ 51 | pass 52 | 53 | 54 | class Client(Iface): 55 | def __init__(self, iprot, oprot=None): 56 | self._iprot = self._oprot = iprot 57 | if oprot is not None: 58 | self._oprot = oprot 59 | self._seqid = 0 60 | 61 | def notifyLeaveGroup(self, groupMid): 62 | """ 63 | Parameters: 64 | - groupMid 65 | """ 66 | self.send_notifyLeaveGroup(groupMid) 67 | self.recv_notifyLeaveGroup() 68 | 69 | def send_notifyLeaveGroup(self, groupMid): 70 | self._oprot.writeMessageBegin('notifyLeaveGroup', TMessageType.CALL, self._seqid) 71 | args = notifyLeaveGroup_args() 72 | args.groupMid = groupMid 73 | args.write(self._oprot) 74 | self._oprot.writeMessageEnd() 75 | self._oprot.trans.flush() 76 | 77 | def recv_notifyLeaveGroup(self): 78 | iprot = self._iprot 79 | (fname, mtype, rseqid) = iprot.readMessageBegin() 80 | if mtype == TMessageType.EXCEPTION: 81 | x = TApplicationException() 82 | x.read(iprot) 83 | iprot.readMessageEnd() 84 | raise x 85 | result = notifyLeaveGroup_result() 86 | result.read(iprot) 87 | iprot.readMessageEnd() 88 | if result.e is not None: 89 | raise result.e 90 | return 91 | 92 | def notifyLeaveRoom(self, roomMid): 93 | """ 94 | Parameters: 95 | - roomMid 96 | """ 97 | self.send_notifyLeaveRoom(roomMid) 98 | self.recv_notifyLeaveRoom() 99 | 100 | def send_notifyLeaveRoom(self, roomMid): 101 | self._oprot.writeMessageBegin('notifyLeaveRoom', TMessageType.CALL, self._seqid) 102 | args = notifyLeaveRoom_args() 103 | args.roomMid = roomMid 104 | args.write(self._oprot) 105 | self._oprot.writeMessageEnd() 106 | self._oprot.trans.flush() 107 | 108 | def recv_notifyLeaveRoom(self): 109 | iprot = self._iprot 110 | (fname, mtype, rseqid) = iprot.readMessageBegin() 111 | if mtype == TMessageType.EXCEPTION: 112 | x = TApplicationException() 113 | x.read(iprot) 114 | iprot.readMessageEnd() 115 | raise x 116 | result = notifyLeaveRoom_result() 117 | result.read(iprot) 118 | iprot.readMessageEnd() 119 | if result.e is not None: 120 | raise result.e 121 | return 122 | 123 | def getBotUseInfo(self, botMid): 124 | """ 125 | Parameters: 126 | - botMid 127 | """ 128 | self.send_getBotUseInfo(botMid) 129 | return self.recv_getBotUseInfo() 130 | 131 | def send_getBotUseInfo(self, botMid): 132 | self._oprot.writeMessageBegin('getBotUseInfo', TMessageType.CALL, self._seqid) 133 | args = getBotUseInfo_args() 134 | args.botMid = botMid 135 | args.write(self._oprot) 136 | self._oprot.writeMessageEnd() 137 | self._oprot.trans.flush() 138 | 139 | def recv_getBotUseInfo(self): 140 | iprot = self._iprot 141 | (fname, mtype, rseqid) = iprot.readMessageBegin() 142 | if mtype == TMessageType.EXCEPTION: 143 | x = TApplicationException() 144 | x.read(iprot) 145 | iprot.readMessageEnd() 146 | raise x 147 | result = getBotUseInfo_result() 148 | result.read(iprot) 149 | iprot.readMessageEnd() 150 | if result.success is not None: 151 | return result.success 152 | if result.e is not None: 153 | raise result.e 154 | raise TApplicationException(TApplicationException.MISSING_RESULT, "getBotUseInfo failed: unknown result") 155 | 156 | def sendChatCheckedByWatermark(self, seq, mid, watermark, sessionId): 157 | """ 158 | Parameters: 159 | - seq 160 | - mid 161 | - watermark 162 | - sessionId 163 | """ 164 | self.send_sendChatCheckedByWatermark(seq, mid, watermark, sessionId) 165 | self.recv_sendChatCheckedByWatermark() 166 | 167 | def send_sendChatCheckedByWatermark(self, seq, mid, watermark, sessionId): 168 | self._oprot.writeMessageBegin('sendChatCheckedByWatermark', TMessageType.CALL, self._seqid) 169 | args = sendChatCheckedByWatermark_args() 170 | args.seq = seq 171 | args.mid = mid 172 | args.watermark = watermark 173 | args.sessionId = sessionId 174 | args.write(self._oprot) 175 | self._oprot.writeMessageEnd() 176 | self._oprot.trans.flush() 177 | 178 | def recv_sendChatCheckedByWatermark(self): 179 | iprot = self._iprot 180 | (fname, mtype, rseqid) = iprot.readMessageBegin() 181 | if mtype == TMessageType.EXCEPTION: 182 | x = TApplicationException() 183 | x.read(iprot) 184 | iprot.readMessageEnd() 185 | raise x 186 | result = sendChatCheckedByWatermark_result() 187 | result.read(iprot) 188 | iprot.readMessageEnd() 189 | if result.e is not None: 190 | raise result.e 191 | return 192 | 193 | 194 | class Processor(Iface, TProcessor): 195 | def __init__(self, handler): 196 | self._handler = handler 197 | self._processMap = {} 198 | self._processMap["notifyLeaveGroup"] = Processor.process_notifyLeaveGroup 199 | self._processMap["notifyLeaveRoom"] = Processor.process_notifyLeaveRoom 200 | self._processMap["getBotUseInfo"] = Processor.process_getBotUseInfo 201 | self._processMap["sendChatCheckedByWatermark"] = Processor.process_sendChatCheckedByWatermark 202 | 203 | def process(self, iprot, oprot): 204 | (name, type, seqid) = iprot.readMessageBegin() 205 | if name not in self._processMap: 206 | iprot.skip(TType.STRUCT) 207 | iprot.readMessageEnd() 208 | x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) 209 | oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) 210 | x.write(oprot) 211 | oprot.writeMessageEnd() 212 | oprot.trans.flush() 213 | return 214 | else: 215 | self._processMap[name](self, seqid, iprot, oprot) 216 | return True 217 | 218 | def process_notifyLeaveGroup(self, seqid, iprot, oprot): 219 | args = notifyLeaveGroup_args() 220 | args.read(iprot) 221 | iprot.readMessageEnd() 222 | result = notifyLeaveGroup_result() 223 | try: 224 | self._handler.notifyLeaveGroup(args.groupMid) 225 | msg_type = TMessageType.REPLY 226 | except TTransport.TTransportException: 227 | raise 228 | except TalkException as e: 229 | msg_type = TMessageType.REPLY 230 | result.e = e 231 | except TApplicationException as ex: 232 | logging.exception('TApplication exception in handler') 233 | msg_type = TMessageType.EXCEPTION 234 | result = ex 235 | except Exception: 236 | logging.exception('Unexpected exception in handler') 237 | msg_type = TMessageType.EXCEPTION 238 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 239 | oprot.writeMessageBegin("notifyLeaveGroup", msg_type, seqid) 240 | result.write(oprot) 241 | oprot.writeMessageEnd() 242 | oprot.trans.flush() 243 | 244 | def process_notifyLeaveRoom(self, seqid, iprot, oprot): 245 | args = notifyLeaveRoom_args() 246 | args.read(iprot) 247 | iprot.readMessageEnd() 248 | result = notifyLeaveRoom_result() 249 | try: 250 | self._handler.notifyLeaveRoom(args.roomMid) 251 | msg_type = TMessageType.REPLY 252 | except TTransport.TTransportException: 253 | raise 254 | except TalkException as e: 255 | msg_type = TMessageType.REPLY 256 | result.e = e 257 | except TApplicationException as ex: 258 | logging.exception('TApplication exception in handler') 259 | msg_type = TMessageType.EXCEPTION 260 | result = ex 261 | except Exception: 262 | logging.exception('Unexpected exception in handler') 263 | msg_type = TMessageType.EXCEPTION 264 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 265 | oprot.writeMessageBegin("notifyLeaveRoom", msg_type, seqid) 266 | result.write(oprot) 267 | oprot.writeMessageEnd() 268 | oprot.trans.flush() 269 | 270 | def process_getBotUseInfo(self, seqid, iprot, oprot): 271 | args = getBotUseInfo_args() 272 | args.read(iprot) 273 | iprot.readMessageEnd() 274 | result = getBotUseInfo_result() 275 | try: 276 | result.success = self._handler.getBotUseInfo(args.botMid) 277 | msg_type = TMessageType.REPLY 278 | except TTransport.TTransportException: 279 | raise 280 | except TalkException as e: 281 | msg_type = TMessageType.REPLY 282 | result.e = e 283 | except TApplicationException as ex: 284 | logging.exception('TApplication exception in handler') 285 | msg_type = TMessageType.EXCEPTION 286 | result = ex 287 | except Exception: 288 | logging.exception('Unexpected exception in handler') 289 | msg_type = TMessageType.EXCEPTION 290 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 291 | oprot.writeMessageBegin("getBotUseInfo", msg_type, seqid) 292 | result.write(oprot) 293 | oprot.writeMessageEnd() 294 | oprot.trans.flush() 295 | 296 | def process_sendChatCheckedByWatermark(self, seqid, iprot, oprot): 297 | args = sendChatCheckedByWatermark_args() 298 | args.read(iprot) 299 | iprot.readMessageEnd() 300 | result = sendChatCheckedByWatermark_result() 301 | try: 302 | self._handler.sendChatCheckedByWatermark(args.seq, args.mid, args.watermark, args.sessionId) 303 | msg_type = TMessageType.REPLY 304 | except TTransport.TTransportException: 305 | raise 306 | except TalkException as e: 307 | msg_type = TMessageType.REPLY 308 | result.e = e 309 | except TApplicationException as ex: 310 | logging.exception('TApplication exception in handler') 311 | msg_type = TMessageType.EXCEPTION 312 | result = ex 313 | except Exception: 314 | logging.exception('Unexpected exception in handler') 315 | msg_type = TMessageType.EXCEPTION 316 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 317 | oprot.writeMessageBegin("sendChatCheckedByWatermark", msg_type, seqid) 318 | result.write(oprot) 319 | oprot.writeMessageEnd() 320 | oprot.trans.flush() 321 | 322 | # HELPER FUNCTIONS AND STRUCTURES 323 | 324 | 325 | class notifyLeaveGroup_args(object): 326 | """ 327 | Attributes: 328 | - groupMid 329 | """ 330 | 331 | 332 | def __init__(self, groupMid=None,): 333 | self.groupMid = groupMid 334 | 335 | def read(self, iprot): 336 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 337 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 338 | return 339 | iprot.readStructBegin() 340 | while True: 341 | (fname, ftype, fid) = iprot.readFieldBegin() 342 | if ftype == TType.STOP: 343 | break 344 | if fid == 1: 345 | if ftype == TType.STRING: 346 | self.groupMid = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 347 | else: 348 | iprot.skip(ftype) 349 | else: 350 | iprot.skip(ftype) 351 | iprot.readFieldEnd() 352 | iprot.readStructEnd() 353 | 354 | def write(self, oprot): 355 | if oprot._fast_encode is not None and self.thrift_spec is not None: 356 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 357 | return 358 | oprot.writeStructBegin('notifyLeaveGroup_args') 359 | if self.groupMid is not None: 360 | oprot.writeFieldBegin('groupMid', TType.STRING, 1) 361 | oprot.writeString(self.groupMid.encode('utf-8') if sys.version_info[0] == 2 else self.groupMid) 362 | oprot.writeFieldEnd() 363 | oprot.writeFieldStop() 364 | oprot.writeStructEnd() 365 | 366 | def validate(self): 367 | return 368 | 369 | def __repr__(self): 370 | L = ['%s=%r' % (key, value) 371 | for key, value in self.__dict__.items()] 372 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 373 | 374 | def __eq__(self, other): 375 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 376 | 377 | def __ne__(self, other): 378 | return not (self == other) 379 | all_structs.append(notifyLeaveGroup_args) 380 | notifyLeaveGroup_args.thrift_spec = ( 381 | None, # 0 382 | (1, TType.STRING, 'groupMid', 'UTF8', None, ), # 1 383 | ) 384 | 385 | 386 | class notifyLeaveGroup_result(object): 387 | """ 388 | Attributes: 389 | - e 390 | """ 391 | 392 | 393 | def __init__(self, e=None,): 394 | self.e = e 395 | 396 | def read(self, iprot): 397 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 398 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 399 | return 400 | iprot.readStructBegin() 401 | while True: 402 | (fname, ftype, fid) = iprot.readFieldBegin() 403 | if ftype == TType.STOP: 404 | break 405 | if fid == 1: 406 | if ftype == TType.STRUCT: 407 | self.e = TalkException() 408 | self.e.read(iprot) 409 | else: 410 | iprot.skip(ftype) 411 | else: 412 | iprot.skip(ftype) 413 | iprot.readFieldEnd() 414 | iprot.readStructEnd() 415 | 416 | def write(self, oprot): 417 | if oprot._fast_encode is not None and self.thrift_spec is not None: 418 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 419 | return 420 | oprot.writeStructBegin('notifyLeaveGroup_result') 421 | if self.e is not None: 422 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 423 | self.e.write(oprot) 424 | oprot.writeFieldEnd() 425 | oprot.writeFieldStop() 426 | oprot.writeStructEnd() 427 | 428 | def validate(self): 429 | return 430 | 431 | def __repr__(self): 432 | L = ['%s=%r' % (key, value) 433 | for key, value in self.__dict__.items()] 434 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 435 | 436 | def __eq__(self, other): 437 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 438 | 439 | def __ne__(self, other): 440 | return not (self == other) 441 | all_structs.append(notifyLeaveGroup_result) 442 | notifyLeaveGroup_result.thrift_spec = ( 443 | None, # 0 444 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 445 | ) 446 | 447 | 448 | class notifyLeaveRoom_args(object): 449 | """ 450 | Attributes: 451 | - roomMid 452 | """ 453 | 454 | 455 | def __init__(self, roomMid=None,): 456 | self.roomMid = roomMid 457 | 458 | def read(self, iprot): 459 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 460 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 461 | return 462 | iprot.readStructBegin() 463 | while True: 464 | (fname, ftype, fid) = iprot.readFieldBegin() 465 | if ftype == TType.STOP: 466 | break 467 | if fid == 1: 468 | if ftype == TType.STRING: 469 | self.roomMid = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 470 | else: 471 | iprot.skip(ftype) 472 | else: 473 | iprot.skip(ftype) 474 | iprot.readFieldEnd() 475 | iprot.readStructEnd() 476 | 477 | def write(self, oprot): 478 | if oprot._fast_encode is not None and self.thrift_spec is not None: 479 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 480 | return 481 | oprot.writeStructBegin('notifyLeaveRoom_args') 482 | if self.roomMid is not None: 483 | oprot.writeFieldBegin('roomMid', TType.STRING, 1) 484 | oprot.writeString(self.roomMid.encode('utf-8') if sys.version_info[0] == 2 else self.roomMid) 485 | oprot.writeFieldEnd() 486 | oprot.writeFieldStop() 487 | oprot.writeStructEnd() 488 | 489 | def validate(self): 490 | return 491 | 492 | def __repr__(self): 493 | L = ['%s=%r' % (key, value) 494 | for key, value in self.__dict__.items()] 495 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 496 | 497 | def __eq__(self, other): 498 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 499 | 500 | def __ne__(self, other): 501 | return not (self == other) 502 | all_structs.append(notifyLeaveRoom_args) 503 | notifyLeaveRoom_args.thrift_spec = ( 504 | None, # 0 505 | (1, TType.STRING, 'roomMid', 'UTF8', None, ), # 1 506 | ) 507 | 508 | 509 | class notifyLeaveRoom_result(object): 510 | """ 511 | Attributes: 512 | - e 513 | """ 514 | 515 | 516 | def __init__(self, e=None,): 517 | self.e = e 518 | 519 | def read(self, iprot): 520 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 521 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 522 | return 523 | iprot.readStructBegin() 524 | while True: 525 | (fname, ftype, fid) = iprot.readFieldBegin() 526 | if ftype == TType.STOP: 527 | break 528 | if fid == 1: 529 | if ftype == TType.STRUCT: 530 | self.e = TalkException() 531 | self.e.read(iprot) 532 | else: 533 | iprot.skip(ftype) 534 | else: 535 | iprot.skip(ftype) 536 | iprot.readFieldEnd() 537 | iprot.readStructEnd() 538 | 539 | def write(self, oprot): 540 | if oprot._fast_encode is not None and self.thrift_spec is not None: 541 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 542 | return 543 | oprot.writeStructBegin('notifyLeaveRoom_result') 544 | if self.e is not None: 545 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 546 | self.e.write(oprot) 547 | oprot.writeFieldEnd() 548 | oprot.writeFieldStop() 549 | oprot.writeStructEnd() 550 | 551 | def validate(self): 552 | return 553 | 554 | def __repr__(self): 555 | L = ['%s=%r' % (key, value) 556 | for key, value in self.__dict__.items()] 557 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 558 | 559 | def __eq__(self, other): 560 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 561 | 562 | def __ne__(self, other): 563 | return not (self == other) 564 | all_structs.append(notifyLeaveRoom_result) 565 | notifyLeaveRoom_result.thrift_spec = ( 566 | None, # 0 567 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 568 | ) 569 | 570 | 571 | class getBotUseInfo_args(object): 572 | """ 573 | Attributes: 574 | - botMid 575 | """ 576 | 577 | 578 | def __init__(self, botMid=None,): 579 | self.botMid = botMid 580 | 581 | def read(self, iprot): 582 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 583 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 584 | return 585 | iprot.readStructBegin() 586 | while True: 587 | (fname, ftype, fid) = iprot.readFieldBegin() 588 | if ftype == TType.STOP: 589 | break 590 | if fid == 2: 591 | if ftype == TType.STRING: 592 | self.botMid = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 593 | else: 594 | iprot.skip(ftype) 595 | else: 596 | iprot.skip(ftype) 597 | iprot.readFieldEnd() 598 | iprot.readStructEnd() 599 | 600 | def write(self, oprot): 601 | if oprot._fast_encode is not None and self.thrift_spec is not None: 602 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 603 | return 604 | oprot.writeStructBegin('getBotUseInfo_args') 605 | if self.botMid is not None: 606 | oprot.writeFieldBegin('botMid', TType.STRING, 2) 607 | oprot.writeString(self.botMid.encode('utf-8') if sys.version_info[0] == 2 else self.botMid) 608 | oprot.writeFieldEnd() 609 | oprot.writeFieldStop() 610 | oprot.writeStructEnd() 611 | 612 | def validate(self): 613 | return 614 | 615 | def __repr__(self): 616 | L = ['%s=%r' % (key, value) 617 | for key, value in self.__dict__.items()] 618 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 619 | 620 | def __eq__(self, other): 621 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 622 | 623 | def __ne__(self, other): 624 | return not (self == other) 625 | all_structs.append(getBotUseInfo_args) 626 | getBotUseInfo_args.thrift_spec = ( 627 | None, # 0 628 | None, # 1 629 | (2, TType.STRING, 'botMid', 'UTF8', None, ), # 2 630 | ) 631 | 632 | 633 | class getBotUseInfo_result(object): 634 | """ 635 | Attributes: 636 | - success 637 | - e 638 | """ 639 | 640 | 641 | def __init__(self, success=None, e=None,): 642 | self.success = success 643 | self.e = e 644 | 645 | def read(self, iprot): 646 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 647 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 648 | return 649 | iprot.readStructBegin() 650 | while True: 651 | (fname, ftype, fid) = iprot.readFieldBegin() 652 | if ftype == TType.STOP: 653 | break 654 | if fid == 0: 655 | if ftype == TType.STRUCT: 656 | self.success = BotUseInfo() 657 | self.success.read(iprot) 658 | else: 659 | iprot.skip(ftype) 660 | elif fid == 1: 661 | if ftype == TType.STRUCT: 662 | self.e = TalkException() 663 | self.e.read(iprot) 664 | else: 665 | iprot.skip(ftype) 666 | else: 667 | iprot.skip(ftype) 668 | iprot.readFieldEnd() 669 | iprot.readStructEnd() 670 | 671 | def write(self, oprot): 672 | if oprot._fast_encode is not None and self.thrift_spec is not None: 673 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 674 | return 675 | oprot.writeStructBegin('getBotUseInfo_result') 676 | if self.success is not None: 677 | oprot.writeFieldBegin('success', TType.STRUCT, 0) 678 | self.success.write(oprot) 679 | oprot.writeFieldEnd() 680 | if self.e is not None: 681 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 682 | self.e.write(oprot) 683 | oprot.writeFieldEnd() 684 | oprot.writeFieldStop() 685 | oprot.writeStructEnd() 686 | 687 | def validate(self): 688 | return 689 | 690 | def __repr__(self): 691 | L = ['%s=%r' % (key, value) 692 | for key, value in self.__dict__.items()] 693 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 694 | 695 | def __eq__(self, other): 696 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 697 | 698 | def __ne__(self, other): 699 | return not (self == other) 700 | all_structs.append(getBotUseInfo_result) 701 | getBotUseInfo_result.thrift_spec = ( 702 | (0, TType.STRUCT, 'success', [BotUseInfo, None], None, ), # 0 703 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 704 | ) 705 | 706 | 707 | class sendChatCheckedByWatermark_args(object): 708 | """ 709 | Attributes: 710 | - seq 711 | - mid 712 | - watermark 713 | - sessionId 714 | """ 715 | 716 | 717 | def __init__(self, seq=None, mid=None, watermark=None, sessionId=None,): 718 | self.seq = seq 719 | self.mid = mid 720 | self.watermark = watermark 721 | self.sessionId = sessionId 722 | 723 | def read(self, iprot): 724 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 725 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 726 | return 727 | iprot.readStructBegin() 728 | while True: 729 | (fname, ftype, fid) = iprot.readFieldBegin() 730 | if ftype == TType.STOP: 731 | break 732 | if fid == 1: 733 | if ftype == TType.I32: 734 | self.seq = iprot.readI32() 735 | else: 736 | iprot.skip(ftype) 737 | elif fid == 2: 738 | if ftype == TType.STRING: 739 | self.mid = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 740 | else: 741 | iprot.skip(ftype) 742 | elif fid == 3: 743 | if ftype == TType.I64: 744 | self.watermark = iprot.readI64() 745 | else: 746 | iprot.skip(ftype) 747 | elif fid == 4: 748 | if ftype == TType.BYTE: 749 | self.sessionId = iprot.readByte() 750 | else: 751 | iprot.skip(ftype) 752 | else: 753 | iprot.skip(ftype) 754 | iprot.readFieldEnd() 755 | iprot.readStructEnd() 756 | 757 | def write(self, oprot): 758 | if oprot._fast_encode is not None and self.thrift_spec is not None: 759 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 760 | return 761 | oprot.writeStructBegin('sendChatCheckedByWatermark_args') 762 | if self.seq is not None: 763 | oprot.writeFieldBegin('seq', TType.I32, 1) 764 | oprot.writeI32(self.seq) 765 | oprot.writeFieldEnd() 766 | if self.mid is not None: 767 | oprot.writeFieldBegin('mid', TType.STRING, 2) 768 | oprot.writeString(self.mid.encode('utf-8') if sys.version_info[0] == 2 else self.mid) 769 | oprot.writeFieldEnd() 770 | if self.watermark is not None: 771 | oprot.writeFieldBegin('watermark', TType.I64, 3) 772 | oprot.writeI64(self.watermark) 773 | oprot.writeFieldEnd() 774 | if self.sessionId is not None: 775 | oprot.writeFieldBegin('sessionId', TType.BYTE, 4) 776 | oprot.writeByte(self.sessionId) 777 | oprot.writeFieldEnd() 778 | oprot.writeFieldStop() 779 | oprot.writeStructEnd() 780 | 781 | def validate(self): 782 | return 783 | 784 | def __repr__(self): 785 | L = ['%s=%r' % (key, value) 786 | for key, value in self.__dict__.items()] 787 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 788 | 789 | def __eq__(self, other): 790 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 791 | 792 | def __ne__(self, other): 793 | return not (self == other) 794 | all_structs.append(sendChatCheckedByWatermark_args) 795 | sendChatCheckedByWatermark_args.thrift_spec = ( 796 | None, # 0 797 | (1, TType.I32, 'seq', None, None, ), # 1 798 | (2, TType.STRING, 'mid', 'UTF8', None, ), # 2 799 | (3, TType.I64, 'watermark', None, None, ), # 3 800 | (4, TType.BYTE, 'sessionId', None, None, ), # 4 801 | ) 802 | 803 | 804 | class sendChatCheckedByWatermark_result(object): 805 | """ 806 | Attributes: 807 | - e 808 | """ 809 | 810 | 811 | def __init__(self, e=None,): 812 | self.e = e 813 | 814 | def read(self, iprot): 815 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 816 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 817 | return 818 | iprot.readStructBegin() 819 | while True: 820 | (fname, ftype, fid) = iprot.readFieldBegin() 821 | if ftype == TType.STOP: 822 | break 823 | if fid == 1: 824 | if ftype == TType.STRUCT: 825 | self.e = TalkException() 826 | self.e.read(iprot) 827 | else: 828 | iprot.skip(ftype) 829 | else: 830 | iprot.skip(ftype) 831 | iprot.readFieldEnd() 832 | iprot.readStructEnd() 833 | 834 | def write(self, oprot): 835 | if oprot._fast_encode is not None and self.thrift_spec is not None: 836 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 837 | return 838 | oprot.writeStructBegin('sendChatCheckedByWatermark_result') 839 | if self.e is not None: 840 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 841 | self.e.write(oprot) 842 | oprot.writeFieldEnd() 843 | oprot.writeFieldStop() 844 | oprot.writeStructEnd() 845 | 846 | def validate(self): 847 | return 848 | 849 | def __repr__(self): 850 | L = ['%s=%r' % (key, value) 851 | for key, value in self.__dict__.items()] 852 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 853 | 854 | def __eq__(self, other): 855 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 856 | 857 | def __ne__(self, other): 858 | return not (self == other) 859 | all_structs.append(sendChatCheckedByWatermark_result) 860 | sendChatCheckedByWatermark_result.thrift_spec = ( 861 | None, # 0 862 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 863 | ) 864 | fix_spec(all_structs) 865 | del all_structs 866 | 867 | -------------------------------------------------------------------------------- /akad/MessageService.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.11.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException 10 | from thrift.protocol.TProtocol import TProtocolException 11 | from thrift.TRecursive import fix_spec 12 | 13 | import sys 14 | import logging 15 | from .ttypes import * 16 | from thrift.Thrift import TProcessor 17 | from thrift.transport import TTransport 18 | all_structs = [] 19 | 20 | 21 | class Iface(object): 22 | def fetchMessageOperations(self, localRevision, lastOpTimestamp, count): 23 | """ 24 | Parameters: 25 | - localRevision 26 | - lastOpTimestamp 27 | - count 28 | """ 29 | pass 30 | 31 | def getLastReadMessageIds(self, chatId): 32 | """ 33 | Parameters: 34 | - chatId 35 | """ 36 | pass 37 | 38 | def multiGetLastReadMessageIds(self, chatIds): 39 | """ 40 | Parameters: 41 | - chatIds 42 | """ 43 | pass 44 | 45 | 46 | class Client(Iface): 47 | def __init__(self, iprot, oprot=None): 48 | self._iprot = self._oprot = iprot 49 | if oprot is not None: 50 | self._oprot = oprot 51 | self._seqid = 0 52 | 53 | def fetchMessageOperations(self, localRevision, lastOpTimestamp, count): 54 | """ 55 | Parameters: 56 | - localRevision 57 | - lastOpTimestamp 58 | - count 59 | """ 60 | self.send_fetchMessageOperations(localRevision, lastOpTimestamp, count) 61 | return self.recv_fetchMessageOperations() 62 | 63 | def send_fetchMessageOperations(self, localRevision, lastOpTimestamp, count): 64 | self._oprot.writeMessageBegin('fetchMessageOperations', TMessageType.CALL, self._seqid) 65 | args = fetchMessageOperations_args() 66 | args.localRevision = localRevision 67 | args.lastOpTimestamp = lastOpTimestamp 68 | args.count = count 69 | args.write(self._oprot) 70 | self._oprot.writeMessageEnd() 71 | self._oprot.trans.flush() 72 | 73 | def recv_fetchMessageOperations(self): 74 | iprot = self._iprot 75 | (fname, mtype, rseqid) = iprot.readMessageBegin() 76 | if mtype == TMessageType.EXCEPTION: 77 | x = TApplicationException() 78 | x.read(iprot) 79 | iprot.readMessageEnd() 80 | raise x 81 | result = fetchMessageOperations_result() 82 | result.read(iprot) 83 | iprot.readMessageEnd() 84 | if result.success is not None: 85 | return result.success 86 | if result.e is not None: 87 | raise result.e 88 | raise TApplicationException(TApplicationException.MISSING_RESULT, "fetchMessageOperations failed: unknown result") 89 | 90 | def getLastReadMessageIds(self, chatId): 91 | """ 92 | Parameters: 93 | - chatId 94 | """ 95 | self.send_getLastReadMessageIds(chatId) 96 | return self.recv_getLastReadMessageIds() 97 | 98 | def send_getLastReadMessageIds(self, chatId): 99 | self._oprot.writeMessageBegin('getLastReadMessageIds', TMessageType.CALL, self._seqid) 100 | args = getLastReadMessageIds_args() 101 | args.chatId = chatId 102 | args.write(self._oprot) 103 | self._oprot.writeMessageEnd() 104 | self._oprot.trans.flush() 105 | 106 | def recv_getLastReadMessageIds(self): 107 | iprot = self._iprot 108 | (fname, mtype, rseqid) = iprot.readMessageBegin() 109 | if mtype == TMessageType.EXCEPTION: 110 | x = TApplicationException() 111 | x.read(iprot) 112 | iprot.readMessageEnd() 113 | raise x 114 | result = getLastReadMessageIds_result() 115 | result.read(iprot) 116 | iprot.readMessageEnd() 117 | if result.success is not None: 118 | return result.success 119 | if result.e is not None: 120 | raise result.e 121 | raise TApplicationException(TApplicationException.MISSING_RESULT, "getLastReadMessageIds failed: unknown result") 122 | 123 | def multiGetLastReadMessageIds(self, chatIds): 124 | """ 125 | Parameters: 126 | - chatIds 127 | """ 128 | self.send_multiGetLastReadMessageIds(chatIds) 129 | return self.recv_multiGetLastReadMessageIds() 130 | 131 | def send_multiGetLastReadMessageIds(self, chatIds): 132 | self._oprot.writeMessageBegin('multiGetLastReadMessageIds', TMessageType.CALL, self._seqid) 133 | args = multiGetLastReadMessageIds_args() 134 | args.chatIds = chatIds 135 | args.write(self._oprot) 136 | self._oprot.writeMessageEnd() 137 | self._oprot.trans.flush() 138 | 139 | def recv_multiGetLastReadMessageIds(self): 140 | iprot = self._iprot 141 | (fname, mtype, rseqid) = iprot.readMessageBegin() 142 | if mtype == TMessageType.EXCEPTION: 143 | x = TApplicationException() 144 | x.read(iprot) 145 | iprot.readMessageEnd() 146 | raise x 147 | result = multiGetLastReadMessageIds_result() 148 | result.read(iprot) 149 | iprot.readMessageEnd() 150 | if result.success is not None: 151 | return result.success 152 | if result.e is not None: 153 | raise result.e 154 | raise TApplicationException(TApplicationException.MISSING_RESULT, "multiGetLastReadMessageIds failed: unknown result") 155 | 156 | 157 | class Processor(Iface, TProcessor): 158 | def __init__(self, handler): 159 | self._handler = handler 160 | self._processMap = {} 161 | self._processMap["fetchMessageOperations"] = Processor.process_fetchMessageOperations 162 | self._processMap["getLastReadMessageIds"] = Processor.process_getLastReadMessageIds 163 | self._processMap["multiGetLastReadMessageIds"] = Processor.process_multiGetLastReadMessageIds 164 | 165 | def process(self, iprot, oprot): 166 | (name, type, seqid) = iprot.readMessageBegin() 167 | if name not in self._processMap: 168 | iprot.skip(TType.STRUCT) 169 | iprot.readMessageEnd() 170 | x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) 171 | oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) 172 | x.write(oprot) 173 | oprot.writeMessageEnd() 174 | oprot.trans.flush() 175 | return 176 | else: 177 | self._processMap[name](self, seqid, iprot, oprot) 178 | return True 179 | 180 | def process_fetchMessageOperations(self, seqid, iprot, oprot): 181 | args = fetchMessageOperations_args() 182 | args.read(iprot) 183 | iprot.readMessageEnd() 184 | result = fetchMessageOperations_result() 185 | try: 186 | result.success = self._handler.fetchMessageOperations(args.localRevision, args.lastOpTimestamp, args.count) 187 | msg_type = TMessageType.REPLY 188 | except TTransport.TTransportException: 189 | raise 190 | except TalkException as e: 191 | msg_type = TMessageType.REPLY 192 | result.e = e 193 | except TApplicationException as ex: 194 | logging.exception('TApplication exception in handler') 195 | msg_type = TMessageType.EXCEPTION 196 | result = ex 197 | except Exception: 198 | logging.exception('Unexpected exception in handler') 199 | msg_type = TMessageType.EXCEPTION 200 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 201 | oprot.writeMessageBegin("fetchMessageOperations", msg_type, seqid) 202 | result.write(oprot) 203 | oprot.writeMessageEnd() 204 | oprot.trans.flush() 205 | 206 | def process_getLastReadMessageIds(self, seqid, iprot, oprot): 207 | args = getLastReadMessageIds_args() 208 | args.read(iprot) 209 | iprot.readMessageEnd() 210 | result = getLastReadMessageIds_result() 211 | try: 212 | result.success = self._handler.getLastReadMessageIds(args.chatId) 213 | msg_type = TMessageType.REPLY 214 | except TTransport.TTransportException: 215 | raise 216 | except TalkException as e: 217 | msg_type = TMessageType.REPLY 218 | result.e = e 219 | except TApplicationException as ex: 220 | logging.exception('TApplication exception in handler') 221 | msg_type = TMessageType.EXCEPTION 222 | result = ex 223 | except Exception: 224 | logging.exception('Unexpected exception in handler') 225 | msg_type = TMessageType.EXCEPTION 226 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 227 | oprot.writeMessageBegin("getLastReadMessageIds", msg_type, seqid) 228 | result.write(oprot) 229 | oprot.writeMessageEnd() 230 | oprot.trans.flush() 231 | 232 | def process_multiGetLastReadMessageIds(self, seqid, iprot, oprot): 233 | args = multiGetLastReadMessageIds_args() 234 | args.read(iprot) 235 | iprot.readMessageEnd() 236 | result = multiGetLastReadMessageIds_result() 237 | try: 238 | result.success = self._handler.multiGetLastReadMessageIds(args.chatIds) 239 | msg_type = TMessageType.REPLY 240 | except TTransport.TTransportException: 241 | raise 242 | except TalkException as e: 243 | msg_type = TMessageType.REPLY 244 | result.e = e 245 | except TApplicationException as ex: 246 | logging.exception('TApplication exception in handler') 247 | msg_type = TMessageType.EXCEPTION 248 | result = ex 249 | except Exception: 250 | logging.exception('Unexpected exception in handler') 251 | msg_type = TMessageType.EXCEPTION 252 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 253 | oprot.writeMessageBegin("multiGetLastReadMessageIds", msg_type, seqid) 254 | result.write(oprot) 255 | oprot.writeMessageEnd() 256 | oprot.trans.flush() 257 | 258 | # HELPER FUNCTIONS AND STRUCTURES 259 | 260 | 261 | class fetchMessageOperations_args(object): 262 | """ 263 | Attributes: 264 | - localRevision 265 | - lastOpTimestamp 266 | - count 267 | """ 268 | 269 | 270 | def __init__(self, localRevision=None, lastOpTimestamp=None, count=None,): 271 | self.localRevision = localRevision 272 | self.lastOpTimestamp = lastOpTimestamp 273 | self.count = count 274 | 275 | def read(self, iprot): 276 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 277 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 278 | return 279 | iprot.readStructBegin() 280 | while True: 281 | (fname, ftype, fid) = iprot.readFieldBegin() 282 | if ftype == TType.STOP: 283 | break 284 | if fid == 2: 285 | if ftype == TType.I64: 286 | self.localRevision = iprot.readI64() 287 | else: 288 | iprot.skip(ftype) 289 | elif fid == 3: 290 | if ftype == TType.I64: 291 | self.lastOpTimestamp = iprot.readI64() 292 | else: 293 | iprot.skip(ftype) 294 | elif fid == 4: 295 | if ftype == TType.I32: 296 | self.count = iprot.readI32() 297 | else: 298 | iprot.skip(ftype) 299 | else: 300 | iprot.skip(ftype) 301 | iprot.readFieldEnd() 302 | iprot.readStructEnd() 303 | 304 | def write(self, oprot): 305 | if oprot._fast_encode is not None and self.thrift_spec is not None: 306 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 307 | return 308 | oprot.writeStructBegin('fetchMessageOperations_args') 309 | if self.localRevision is not None: 310 | oprot.writeFieldBegin('localRevision', TType.I64, 2) 311 | oprot.writeI64(self.localRevision) 312 | oprot.writeFieldEnd() 313 | if self.lastOpTimestamp is not None: 314 | oprot.writeFieldBegin('lastOpTimestamp', TType.I64, 3) 315 | oprot.writeI64(self.lastOpTimestamp) 316 | oprot.writeFieldEnd() 317 | if self.count is not None: 318 | oprot.writeFieldBegin('count', TType.I32, 4) 319 | oprot.writeI32(self.count) 320 | oprot.writeFieldEnd() 321 | oprot.writeFieldStop() 322 | oprot.writeStructEnd() 323 | 324 | def validate(self): 325 | return 326 | 327 | def __repr__(self): 328 | L = ['%s=%r' % (key, value) 329 | for key, value in self.__dict__.items()] 330 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 331 | 332 | def __eq__(self, other): 333 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 334 | 335 | def __ne__(self, other): 336 | return not (self == other) 337 | all_structs.append(fetchMessageOperations_args) 338 | fetchMessageOperations_args.thrift_spec = ( 339 | None, # 0 340 | None, # 1 341 | (2, TType.I64, 'localRevision', None, None, ), # 2 342 | (3, TType.I64, 'lastOpTimestamp', None, None, ), # 3 343 | (4, TType.I32, 'count', None, None, ), # 4 344 | ) 345 | 346 | 347 | class fetchMessageOperations_result(object): 348 | """ 349 | Attributes: 350 | - success 351 | - e 352 | """ 353 | 354 | 355 | def __init__(self, success=None, e=None,): 356 | self.success = success 357 | self.e = e 358 | 359 | def read(self, iprot): 360 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 361 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 362 | return 363 | iprot.readStructBegin() 364 | while True: 365 | (fname, ftype, fid) = iprot.readFieldBegin() 366 | if ftype == TType.STOP: 367 | break 368 | if fid == 0: 369 | if ftype == TType.STRUCT: 370 | self.success = MessageOperations() 371 | self.success.read(iprot) 372 | else: 373 | iprot.skip(ftype) 374 | elif fid == 1: 375 | if ftype == TType.STRUCT: 376 | self.e = TalkException() 377 | self.e.read(iprot) 378 | else: 379 | iprot.skip(ftype) 380 | else: 381 | iprot.skip(ftype) 382 | iprot.readFieldEnd() 383 | iprot.readStructEnd() 384 | 385 | def write(self, oprot): 386 | if oprot._fast_encode is not None and self.thrift_spec is not None: 387 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 388 | return 389 | oprot.writeStructBegin('fetchMessageOperations_result') 390 | if self.success is not None: 391 | oprot.writeFieldBegin('success', TType.STRUCT, 0) 392 | self.success.write(oprot) 393 | oprot.writeFieldEnd() 394 | if self.e is not None: 395 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 396 | self.e.write(oprot) 397 | oprot.writeFieldEnd() 398 | oprot.writeFieldStop() 399 | oprot.writeStructEnd() 400 | 401 | def validate(self): 402 | return 403 | 404 | def __repr__(self): 405 | L = ['%s=%r' % (key, value) 406 | for key, value in self.__dict__.items()] 407 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 408 | 409 | def __eq__(self, other): 410 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 411 | 412 | def __ne__(self, other): 413 | return not (self == other) 414 | all_structs.append(fetchMessageOperations_result) 415 | fetchMessageOperations_result.thrift_spec = ( 416 | (0, TType.STRUCT, 'success', [MessageOperations, None], None, ), # 0 417 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 418 | ) 419 | 420 | 421 | class getLastReadMessageIds_args(object): 422 | """ 423 | Attributes: 424 | - chatId 425 | """ 426 | 427 | 428 | def __init__(self, chatId=None,): 429 | self.chatId = chatId 430 | 431 | def read(self, iprot): 432 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 433 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 434 | return 435 | iprot.readStructBegin() 436 | while True: 437 | (fname, ftype, fid) = iprot.readFieldBegin() 438 | if ftype == TType.STOP: 439 | break 440 | if fid == 2: 441 | if ftype == TType.STRING: 442 | self.chatId = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 443 | else: 444 | iprot.skip(ftype) 445 | else: 446 | iprot.skip(ftype) 447 | iprot.readFieldEnd() 448 | iprot.readStructEnd() 449 | 450 | def write(self, oprot): 451 | if oprot._fast_encode is not None and self.thrift_spec is not None: 452 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 453 | return 454 | oprot.writeStructBegin('getLastReadMessageIds_args') 455 | if self.chatId is not None: 456 | oprot.writeFieldBegin('chatId', TType.STRING, 2) 457 | oprot.writeString(self.chatId.encode('utf-8') if sys.version_info[0] == 2 else self.chatId) 458 | oprot.writeFieldEnd() 459 | oprot.writeFieldStop() 460 | oprot.writeStructEnd() 461 | 462 | def validate(self): 463 | return 464 | 465 | def __repr__(self): 466 | L = ['%s=%r' % (key, value) 467 | for key, value in self.__dict__.items()] 468 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 469 | 470 | def __eq__(self, other): 471 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 472 | 473 | def __ne__(self, other): 474 | return not (self == other) 475 | all_structs.append(getLastReadMessageIds_args) 476 | getLastReadMessageIds_args.thrift_spec = ( 477 | None, # 0 478 | None, # 1 479 | (2, TType.STRING, 'chatId', 'UTF8', None, ), # 2 480 | ) 481 | 482 | 483 | class getLastReadMessageIds_result(object): 484 | """ 485 | Attributes: 486 | - success 487 | - e 488 | """ 489 | 490 | 491 | def __init__(self, success=None, e=None,): 492 | self.success = success 493 | self.e = e 494 | 495 | def read(self, iprot): 496 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 497 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 498 | return 499 | iprot.readStructBegin() 500 | while True: 501 | (fname, ftype, fid) = iprot.readFieldBegin() 502 | if ftype == TType.STOP: 503 | break 504 | if fid == 0: 505 | if ftype == TType.STRUCT: 506 | self.success = LastReadMessageIds() 507 | self.success.read(iprot) 508 | else: 509 | iprot.skip(ftype) 510 | elif fid == 1: 511 | if ftype == TType.STRUCT: 512 | self.e = TalkException() 513 | self.e.read(iprot) 514 | else: 515 | iprot.skip(ftype) 516 | else: 517 | iprot.skip(ftype) 518 | iprot.readFieldEnd() 519 | iprot.readStructEnd() 520 | 521 | def write(self, oprot): 522 | if oprot._fast_encode is not None and self.thrift_spec is not None: 523 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 524 | return 525 | oprot.writeStructBegin('getLastReadMessageIds_result') 526 | if self.success is not None: 527 | oprot.writeFieldBegin('success', TType.STRUCT, 0) 528 | self.success.write(oprot) 529 | oprot.writeFieldEnd() 530 | if self.e is not None: 531 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 532 | self.e.write(oprot) 533 | oprot.writeFieldEnd() 534 | oprot.writeFieldStop() 535 | oprot.writeStructEnd() 536 | 537 | def validate(self): 538 | return 539 | 540 | def __repr__(self): 541 | L = ['%s=%r' % (key, value) 542 | for key, value in self.__dict__.items()] 543 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 544 | 545 | def __eq__(self, other): 546 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 547 | 548 | def __ne__(self, other): 549 | return not (self == other) 550 | all_structs.append(getLastReadMessageIds_result) 551 | getLastReadMessageIds_result.thrift_spec = ( 552 | (0, TType.STRUCT, 'success', [LastReadMessageIds, None], None, ), # 0 553 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 554 | ) 555 | 556 | 557 | class multiGetLastReadMessageIds_args(object): 558 | """ 559 | Attributes: 560 | - chatIds 561 | """ 562 | 563 | 564 | def __init__(self, chatIds=None,): 565 | self.chatIds = chatIds 566 | 567 | def read(self, iprot): 568 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 569 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 570 | return 571 | iprot.readStructBegin() 572 | while True: 573 | (fname, ftype, fid) = iprot.readFieldBegin() 574 | if ftype == TType.STOP: 575 | break 576 | if fid == 2: 577 | if ftype == TType.LIST: 578 | self.chatIds = [] 579 | (_etype1309, _size1306) = iprot.readListBegin() 580 | for _i1310 in range(_size1306): 581 | _elem1311 = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 582 | self.chatIds.append(_elem1311) 583 | iprot.readListEnd() 584 | else: 585 | iprot.skip(ftype) 586 | else: 587 | iprot.skip(ftype) 588 | iprot.readFieldEnd() 589 | iprot.readStructEnd() 590 | 591 | def write(self, oprot): 592 | if oprot._fast_encode is not None and self.thrift_spec is not None: 593 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 594 | return 595 | oprot.writeStructBegin('multiGetLastReadMessageIds_args') 596 | if self.chatIds is not None: 597 | oprot.writeFieldBegin('chatIds', TType.LIST, 2) 598 | oprot.writeListBegin(TType.STRING, len(self.chatIds)) 599 | for iter1312 in self.chatIds: 600 | oprot.writeString(iter1312.encode('utf-8') if sys.version_info[0] == 2 else iter1312) 601 | oprot.writeListEnd() 602 | oprot.writeFieldEnd() 603 | oprot.writeFieldStop() 604 | oprot.writeStructEnd() 605 | 606 | def validate(self): 607 | return 608 | 609 | def __repr__(self): 610 | L = ['%s=%r' % (key, value) 611 | for key, value in self.__dict__.items()] 612 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 613 | 614 | def __eq__(self, other): 615 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 616 | 617 | def __ne__(self, other): 618 | return not (self == other) 619 | all_structs.append(multiGetLastReadMessageIds_args) 620 | multiGetLastReadMessageIds_args.thrift_spec = ( 621 | None, # 0 622 | None, # 1 623 | (2, TType.LIST, 'chatIds', (TType.STRING, 'UTF8', False), None, ), # 2 624 | ) 625 | 626 | 627 | class multiGetLastReadMessageIds_result(object): 628 | """ 629 | Attributes: 630 | - success 631 | - e 632 | """ 633 | 634 | 635 | def __init__(self, success=None, e=None,): 636 | self.success = success 637 | self.e = e 638 | 639 | def read(self, iprot): 640 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 641 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 642 | return 643 | iprot.readStructBegin() 644 | while True: 645 | (fname, ftype, fid) = iprot.readFieldBegin() 646 | if ftype == TType.STOP: 647 | break 648 | if fid == 0: 649 | if ftype == TType.LIST: 650 | self.success = [] 651 | (_etype1316, _size1313) = iprot.readListBegin() 652 | for _i1317 in range(_size1313): 653 | _elem1318 = LastReadMessageIds() 654 | _elem1318.read(iprot) 655 | self.success.append(_elem1318) 656 | iprot.readListEnd() 657 | else: 658 | iprot.skip(ftype) 659 | elif fid == 1: 660 | if ftype == TType.STRUCT: 661 | self.e = TalkException() 662 | self.e.read(iprot) 663 | else: 664 | iprot.skip(ftype) 665 | else: 666 | iprot.skip(ftype) 667 | iprot.readFieldEnd() 668 | iprot.readStructEnd() 669 | 670 | def write(self, oprot): 671 | if oprot._fast_encode is not None and self.thrift_spec is not None: 672 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 673 | return 674 | oprot.writeStructBegin('multiGetLastReadMessageIds_result') 675 | if self.success is not None: 676 | oprot.writeFieldBegin('success', TType.LIST, 0) 677 | oprot.writeListBegin(TType.STRUCT, len(self.success)) 678 | for iter1319 in self.success: 679 | iter1319.write(oprot) 680 | oprot.writeListEnd() 681 | oprot.writeFieldEnd() 682 | if self.e is not None: 683 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 684 | self.e.write(oprot) 685 | oprot.writeFieldEnd() 686 | oprot.writeFieldStop() 687 | oprot.writeStructEnd() 688 | 689 | def validate(self): 690 | return 691 | 692 | def __repr__(self): 693 | L = ['%s=%r' % (key, value) 694 | for key, value in self.__dict__.items()] 695 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 696 | 697 | def __eq__(self, other): 698 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 699 | 700 | def __ne__(self, other): 701 | return not (self == other) 702 | all_structs.append(multiGetLastReadMessageIds_result) 703 | multiGetLastReadMessageIds_result.thrift_spec = ( 704 | (0, TType.LIST, 'success', (TType.STRUCT, [LastReadMessageIds, None], False), None, ), # 0 705 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 706 | ) 707 | fix_spec(all_structs) 708 | del all_structs 709 | 710 | -------------------------------------------------------------------------------- /akad/SnsAdaptorService.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.11.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException 10 | from thrift.protocol.TProtocol import TProtocolException 11 | from thrift.TRecursive import fix_spec 12 | 13 | import sys 14 | import logging 15 | from .ttypes import * 16 | from thrift.Thrift import TProcessor 17 | from thrift.transport import TTransport 18 | all_structs = [] 19 | 20 | 21 | class Iface(object): 22 | def getSnsFriends(self, snsIdType, snsAccessToken, startIdx, limit): 23 | """ 24 | Parameters: 25 | - snsIdType 26 | - snsAccessToken 27 | - startIdx 28 | - limit 29 | """ 30 | pass 31 | 32 | def getSnsMyProfile(self, snsIdType, snsAccessToken): 33 | """ 34 | Parameters: 35 | - snsIdType 36 | - snsAccessToken 37 | """ 38 | pass 39 | 40 | def postSnsInvitationMessage(self, snsIdType, snsAccessToken, toSnsUserId): 41 | """ 42 | Parameters: 43 | - snsIdType 44 | - snsAccessToken 45 | - toSnsUserId 46 | """ 47 | pass 48 | 49 | 50 | class Client(Iface): 51 | def __init__(self, iprot, oprot=None): 52 | self._iprot = self._oprot = iprot 53 | if oprot is not None: 54 | self._oprot = oprot 55 | self._seqid = 0 56 | 57 | def getSnsFriends(self, snsIdType, snsAccessToken, startIdx, limit): 58 | """ 59 | Parameters: 60 | - snsIdType 61 | - snsAccessToken 62 | - startIdx 63 | - limit 64 | """ 65 | self.send_getSnsFriends(snsIdType, snsAccessToken, startIdx, limit) 66 | return self.recv_getSnsFriends() 67 | 68 | def send_getSnsFriends(self, snsIdType, snsAccessToken, startIdx, limit): 69 | self._oprot.writeMessageBegin('getSnsFriends', TMessageType.CALL, self._seqid) 70 | args = getSnsFriends_args() 71 | args.snsIdType = snsIdType 72 | args.snsAccessToken = snsAccessToken 73 | args.startIdx = startIdx 74 | args.limit = limit 75 | args.write(self._oprot) 76 | self._oprot.writeMessageEnd() 77 | self._oprot.trans.flush() 78 | 79 | def recv_getSnsFriends(self): 80 | iprot = self._iprot 81 | (fname, mtype, rseqid) = iprot.readMessageBegin() 82 | if mtype == TMessageType.EXCEPTION: 83 | x = TApplicationException() 84 | x.read(iprot) 85 | iprot.readMessageEnd() 86 | raise x 87 | result = getSnsFriends_result() 88 | result.read(iprot) 89 | iprot.readMessageEnd() 90 | if result.success is not None: 91 | return result.success 92 | if result.e is not None: 93 | raise result.e 94 | raise TApplicationException(TApplicationException.MISSING_RESULT, "getSnsFriends failed: unknown result") 95 | 96 | def getSnsMyProfile(self, snsIdType, snsAccessToken): 97 | """ 98 | Parameters: 99 | - snsIdType 100 | - snsAccessToken 101 | """ 102 | self.send_getSnsMyProfile(snsIdType, snsAccessToken) 103 | return self.recv_getSnsMyProfile() 104 | 105 | def send_getSnsMyProfile(self, snsIdType, snsAccessToken): 106 | self._oprot.writeMessageBegin('getSnsMyProfile', TMessageType.CALL, self._seqid) 107 | args = getSnsMyProfile_args() 108 | args.snsIdType = snsIdType 109 | args.snsAccessToken = snsAccessToken 110 | args.write(self._oprot) 111 | self._oprot.writeMessageEnd() 112 | self._oprot.trans.flush() 113 | 114 | def recv_getSnsMyProfile(self): 115 | iprot = self._iprot 116 | (fname, mtype, rseqid) = iprot.readMessageBegin() 117 | if mtype == TMessageType.EXCEPTION: 118 | x = TApplicationException() 119 | x.read(iprot) 120 | iprot.readMessageEnd() 121 | raise x 122 | result = getSnsMyProfile_result() 123 | result.read(iprot) 124 | iprot.readMessageEnd() 125 | if result.success is not None: 126 | return result.success 127 | if result.e is not None: 128 | raise result.e 129 | raise TApplicationException(TApplicationException.MISSING_RESULT, "getSnsMyProfile failed: unknown result") 130 | 131 | def postSnsInvitationMessage(self, snsIdType, snsAccessToken, toSnsUserId): 132 | """ 133 | Parameters: 134 | - snsIdType 135 | - snsAccessToken 136 | - toSnsUserId 137 | """ 138 | self.send_postSnsInvitationMessage(snsIdType, snsAccessToken, toSnsUserId) 139 | self.recv_postSnsInvitationMessage() 140 | 141 | def send_postSnsInvitationMessage(self, snsIdType, snsAccessToken, toSnsUserId): 142 | self._oprot.writeMessageBegin('postSnsInvitationMessage', TMessageType.CALL, self._seqid) 143 | args = postSnsInvitationMessage_args() 144 | args.snsIdType = snsIdType 145 | args.snsAccessToken = snsAccessToken 146 | args.toSnsUserId = toSnsUserId 147 | args.write(self._oprot) 148 | self._oprot.writeMessageEnd() 149 | self._oprot.trans.flush() 150 | 151 | def recv_postSnsInvitationMessage(self): 152 | iprot = self._iprot 153 | (fname, mtype, rseqid) = iprot.readMessageBegin() 154 | if mtype == TMessageType.EXCEPTION: 155 | x = TApplicationException() 156 | x.read(iprot) 157 | iprot.readMessageEnd() 158 | raise x 159 | result = postSnsInvitationMessage_result() 160 | result.read(iprot) 161 | iprot.readMessageEnd() 162 | if result.e is not None: 163 | raise result.e 164 | return 165 | 166 | 167 | class Processor(Iface, TProcessor): 168 | def __init__(self, handler): 169 | self._handler = handler 170 | self._processMap = {} 171 | self._processMap["getSnsFriends"] = Processor.process_getSnsFriends 172 | self._processMap["getSnsMyProfile"] = Processor.process_getSnsMyProfile 173 | self._processMap["postSnsInvitationMessage"] = Processor.process_postSnsInvitationMessage 174 | 175 | def process(self, iprot, oprot): 176 | (name, type, seqid) = iprot.readMessageBegin() 177 | if name not in self._processMap: 178 | iprot.skip(TType.STRUCT) 179 | iprot.readMessageEnd() 180 | x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) 181 | oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) 182 | x.write(oprot) 183 | oprot.writeMessageEnd() 184 | oprot.trans.flush() 185 | return 186 | else: 187 | self._processMap[name](self, seqid, iprot, oprot) 188 | return True 189 | 190 | def process_getSnsFriends(self, seqid, iprot, oprot): 191 | args = getSnsFriends_args() 192 | args.read(iprot) 193 | iprot.readMessageEnd() 194 | result = getSnsFriends_result() 195 | try: 196 | result.success = self._handler.getSnsFriends(args.snsIdType, args.snsAccessToken, args.startIdx, args.limit) 197 | msg_type = TMessageType.REPLY 198 | except TTransport.TTransportException: 199 | raise 200 | except TalkException as e: 201 | msg_type = TMessageType.REPLY 202 | result.e = e 203 | except TApplicationException as ex: 204 | logging.exception('TApplication exception in handler') 205 | msg_type = TMessageType.EXCEPTION 206 | result = ex 207 | except Exception: 208 | logging.exception('Unexpected exception in handler') 209 | msg_type = TMessageType.EXCEPTION 210 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 211 | oprot.writeMessageBegin("getSnsFriends", msg_type, seqid) 212 | result.write(oprot) 213 | oprot.writeMessageEnd() 214 | oprot.trans.flush() 215 | 216 | def process_getSnsMyProfile(self, seqid, iprot, oprot): 217 | args = getSnsMyProfile_args() 218 | args.read(iprot) 219 | iprot.readMessageEnd() 220 | result = getSnsMyProfile_result() 221 | try: 222 | result.success = self._handler.getSnsMyProfile(args.snsIdType, args.snsAccessToken) 223 | msg_type = TMessageType.REPLY 224 | except TTransport.TTransportException: 225 | raise 226 | except TalkException as e: 227 | msg_type = TMessageType.REPLY 228 | result.e = e 229 | except TApplicationException as ex: 230 | logging.exception('TApplication exception in handler') 231 | msg_type = TMessageType.EXCEPTION 232 | result = ex 233 | except Exception: 234 | logging.exception('Unexpected exception in handler') 235 | msg_type = TMessageType.EXCEPTION 236 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 237 | oprot.writeMessageBegin("getSnsMyProfile", msg_type, seqid) 238 | result.write(oprot) 239 | oprot.writeMessageEnd() 240 | oprot.trans.flush() 241 | 242 | def process_postSnsInvitationMessage(self, seqid, iprot, oprot): 243 | args = postSnsInvitationMessage_args() 244 | args.read(iprot) 245 | iprot.readMessageEnd() 246 | result = postSnsInvitationMessage_result() 247 | try: 248 | self._handler.postSnsInvitationMessage(args.snsIdType, args.snsAccessToken, args.toSnsUserId) 249 | msg_type = TMessageType.REPLY 250 | except TTransport.TTransportException: 251 | raise 252 | except TalkException as e: 253 | msg_type = TMessageType.REPLY 254 | result.e = e 255 | except TApplicationException as ex: 256 | logging.exception('TApplication exception in handler') 257 | msg_type = TMessageType.EXCEPTION 258 | result = ex 259 | except Exception: 260 | logging.exception('Unexpected exception in handler') 261 | msg_type = TMessageType.EXCEPTION 262 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 263 | oprot.writeMessageBegin("postSnsInvitationMessage", msg_type, seqid) 264 | result.write(oprot) 265 | oprot.writeMessageEnd() 266 | oprot.trans.flush() 267 | 268 | # HELPER FUNCTIONS AND STRUCTURES 269 | 270 | 271 | class getSnsFriends_args(object): 272 | """ 273 | Attributes: 274 | - snsIdType 275 | - snsAccessToken 276 | - startIdx 277 | - limit 278 | """ 279 | 280 | 281 | def __init__(self, snsIdType=None, snsAccessToken=None, startIdx=None, limit=None,): 282 | self.snsIdType = snsIdType 283 | self.snsAccessToken = snsAccessToken 284 | self.startIdx = startIdx 285 | self.limit = limit 286 | 287 | def read(self, iprot): 288 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 289 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 290 | return 291 | iprot.readStructBegin() 292 | while True: 293 | (fname, ftype, fid) = iprot.readFieldBegin() 294 | if ftype == TType.STOP: 295 | break 296 | if fid == 2: 297 | if ftype == TType.I32: 298 | self.snsIdType = iprot.readI32() 299 | else: 300 | iprot.skip(ftype) 301 | elif fid == 3: 302 | if ftype == TType.STRING: 303 | self.snsAccessToken = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 304 | else: 305 | iprot.skip(ftype) 306 | elif fid == 4: 307 | if ftype == TType.I32: 308 | self.startIdx = iprot.readI32() 309 | else: 310 | iprot.skip(ftype) 311 | elif fid == 5: 312 | if ftype == TType.I32: 313 | self.limit = iprot.readI32() 314 | else: 315 | iprot.skip(ftype) 316 | else: 317 | iprot.skip(ftype) 318 | iprot.readFieldEnd() 319 | iprot.readStructEnd() 320 | 321 | def write(self, oprot): 322 | if oprot._fast_encode is not None and self.thrift_spec is not None: 323 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 324 | return 325 | oprot.writeStructBegin('getSnsFriends_args') 326 | if self.snsIdType is not None: 327 | oprot.writeFieldBegin('snsIdType', TType.I32, 2) 328 | oprot.writeI32(self.snsIdType) 329 | oprot.writeFieldEnd() 330 | if self.snsAccessToken is not None: 331 | oprot.writeFieldBegin('snsAccessToken', TType.STRING, 3) 332 | oprot.writeString(self.snsAccessToken.encode('utf-8') if sys.version_info[0] == 2 else self.snsAccessToken) 333 | oprot.writeFieldEnd() 334 | if self.startIdx is not None: 335 | oprot.writeFieldBegin('startIdx', TType.I32, 4) 336 | oprot.writeI32(self.startIdx) 337 | oprot.writeFieldEnd() 338 | if self.limit is not None: 339 | oprot.writeFieldBegin('limit', TType.I32, 5) 340 | oprot.writeI32(self.limit) 341 | oprot.writeFieldEnd() 342 | oprot.writeFieldStop() 343 | oprot.writeStructEnd() 344 | 345 | def validate(self): 346 | return 347 | 348 | def __repr__(self): 349 | L = ['%s=%r' % (key, value) 350 | for key, value in self.__dict__.items()] 351 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 352 | 353 | def __eq__(self, other): 354 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 355 | 356 | def __ne__(self, other): 357 | return not (self == other) 358 | all_structs.append(getSnsFriends_args) 359 | getSnsFriends_args.thrift_spec = ( 360 | None, # 0 361 | None, # 1 362 | (2, TType.I32, 'snsIdType', None, None, ), # 2 363 | (3, TType.STRING, 'snsAccessToken', 'UTF8', None, ), # 3 364 | (4, TType.I32, 'startIdx', None, None, ), # 4 365 | (5, TType.I32, 'limit', None, None, ), # 5 366 | ) 367 | 368 | 369 | class getSnsFriends_result(object): 370 | """ 371 | Attributes: 372 | - success 373 | - e 374 | """ 375 | 376 | 377 | def __init__(self, success=None, e=None,): 378 | self.success = success 379 | self.e = e 380 | 381 | def read(self, iprot): 382 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 383 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 384 | return 385 | iprot.readStructBegin() 386 | while True: 387 | (fname, ftype, fid) = iprot.readFieldBegin() 388 | if ftype == TType.STOP: 389 | break 390 | if fid == 0: 391 | if ftype == TType.STRUCT: 392 | self.success = SnsFriends() 393 | self.success.read(iprot) 394 | else: 395 | iprot.skip(ftype) 396 | elif fid == 1: 397 | if ftype == TType.STRUCT: 398 | self.e = TalkException() 399 | self.e.read(iprot) 400 | else: 401 | iprot.skip(ftype) 402 | else: 403 | iprot.skip(ftype) 404 | iprot.readFieldEnd() 405 | iprot.readStructEnd() 406 | 407 | def write(self, oprot): 408 | if oprot._fast_encode is not None and self.thrift_spec is not None: 409 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 410 | return 411 | oprot.writeStructBegin('getSnsFriends_result') 412 | if self.success is not None: 413 | oprot.writeFieldBegin('success', TType.STRUCT, 0) 414 | self.success.write(oprot) 415 | oprot.writeFieldEnd() 416 | if self.e is not None: 417 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 418 | self.e.write(oprot) 419 | oprot.writeFieldEnd() 420 | oprot.writeFieldStop() 421 | oprot.writeStructEnd() 422 | 423 | def validate(self): 424 | return 425 | 426 | def __repr__(self): 427 | L = ['%s=%r' % (key, value) 428 | for key, value in self.__dict__.items()] 429 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 430 | 431 | def __eq__(self, other): 432 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 433 | 434 | def __ne__(self, other): 435 | return not (self == other) 436 | all_structs.append(getSnsFriends_result) 437 | getSnsFriends_result.thrift_spec = ( 438 | (0, TType.STRUCT, 'success', [SnsFriends, None], None, ), # 0 439 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 440 | ) 441 | 442 | 443 | class getSnsMyProfile_args(object): 444 | """ 445 | Attributes: 446 | - snsIdType 447 | - snsAccessToken 448 | """ 449 | 450 | 451 | def __init__(self, snsIdType=None, snsAccessToken=None,): 452 | self.snsIdType = snsIdType 453 | self.snsAccessToken = snsAccessToken 454 | 455 | def read(self, iprot): 456 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 457 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 458 | return 459 | iprot.readStructBegin() 460 | while True: 461 | (fname, ftype, fid) = iprot.readFieldBegin() 462 | if ftype == TType.STOP: 463 | break 464 | if fid == 2: 465 | if ftype == TType.I32: 466 | self.snsIdType = iprot.readI32() 467 | else: 468 | iprot.skip(ftype) 469 | elif fid == 3: 470 | if ftype == TType.STRING: 471 | self.snsAccessToken = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 472 | else: 473 | iprot.skip(ftype) 474 | else: 475 | iprot.skip(ftype) 476 | iprot.readFieldEnd() 477 | iprot.readStructEnd() 478 | 479 | def write(self, oprot): 480 | if oprot._fast_encode is not None and self.thrift_spec is not None: 481 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 482 | return 483 | oprot.writeStructBegin('getSnsMyProfile_args') 484 | if self.snsIdType is not None: 485 | oprot.writeFieldBegin('snsIdType', TType.I32, 2) 486 | oprot.writeI32(self.snsIdType) 487 | oprot.writeFieldEnd() 488 | if self.snsAccessToken is not None: 489 | oprot.writeFieldBegin('snsAccessToken', TType.STRING, 3) 490 | oprot.writeString(self.snsAccessToken.encode('utf-8') if sys.version_info[0] == 2 else self.snsAccessToken) 491 | oprot.writeFieldEnd() 492 | oprot.writeFieldStop() 493 | oprot.writeStructEnd() 494 | 495 | def validate(self): 496 | return 497 | 498 | def __repr__(self): 499 | L = ['%s=%r' % (key, value) 500 | for key, value in self.__dict__.items()] 501 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 502 | 503 | def __eq__(self, other): 504 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 505 | 506 | def __ne__(self, other): 507 | return not (self == other) 508 | all_structs.append(getSnsMyProfile_args) 509 | getSnsMyProfile_args.thrift_spec = ( 510 | None, # 0 511 | None, # 1 512 | (2, TType.I32, 'snsIdType', None, None, ), # 2 513 | (3, TType.STRING, 'snsAccessToken', 'UTF8', None, ), # 3 514 | ) 515 | 516 | 517 | class getSnsMyProfile_result(object): 518 | """ 519 | Attributes: 520 | - success 521 | - e 522 | """ 523 | 524 | 525 | def __init__(self, success=None, e=None,): 526 | self.success = success 527 | self.e = e 528 | 529 | def read(self, iprot): 530 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 531 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 532 | return 533 | iprot.readStructBegin() 534 | while True: 535 | (fname, ftype, fid) = iprot.readFieldBegin() 536 | if ftype == TType.STOP: 537 | break 538 | if fid == 0: 539 | if ftype == TType.STRUCT: 540 | self.success = SnsProfile() 541 | self.success.read(iprot) 542 | else: 543 | iprot.skip(ftype) 544 | elif fid == 1: 545 | if ftype == TType.STRUCT: 546 | self.e = TalkException() 547 | self.e.read(iprot) 548 | else: 549 | iprot.skip(ftype) 550 | else: 551 | iprot.skip(ftype) 552 | iprot.readFieldEnd() 553 | iprot.readStructEnd() 554 | 555 | def write(self, oprot): 556 | if oprot._fast_encode is not None and self.thrift_spec is not None: 557 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 558 | return 559 | oprot.writeStructBegin('getSnsMyProfile_result') 560 | if self.success is not None: 561 | oprot.writeFieldBegin('success', TType.STRUCT, 0) 562 | self.success.write(oprot) 563 | oprot.writeFieldEnd() 564 | if self.e is not None: 565 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 566 | self.e.write(oprot) 567 | oprot.writeFieldEnd() 568 | oprot.writeFieldStop() 569 | oprot.writeStructEnd() 570 | 571 | def validate(self): 572 | return 573 | 574 | def __repr__(self): 575 | L = ['%s=%r' % (key, value) 576 | for key, value in self.__dict__.items()] 577 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 578 | 579 | def __eq__(self, other): 580 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 581 | 582 | def __ne__(self, other): 583 | return not (self == other) 584 | all_structs.append(getSnsMyProfile_result) 585 | getSnsMyProfile_result.thrift_spec = ( 586 | (0, TType.STRUCT, 'success', [SnsProfile, None], None, ), # 0 587 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 588 | ) 589 | 590 | 591 | class postSnsInvitationMessage_args(object): 592 | """ 593 | Attributes: 594 | - snsIdType 595 | - snsAccessToken 596 | - toSnsUserId 597 | """ 598 | 599 | 600 | def __init__(self, snsIdType=None, snsAccessToken=None, toSnsUserId=None,): 601 | self.snsIdType = snsIdType 602 | self.snsAccessToken = snsAccessToken 603 | self.toSnsUserId = toSnsUserId 604 | 605 | def read(self, iprot): 606 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 607 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 608 | return 609 | iprot.readStructBegin() 610 | while True: 611 | (fname, ftype, fid) = iprot.readFieldBegin() 612 | if ftype == TType.STOP: 613 | break 614 | if fid == 2: 615 | if ftype == TType.I32: 616 | self.snsIdType = iprot.readI32() 617 | else: 618 | iprot.skip(ftype) 619 | elif fid == 3: 620 | if ftype == TType.STRING: 621 | self.snsAccessToken = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 622 | else: 623 | iprot.skip(ftype) 624 | elif fid == 4: 625 | if ftype == TType.STRING: 626 | self.toSnsUserId = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 627 | else: 628 | iprot.skip(ftype) 629 | else: 630 | iprot.skip(ftype) 631 | iprot.readFieldEnd() 632 | iprot.readStructEnd() 633 | 634 | def write(self, oprot): 635 | if oprot._fast_encode is not None and self.thrift_spec is not None: 636 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 637 | return 638 | oprot.writeStructBegin('postSnsInvitationMessage_args') 639 | if self.snsIdType is not None: 640 | oprot.writeFieldBegin('snsIdType', TType.I32, 2) 641 | oprot.writeI32(self.snsIdType) 642 | oprot.writeFieldEnd() 643 | if self.snsAccessToken is not None: 644 | oprot.writeFieldBegin('snsAccessToken', TType.STRING, 3) 645 | oprot.writeString(self.snsAccessToken.encode('utf-8') if sys.version_info[0] == 2 else self.snsAccessToken) 646 | oprot.writeFieldEnd() 647 | if self.toSnsUserId is not None: 648 | oprot.writeFieldBegin('toSnsUserId', TType.STRING, 4) 649 | oprot.writeString(self.toSnsUserId.encode('utf-8') if sys.version_info[0] == 2 else self.toSnsUserId) 650 | oprot.writeFieldEnd() 651 | oprot.writeFieldStop() 652 | oprot.writeStructEnd() 653 | 654 | def validate(self): 655 | return 656 | 657 | def __repr__(self): 658 | L = ['%s=%r' % (key, value) 659 | for key, value in self.__dict__.items()] 660 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 661 | 662 | def __eq__(self, other): 663 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 664 | 665 | def __ne__(self, other): 666 | return not (self == other) 667 | all_structs.append(postSnsInvitationMessage_args) 668 | postSnsInvitationMessage_args.thrift_spec = ( 669 | None, # 0 670 | None, # 1 671 | (2, TType.I32, 'snsIdType', None, None, ), # 2 672 | (3, TType.STRING, 'snsAccessToken', 'UTF8', None, ), # 3 673 | (4, TType.STRING, 'toSnsUserId', 'UTF8', None, ), # 4 674 | ) 675 | 676 | 677 | class postSnsInvitationMessage_result(object): 678 | """ 679 | Attributes: 680 | - e 681 | """ 682 | 683 | 684 | def __init__(self, e=None,): 685 | self.e = e 686 | 687 | def read(self, iprot): 688 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 689 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 690 | return 691 | iprot.readStructBegin() 692 | while True: 693 | (fname, ftype, fid) = iprot.readFieldBegin() 694 | if ftype == TType.STOP: 695 | break 696 | if fid == 1: 697 | if ftype == TType.STRUCT: 698 | self.e = TalkException() 699 | self.e.read(iprot) 700 | else: 701 | iprot.skip(ftype) 702 | else: 703 | iprot.skip(ftype) 704 | iprot.readFieldEnd() 705 | iprot.readStructEnd() 706 | 707 | def write(self, oprot): 708 | if oprot._fast_encode is not None and self.thrift_spec is not None: 709 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 710 | return 711 | oprot.writeStructBegin('postSnsInvitationMessage_result') 712 | if self.e is not None: 713 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 714 | self.e.write(oprot) 715 | oprot.writeFieldEnd() 716 | oprot.writeFieldStop() 717 | oprot.writeStructEnd() 718 | 719 | def validate(self): 720 | return 721 | 722 | def __repr__(self): 723 | L = ['%s=%r' % (key, value) 724 | for key, value in self.__dict__.items()] 725 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 726 | 727 | def __eq__(self, other): 728 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 729 | 730 | def __ne__(self, other): 731 | return not (self == other) 732 | all_structs.append(postSnsInvitationMessage_result) 733 | postSnsInvitationMessage_result.thrift_spec = ( 734 | None, # 0 735 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 736 | ) 737 | fix_spec(all_structs) 738 | del all_structs 739 | 740 | -------------------------------------------------------------------------------- /akad/SpotService.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.11.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException 10 | from thrift.protocol.TProtocol import TProtocolException 11 | from thrift.TRecursive import fix_spec 12 | 13 | import sys 14 | import logging 15 | from .ttypes import * 16 | from thrift.Thrift import TProcessor 17 | from thrift.transport import TTransport 18 | all_structs = [] 19 | 20 | 21 | class Iface(object): 22 | def lookupByPhoneNumber(self, countryAreaCode, phoneNumber): 23 | """ 24 | Parameters: 25 | - countryAreaCode 26 | - phoneNumber 27 | """ 28 | pass 29 | 30 | def lookupNearby(self, location, category, query, countryAreaCode): 31 | """ 32 | Parameters: 33 | - location 34 | - category 35 | - query 36 | - countryAreaCode 37 | """ 38 | pass 39 | 40 | 41 | class Client(Iface): 42 | def __init__(self, iprot, oprot=None): 43 | self._iprot = self._oprot = iprot 44 | if oprot is not None: 45 | self._oprot = oprot 46 | self._seqid = 0 47 | 48 | def lookupByPhoneNumber(self, countryAreaCode, phoneNumber): 49 | """ 50 | Parameters: 51 | - countryAreaCode 52 | - phoneNumber 53 | """ 54 | self.send_lookupByPhoneNumber(countryAreaCode, phoneNumber) 55 | return self.recv_lookupByPhoneNumber() 56 | 57 | def send_lookupByPhoneNumber(self, countryAreaCode, phoneNumber): 58 | self._oprot.writeMessageBegin('lookupByPhoneNumber', TMessageType.CALL, self._seqid) 59 | args = lookupByPhoneNumber_args() 60 | args.countryAreaCode = countryAreaCode 61 | args.phoneNumber = phoneNumber 62 | args.write(self._oprot) 63 | self._oprot.writeMessageEnd() 64 | self._oprot.trans.flush() 65 | 66 | def recv_lookupByPhoneNumber(self): 67 | iprot = self._iprot 68 | (fname, mtype, rseqid) = iprot.readMessageBegin() 69 | if mtype == TMessageType.EXCEPTION: 70 | x = TApplicationException() 71 | x.read(iprot) 72 | iprot.readMessageEnd() 73 | raise x 74 | result = lookupByPhoneNumber_result() 75 | result.read(iprot) 76 | iprot.readMessageEnd() 77 | if result.success is not None: 78 | return result.success 79 | if result.e is not None: 80 | raise result.e 81 | raise TApplicationException(TApplicationException.MISSING_RESULT, "lookupByPhoneNumber failed: unknown result") 82 | 83 | def lookupNearby(self, location, category, query, countryAreaCode): 84 | """ 85 | Parameters: 86 | - location 87 | - category 88 | - query 89 | - countryAreaCode 90 | """ 91 | self.send_lookupNearby(location, category, query, countryAreaCode) 92 | return self.recv_lookupNearby() 93 | 94 | def send_lookupNearby(self, location, category, query, countryAreaCode): 95 | self._oprot.writeMessageBegin('lookupNearby', TMessageType.CALL, self._seqid) 96 | args = lookupNearby_args() 97 | args.location = location 98 | args.category = category 99 | args.query = query 100 | args.countryAreaCode = countryAreaCode 101 | args.write(self._oprot) 102 | self._oprot.writeMessageEnd() 103 | self._oprot.trans.flush() 104 | 105 | def recv_lookupNearby(self): 106 | iprot = self._iprot 107 | (fname, mtype, rseqid) = iprot.readMessageBegin() 108 | if mtype == TMessageType.EXCEPTION: 109 | x = TApplicationException() 110 | x.read(iprot) 111 | iprot.readMessageEnd() 112 | raise x 113 | result = lookupNearby_result() 114 | result.read(iprot) 115 | iprot.readMessageEnd() 116 | if result.success is not None: 117 | return result.success 118 | if result.e is not None: 119 | raise result.e 120 | raise TApplicationException(TApplicationException.MISSING_RESULT, "lookupNearby failed: unknown result") 121 | 122 | 123 | class Processor(Iface, TProcessor): 124 | def __init__(self, handler): 125 | self._handler = handler 126 | self._processMap = {} 127 | self._processMap["lookupByPhoneNumber"] = Processor.process_lookupByPhoneNumber 128 | self._processMap["lookupNearby"] = Processor.process_lookupNearby 129 | 130 | def process(self, iprot, oprot): 131 | (name, type, seqid) = iprot.readMessageBegin() 132 | if name not in self._processMap: 133 | iprot.skip(TType.STRUCT) 134 | iprot.readMessageEnd() 135 | x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) 136 | oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) 137 | x.write(oprot) 138 | oprot.writeMessageEnd() 139 | oprot.trans.flush() 140 | return 141 | else: 142 | self._processMap[name](self, seqid, iprot, oprot) 143 | return True 144 | 145 | def process_lookupByPhoneNumber(self, seqid, iprot, oprot): 146 | args = lookupByPhoneNumber_args() 147 | args.read(iprot) 148 | iprot.readMessageEnd() 149 | result = lookupByPhoneNumber_result() 150 | try: 151 | result.success = self._handler.lookupByPhoneNumber(args.countryAreaCode, args.phoneNumber) 152 | msg_type = TMessageType.REPLY 153 | except TTransport.TTransportException: 154 | raise 155 | except TalkException as e: 156 | msg_type = TMessageType.REPLY 157 | result.e = e 158 | except TApplicationException as ex: 159 | logging.exception('TApplication exception in handler') 160 | msg_type = TMessageType.EXCEPTION 161 | result = ex 162 | except Exception: 163 | logging.exception('Unexpected exception in handler') 164 | msg_type = TMessageType.EXCEPTION 165 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 166 | oprot.writeMessageBegin("lookupByPhoneNumber", msg_type, seqid) 167 | result.write(oprot) 168 | oprot.writeMessageEnd() 169 | oprot.trans.flush() 170 | 171 | def process_lookupNearby(self, seqid, iprot, oprot): 172 | args = lookupNearby_args() 173 | args.read(iprot) 174 | iprot.readMessageEnd() 175 | result = lookupNearby_result() 176 | try: 177 | result.success = self._handler.lookupNearby(args.location, args.category, args.query, args.countryAreaCode) 178 | msg_type = TMessageType.REPLY 179 | except TTransport.TTransportException: 180 | raise 181 | except TalkException as e: 182 | msg_type = TMessageType.REPLY 183 | result.e = e 184 | except TApplicationException as ex: 185 | logging.exception('TApplication exception in handler') 186 | msg_type = TMessageType.EXCEPTION 187 | result = ex 188 | except Exception: 189 | logging.exception('Unexpected exception in handler') 190 | msg_type = TMessageType.EXCEPTION 191 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 192 | oprot.writeMessageBegin("lookupNearby", msg_type, seqid) 193 | result.write(oprot) 194 | oprot.writeMessageEnd() 195 | oprot.trans.flush() 196 | 197 | # HELPER FUNCTIONS AND STRUCTURES 198 | 199 | 200 | class lookupByPhoneNumber_args(object): 201 | """ 202 | Attributes: 203 | - countryAreaCode 204 | - phoneNumber 205 | """ 206 | 207 | 208 | def __init__(self, countryAreaCode=None, phoneNumber=None,): 209 | self.countryAreaCode = countryAreaCode 210 | self.phoneNumber = phoneNumber 211 | 212 | def read(self, iprot): 213 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 214 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 215 | return 216 | iprot.readStructBegin() 217 | while True: 218 | (fname, ftype, fid) = iprot.readFieldBegin() 219 | if ftype == TType.STOP: 220 | break 221 | if fid == 2: 222 | if ftype == TType.STRING: 223 | self.countryAreaCode = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 224 | else: 225 | iprot.skip(ftype) 226 | elif fid == 3: 227 | if ftype == TType.STRING: 228 | self.phoneNumber = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 229 | else: 230 | iprot.skip(ftype) 231 | else: 232 | iprot.skip(ftype) 233 | iprot.readFieldEnd() 234 | iprot.readStructEnd() 235 | 236 | def write(self, oprot): 237 | if oprot._fast_encode is not None and self.thrift_spec is not None: 238 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 239 | return 240 | oprot.writeStructBegin('lookupByPhoneNumber_args') 241 | if self.countryAreaCode is not None: 242 | oprot.writeFieldBegin('countryAreaCode', TType.STRING, 2) 243 | oprot.writeString(self.countryAreaCode.encode('utf-8') if sys.version_info[0] == 2 else self.countryAreaCode) 244 | oprot.writeFieldEnd() 245 | if self.phoneNumber is not None: 246 | oprot.writeFieldBegin('phoneNumber', TType.STRING, 3) 247 | oprot.writeString(self.phoneNumber.encode('utf-8') if sys.version_info[0] == 2 else self.phoneNumber) 248 | oprot.writeFieldEnd() 249 | oprot.writeFieldStop() 250 | oprot.writeStructEnd() 251 | 252 | def validate(self): 253 | return 254 | 255 | def __repr__(self): 256 | L = ['%s=%r' % (key, value) 257 | for key, value in self.__dict__.items()] 258 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 259 | 260 | def __eq__(self, other): 261 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 262 | 263 | def __ne__(self, other): 264 | return not (self == other) 265 | all_structs.append(lookupByPhoneNumber_args) 266 | lookupByPhoneNumber_args.thrift_spec = ( 267 | None, # 0 268 | None, # 1 269 | (2, TType.STRING, 'countryAreaCode', 'UTF8', None, ), # 2 270 | (3, TType.STRING, 'phoneNumber', 'UTF8', None, ), # 3 271 | ) 272 | 273 | 274 | class lookupByPhoneNumber_result(object): 275 | """ 276 | Attributes: 277 | - success 278 | - e 279 | """ 280 | 281 | 282 | def __init__(self, success=None, e=None,): 283 | self.success = success 284 | self.e = e 285 | 286 | def read(self, iprot): 287 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 288 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 289 | return 290 | iprot.readStructBegin() 291 | while True: 292 | (fname, ftype, fid) = iprot.readFieldBegin() 293 | if ftype == TType.STOP: 294 | break 295 | if fid == 0: 296 | if ftype == TType.STRUCT: 297 | self.success = SpotPhoneNumberResponse() 298 | self.success.read(iprot) 299 | else: 300 | iprot.skip(ftype) 301 | elif fid == 1: 302 | if ftype == TType.STRUCT: 303 | self.e = TalkException() 304 | self.e.read(iprot) 305 | else: 306 | iprot.skip(ftype) 307 | else: 308 | iprot.skip(ftype) 309 | iprot.readFieldEnd() 310 | iprot.readStructEnd() 311 | 312 | def write(self, oprot): 313 | if oprot._fast_encode is not None and self.thrift_spec is not None: 314 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 315 | return 316 | oprot.writeStructBegin('lookupByPhoneNumber_result') 317 | if self.success is not None: 318 | oprot.writeFieldBegin('success', TType.STRUCT, 0) 319 | self.success.write(oprot) 320 | oprot.writeFieldEnd() 321 | if self.e is not None: 322 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 323 | self.e.write(oprot) 324 | oprot.writeFieldEnd() 325 | oprot.writeFieldStop() 326 | oprot.writeStructEnd() 327 | 328 | def validate(self): 329 | return 330 | 331 | def __repr__(self): 332 | L = ['%s=%r' % (key, value) 333 | for key, value in self.__dict__.items()] 334 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 335 | 336 | def __eq__(self, other): 337 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 338 | 339 | def __ne__(self, other): 340 | return not (self == other) 341 | all_structs.append(lookupByPhoneNumber_result) 342 | lookupByPhoneNumber_result.thrift_spec = ( 343 | (0, TType.STRUCT, 'success', [SpotPhoneNumberResponse, None], None, ), # 0 344 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 345 | ) 346 | 347 | 348 | class lookupNearby_args(object): 349 | """ 350 | Attributes: 351 | - location 352 | - category 353 | - query 354 | - countryAreaCode 355 | """ 356 | 357 | 358 | def __init__(self, location=None, category=None, query=None, countryAreaCode=None,): 359 | self.location = location 360 | self.category = category 361 | self.query = query 362 | self.countryAreaCode = countryAreaCode 363 | 364 | def read(self, iprot): 365 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 366 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 367 | return 368 | iprot.readStructBegin() 369 | while True: 370 | (fname, ftype, fid) = iprot.readFieldBegin() 371 | if ftype == TType.STOP: 372 | break 373 | if fid == 2: 374 | if ftype == TType.STRUCT: 375 | self.location = Location() 376 | self.location.read(iprot) 377 | else: 378 | iprot.skip(ftype) 379 | elif fid == 3: 380 | if ftype == TType.I32: 381 | self.category = iprot.readI32() 382 | else: 383 | iprot.skip(ftype) 384 | elif fid == 4: 385 | if ftype == TType.STRING: 386 | self.query = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 387 | else: 388 | iprot.skip(ftype) 389 | elif fid == 5: 390 | if ftype == TType.STRING: 391 | self.countryAreaCode = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() 392 | else: 393 | iprot.skip(ftype) 394 | else: 395 | iprot.skip(ftype) 396 | iprot.readFieldEnd() 397 | iprot.readStructEnd() 398 | 399 | def write(self, oprot): 400 | if oprot._fast_encode is not None and self.thrift_spec is not None: 401 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 402 | return 403 | oprot.writeStructBegin('lookupNearby_args') 404 | if self.location is not None: 405 | oprot.writeFieldBegin('location', TType.STRUCT, 2) 406 | self.location.write(oprot) 407 | oprot.writeFieldEnd() 408 | if self.category is not None: 409 | oprot.writeFieldBegin('category', TType.I32, 3) 410 | oprot.writeI32(self.category) 411 | oprot.writeFieldEnd() 412 | if self.query is not None: 413 | oprot.writeFieldBegin('query', TType.STRING, 4) 414 | oprot.writeString(self.query.encode('utf-8') if sys.version_info[0] == 2 else self.query) 415 | oprot.writeFieldEnd() 416 | if self.countryAreaCode is not None: 417 | oprot.writeFieldBegin('countryAreaCode', TType.STRING, 5) 418 | oprot.writeString(self.countryAreaCode.encode('utf-8') if sys.version_info[0] == 2 else self.countryAreaCode) 419 | oprot.writeFieldEnd() 420 | oprot.writeFieldStop() 421 | oprot.writeStructEnd() 422 | 423 | def validate(self): 424 | return 425 | 426 | def __repr__(self): 427 | L = ['%s=%r' % (key, value) 428 | for key, value in self.__dict__.items()] 429 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 430 | 431 | def __eq__(self, other): 432 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 433 | 434 | def __ne__(self, other): 435 | return not (self == other) 436 | all_structs.append(lookupNearby_args) 437 | lookupNearby_args.thrift_spec = ( 438 | None, # 0 439 | None, # 1 440 | (2, TType.STRUCT, 'location', [Location, None], None, ), # 2 441 | (3, TType.I32, 'category', None, None, ), # 3 442 | (4, TType.STRING, 'query', 'UTF8', None, ), # 4 443 | (5, TType.STRING, 'countryAreaCode', 'UTF8', None, ), # 5 444 | ) 445 | 446 | 447 | class lookupNearby_result(object): 448 | """ 449 | Attributes: 450 | - success 451 | - e 452 | """ 453 | 454 | 455 | def __init__(self, success=None, e=None,): 456 | self.success = success 457 | self.e = e 458 | 459 | def read(self, iprot): 460 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 461 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 462 | return 463 | iprot.readStructBegin() 464 | while True: 465 | (fname, ftype, fid) = iprot.readFieldBegin() 466 | if ftype == TType.STOP: 467 | break 468 | if fid == 0: 469 | if ftype == TType.STRUCT: 470 | self.success = SpotNearbyResponse() 471 | self.success.read(iprot) 472 | else: 473 | iprot.skip(ftype) 474 | elif fid == 1: 475 | if ftype == TType.STRUCT: 476 | self.e = TalkException() 477 | self.e.read(iprot) 478 | else: 479 | iprot.skip(ftype) 480 | else: 481 | iprot.skip(ftype) 482 | iprot.readFieldEnd() 483 | iprot.readStructEnd() 484 | 485 | def write(self, oprot): 486 | if oprot._fast_encode is not None and self.thrift_spec is not None: 487 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 488 | return 489 | oprot.writeStructBegin('lookupNearby_result') 490 | if self.success is not None: 491 | oprot.writeFieldBegin('success', TType.STRUCT, 0) 492 | self.success.write(oprot) 493 | oprot.writeFieldEnd() 494 | if self.e is not None: 495 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 496 | self.e.write(oprot) 497 | oprot.writeFieldEnd() 498 | oprot.writeFieldStop() 499 | oprot.writeStructEnd() 500 | 501 | def validate(self): 502 | return 503 | 504 | def __repr__(self): 505 | L = ['%s=%r' % (key, value) 506 | for key, value in self.__dict__.items()] 507 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 508 | 509 | def __eq__(self, other): 510 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 511 | 512 | def __ne__(self, other): 513 | return not (self == other) 514 | all_structs.append(lookupNearby_result) 515 | lookupNearby_result.thrift_spec = ( 516 | (0, TType.STRUCT, 'success', [SpotNearbyResponse, None], None, ), # 0 517 | (1, TType.STRUCT, 'e', [TalkException, None], None, ), # 1 518 | ) 519 | fix_spec(all_structs) 520 | del all_structs 521 | 522 | -------------------------------------------------------------------------------- /akad/UniversalNotificationService.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.11.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException 10 | from thrift.protocol.TProtocol import TProtocolException 11 | from thrift.TRecursive import fix_spec 12 | 13 | import sys 14 | import logging 15 | from .ttypes import * 16 | from thrift.Thrift import TProcessor 17 | from thrift.transport import TTransport 18 | all_structs = [] 19 | 20 | 21 | class Iface(object): 22 | def notify(self, event): 23 | """ 24 | Parameters: 25 | - event 26 | """ 27 | pass 28 | 29 | 30 | class Client(Iface): 31 | def __init__(self, iprot, oprot=None): 32 | self._iprot = self._oprot = iprot 33 | if oprot is not None: 34 | self._oprot = oprot 35 | self._seqid = 0 36 | 37 | def notify(self, event): 38 | """ 39 | Parameters: 40 | - event 41 | """ 42 | self.send_notify(event) 43 | self.recv_notify() 44 | 45 | def send_notify(self, event): 46 | self._oprot.writeMessageBegin('notify', TMessageType.CALL, self._seqid) 47 | args = notify_args() 48 | args.event = event 49 | args.write(self._oprot) 50 | self._oprot.writeMessageEnd() 51 | self._oprot.trans.flush() 52 | 53 | def recv_notify(self): 54 | iprot = self._iprot 55 | (fname, mtype, rseqid) = iprot.readMessageBegin() 56 | if mtype == TMessageType.EXCEPTION: 57 | x = TApplicationException() 58 | x.read(iprot) 59 | iprot.readMessageEnd() 60 | raise x 61 | result = notify_result() 62 | result.read(iprot) 63 | iprot.readMessageEnd() 64 | if result.e is not None: 65 | raise result.e 66 | return 67 | 68 | 69 | class Processor(Iface, TProcessor): 70 | def __init__(self, handler): 71 | self._handler = handler 72 | self._processMap = {} 73 | self._processMap["notify"] = Processor.process_notify 74 | 75 | def process(self, iprot, oprot): 76 | (name, type, seqid) = iprot.readMessageBegin() 77 | if name not in self._processMap: 78 | iprot.skip(TType.STRUCT) 79 | iprot.readMessageEnd() 80 | x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) 81 | oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) 82 | x.write(oprot) 83 | oprot.writeMessageEnd() 84 | oprot.trans.flush() 85 | return 86 | else: 87 | self._processMap[name](self, seqid, iprot, oprot) 88 | return True 89 | 90 | def process_notify(self, seqid, iprot, oprot): 91 | args = notify_args() 92 | args.read(iprot) 93 | iprot.readMessageEnd() 94 | result = notify_result() 95 | try: 96 | self._handler.notify(args.event) 97 | msg_type = TMessageType.REPLY 98 | except TTransport.TTransportException: 99 | raise 100 | except UniversalNotificationServiceException as e: 101 | msg_type = TMessageType.REPLY 102 | result.e = e 103 | except TApplicationException as ex: 104 | logging.exception('TApplication exception in handler') 105 | msg_type = TMessageType.EXCEPTION 106 | result = ex 107 | except Exception: 108 | logging.exception('Unexpected exception in handler') 109 | msg_type = TMessageType.EXCEPTION 110 | result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') 111 | oprot.writeMessageBegin("notify", msg_type, seqid) 112 | result.write(oprot) 113 | oprot.writeMessageEnd() 114 | oprot.trans.flush() 115 | 116 | # HELPER FUNCTIONS AND STRUCTURES 117 | 118 | 119 | class notify_args(object): 120 | """ 121 | Attributes: 122 | - event 123 | """ 124 | 125 | 126 | def __init__(self, event=None,): 127 | self.event = event 128 | 129 | def read(self, iprot): 130 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 131 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 132 | return 133 | iprot.readStructBegin() 134 | while True: 135 | (fname, ftype, fid) = iprot.readFieldBegin() 136 | if ftype == TType.STOP: 137 | break 138 | if fid == 2: 139 | if ftype == TType.STRUCT: 140 | self.event = GlobalEvent() 141 | self.event.read(iprot) 142 | else: 143 | iprot.skip(ftype) 144 | else: 145 | iprot.skip(ftype) 146 | iprot.readFieldEnd() 147 | iprot.readStructEnd() 148 | 149 | def write(self, oprot): 150 | if oprot._fast_encode is not None and self.thrift_spec is not None: 151 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 152 | return 153 | oprot.writeStructBegin('notify_args') 154 | if self.event is not None: 155 | oprot.writeFieldBegin('event', TType.STRUCT, 2) 156 | self.event.write(oprot) 157 | oprot.writeFieldEnd() 158 | oprot.writeFieldStop() 159 | oprot.writeStructEnd() 160 | 161 | def validate(self): 162 | return 163 | 164 | def __repr__(self): 165 | L = ['%s=%r' % (key, value) 166 | for key, value in self.__dict__.items()] 167 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 168 | 169 | def __eq__(self, other): 170 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 171 | 172 | def __ne__(self, other): 173 | return not (self == other) 174 | all_structs.append(notify_args) 175 | notify_args.thrift_spec = ( 176 | None, # 0 177 | None, # 1 178 | (2, TType.STRUCT, 'event', [GlobalEvent, None], None, ), # 2 179 | ) 180 | 181 | 182 | class notify_result(object): 183 | """ 184 | Attributes: 185 | - e 186 | """ 187 | 188 | 189 | def __init__(self, e=None,): 190 | self.e = e 191 | 192 | def read(self, iprot): 193 | if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: 194 | iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) 195 | return 196 | iprot.readStructBegin() 197 | while True: 198 | (fname, ftype, fid) = iprot.readFieldBegin() 199 | if ftype == TType.STOP: 200 | break 201 | if fid == 1: 202 | if ftype == TType.STRUCT: 203 | self.e = UniversalNotificationServiceException() 204 | self.e.read(iprot) 205 | else: 206 | iprot.skip(ftype) 207 | else: 208 | iprot.skip(ftype) 209 | iprot.readFieldEnd() 210 | iprot.readStructEnd() 211 | 212 | def write(self, oprot): 213 | if oprot._fast_encode is not None and self.thrift_spec is not None: 214 | oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) 215 | return 216 | oprot.writeStructBegin('notify_result') 217 | if self.e is not None: 218 | oprot.writeFieldBegin('e', TType.STRUCT, 1) 219 | self.e.write(oprot) 220 | oprot.writeFieldEnd() 221 | oprot.writeFieldStop() 222 | oprot.writeStructEnd() 223 | 224 | def validate(self): 225 | return 226 | 227 | def __repr__(self): 228 | L = ['%s=%r' % (key, value) 229 | for key, value in self.__dict__.items()] 230 | return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) 231 | 232 | def __eq__(self, other): 233 | return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ 234 | 235 | def __ne__(self, other): 236 | return not (self == other) 237 | all_structs.append(notify_result) 238 | notify_result.thrift_spec = ( 239 | None, # 0 240 | (1, TType.STRUCT, 'e', [UniversalNotificationServiceException, None], None, ), # 1 241 | ) 242 | fix_spec(all_structs) 243 | del all_structs 244 | 245 | -------------------------------------------------------------------------------- /akad/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ['ttypes', 'constants', 'AccountSupervisorService', 'SpotService', 'BotService', 'AgeCheckService', 'BuddyManagementService', 'BuddyService', 'ChannelApplicationProvidedService', 'ChannelService', 'MessageService', 'ShopService', 'SnsAdaptorService', 'TalkService', 'UniversalNotificationService', 'CallService', 'AuthService', 'SquareService'] 2 | -------------------------------------------------------------------------------- /akad/__pycache__/AccountSupervisorService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/AccountSupervisorService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/AgeCheckService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/AgeCheckService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/AuthService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/AuthService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/BotService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/BotService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/BuddyManagementService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/BuddyManagementService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/BuddyService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/BuddyService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/CallService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/CallService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/ChannelApplicationProvidedService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/ChannelApplicationProvidedService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/ChannelService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/ChannelService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/MessageService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/MessageService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/ShopService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/ShopService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/SnsAdaptorService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/SnsAdaptorService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/SpotService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/SpotService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/SquareService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/SquareService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/TalkService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/TalkService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/UniversalNotificationService.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/UniversalNotificationService.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/constants.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/constants.cpython-36.pyc -------------------------------------------------------------------------------- /akad/__pycache__/ttypes.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wongmu/protectpy3/6c2ce5da21deb1d7952193f92aa80ff7cfd5f51c/akad/__pycache__/ttypes.cpython-36.pyc -------------------------------------------------------------------------------- /akad/constants.py: -------------------------------------------------------------------------------- 1 | # 2 | # Autogenerated by Thrift Compiler (0.11.0) 3 | # 4 | # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | # 6 | # options string: py 7 | # 8 | 9 | from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException 10 | from thrift.protocol.TProtocol import TProtocolException 11 | from thrift.TRecursive import fix_spec 12 | 13 | import sys 14 | from .ttypes import * 15 | -------------------------------------------------------------------------------- /st2__b.json: -------------------------------------------------------------------------------- 1 | { 2 | "u6b32a217fd5b8688bc264079df281162": true 3 | } --------------------------------------------------------------------------------