Commit 5ccdcc1dbe4312ce7b3af74bc2144ba59312b8dd

Authored by Nadya Sutjiadi
Committed by GitHub
1 parent 99ac336e

Delete LineApi.py

Showing 1 changed file with 0 additions and 508 deletions
LINETCR/LineApi.py deleted
1   -# -*- coding: utf-8 -*-
2   -from Api import Poll, Talk, channel
3   -from lib.curve.ttypes import *
4   -import requests
5   -import shutil
6   -import json
7   -from random import randint
8   -
9   -def def_callback(str):
10   - print(str)
11   -
12   -class LINE:
13   -
14   - mid = None
15   - authToken = None
16   - cert = None
17   - channel_access_token = None
18   - token = None
19   - obs_token = None
20   - refresh_token = None
21   -
22   -
23   - def __init__(self):
24   - self.Talk = Talk()
25   - self._session = requests.session()
26   - self._headers = {'X-Line-Application': 'IOSIPAD\x097.14.0\x09iPhone_OS\x0910.12.0'}
27   -
28   - def login(self, mail=None, passwd=None, cert=None, token=None, qr=False, callback=None):
29   - if callback is None:
30   - callback = def_callback
31   - resp = self.__validate(mail,passwd,cert,token,qr)
32   - if resp == 1:
33   - self.Talk.login(mail, passwd, callback=callback)
34   - elif resp == 2:
35   - self.Talk.login(mail,passwd,cert, callback=callback)
36   - elif resp == 3:
37   - self.Talk.TokenLogin(token)
38   - elif resp == 4:
39   - self.Talk.qrLogin(callback)
40   - else:
41   - raise Exception("invalid arguments")
42   -
43   - self.authToken = self.Talk.authToken
44   - self.cert = self.Talk.cert
45   - self._headers = {
46   - 'X-Line-Application': 'IOSIPAD\x097.14.0\x09iPhone_OS\x0910.12.0',
47   - 'X-Line-Access': self.authToken,
48   - 'User-Agent': 'Line/1.4.17'
49   - }
50   -
51   - self.Poll = Poll(self.authToken)
52   - self.channel = channel.Channel(self.authToken)
53   - self.channel.login()
54   - self.mid = self.channel.mid
55   - self.channel_access_token = self.channel.channel_access_token
56   - self.token = self.channel.token
57   - self.obs_token = self.channel.obs_token
58   - self.refresh_token = self.channel.refresh_token
59   -
60   -
61   - """User"""
62   -
63   - def getProfile(self):
64   - return self.Talk.client.getProfile()
65   -
66   - def getSettings(self):
67   - return self.Talk.client.getSettings()
68   -
69   - def getUserTicket(self):
70   - return self.Talk.client.getUserTicket()
71   -
72   - def updateProfile(self, profileObject):
73   - return self.Talk.client.updateProfile(0, profileObject)
74   -
75   - def updateSettings(self, settingObject):
76   - return self.Talk.client.updateSettings(0, settingObject)
77   -
78   - def cloneContactProfile(self, mid):
79   - contact = self.getContact(mid)
80   - profile = self.getProfile()
81   - profile.displayName = contact.displayName
82   - profile.statusMessage = contact.statusMessage
83   - profile.pictureStatus = contact.pictureStatus
84   - self.updateDisplayPicture(profile.pictureStatus)
85   - return self.updateProfile(profile)
86   -
87   - def updateDisplayPicture(self, hash_id):
88   - return self.Talk.client.updateProfileAttribute(0, 8, hash_id)
89   -
90   -
91   - """Operation"""
92   -
93   - def fetchOperation(self, revision, count):
94   - return self.Poll.client.fetchOperations(revision, count)
95   -
96   - def fetchOps(self, rev, count):
97   - return self.Poll.client.fetchOps(rev, count, 0, 0)
98   -
99   - def getLastOpRevision(self):
100   - return self.Talk.client.getLastOpRevision()
101   -
102   - def stream(self):
103   - return self.Poll.stream()
104   -
105   - """Message"""
106   -
107   - def kedapkedip(self, tomid, text):
108   - M = Message()
109   - M.to = tomid
110   - t1 = "\xf4\x80\xb0\x82\xf4\x80\xb0\x82\xf4\x80\xb0\x82\xf4\x80\xb0\x82"
111   - t2 = "\xf4\x80\x82\xb3\xf4\x8f\xbf\xbf"
112   - rst = t1 + text + t2
113   - M.text = rst.replace("\n", " ")
114   - return self.Talk.client.sendMessage(0, M)
115   -
116   - def removeAllMessages(self, lastMessageId):
117   - return self.Talk.client.removeAllMessages(0,lastMessageId)
118   -
119   - def sendMessage(self, messageObject):
120   - return self.Talk.client.sendMessage(0,messageObject)
121   -
122   - def sendText(self, Tomid, text):
123   - msg = Message()
124   - msg.to = Tomid
125   - msg.text = text
126   -
127   - return self.Talk.client.sendMessage(0, msg)
128   - def post_content(self, url, data=None, files=None):
129   - return self._session.post(url, headers=self._headers, data=data, files=files)
130   -
131   - def sendImage(self, to_, path):
132   - M = Message(to=to_, text=None, contentType = 1)
133   - M.contentMetadata = None
134   - M.contentPreview = None
135   - M_id = self.Talk.client.sendMessage(0,M).id
136   - files = {
137   - 'file': open(path, 'rb'),
138   - }
139   - params = {
140   - 'name': 'media',
141   - 'oid': M_id,
142   - 'size': len(open(path, 'rb').read()),
143   - 'type': 'image',
144   - 'ver': '1.0',
145   - }
146   - data = {
147   - 'params': json.dumps(params)
148   - }
149   -
150   - r = self.post_content('https://os.line.naver.jp/talk/m/upload.nhn', data=data, files=files)
151   - print r
152   - if r.status_code != 201:
153   - raise Exception('Upload image failure.')
154   - return True
155   -
156   - def sendImageWithURL(self, to_, url):
157   - """Send a image with given image url
158   -
159   - :param url: image url to send
160   - """
161   - path = 'pythonLine.data'
162   -
163   - r = requests.get(url, stream=True)
164   - if r.status_code == 200:
165   - with open(path, 'w') as f:
166   - shutil.copyfileobj(r.raw, f)
167   - else:
168   - raise Exception('Download image failure.')
169   -
170   - try:
171   - self.sendImage(to_, path)
172   - except Exception as e:
173   - raise e
174   -
175   - def sendAudioWithURL(self, to_, url):
176   - path = 'pythonLiness.data'
177   - r = requests.get(url, stream=True)
178   - if r.status_code == 200:
179   - with open(path, 'w') as f:
180   - shutil.copyfileobj(r.raw, f)
181   - else:
182   - raise Exception('Download Audio failure.')
183   - try:
184   - self.sendAudio(to_, path)
185   - except Exception as e:
186   - raise e
187   - def sendAudio(self, to_, path):
188   - M = Message(to=to_,contentType = 3)
189   - M.contentMetadata = None
190   - M.contentPreview = None
191   - M_id = self.Talk.client.sendMessage(0,M).id
192   - files = {
193   - 'file': open(path, 'rb'),
194   - }
195   - params = {
196   - 'name': 'media',
197   - 'oid': M_id,
198   - 'size': len(open(path, 'rb').read()),
199   - 'type': 'audio',
200   - 'ver': '1.0',
201   - }
202   - data = {
203   - 'params': json.dumps(params)
204   - }
205   - r = self.post_content('https://os.line.naver.jp/talk/m/upload.nhn', data=data, files=files)
206   - if r.status_code != 201:
207   - raise Exception('Upload image failure.')
208   - return True
209   - def sendVideo(self, to_, path):
210   - M = Message(to=to_,contentType = 2)
211   - M.contentMetadata = {
212   - 'VIDLEN' : '0',
213   - 'DURATION' : '0'
214   - }
215   - M.contentPreview = None
216   - M_id = self.Talk.client.sendMessage(0,M).id
217   - files = {
218   - 'file': open(path, 'rb'),
219   - }
220   - params = {
221   - 'name': 'media',
222   - 'oid': M_id,
223   - 'size': len(open(path, 'rb').read()),
224   - 'type': 'video',
225   - 'ver': '1.0',
226   - }
227   - data = {
228   - 'params': json.dumps(params)
229   - }
230   - r = self.post_content('https://os.line.naver.jp/talk/m/upload.nhn', data=data, files=files)
231   - if r.status_code != 201:
232   - raise Exception('Upload image failure.')
233   - return True
234   -
235   - def sendVideoWithURL(self, to_, url):
236   - path = 'pythonLines.data'
237   - r = requests.get(url, stream=True)
238   - if r.status_code == 200:
239   - with open(path, 'w') as f:
240   - shutil.copyfileobj(r.raw, f)
241   - else:
242   - raise Exception('Download Audio failure.')
243   - try:
244   - self.sendVideo(to_, path)
245   - except Exception as e:
246   - raise e
247   -
248   - def sendGif(self, to_, path):
249   - M = Message(to=to_,contentType = 1)
250   - M.contentMetadata = {
251   - 'VIDLEN' : '0',
252   - 'DURATION' : '0'
253   - }
254   - M.contentPreview = None
255   - M_id = self.Talk.client.sendMessage(0,M).id
256   - files = {
257   - 'file': open(path, 'rb'),
258   - }
259   - params = {
260   - 'name': 'media',
261   - 'oid': M_id,
262   - 'size': len(open(path, 'rb').read()),
263   - 'type': 'image',
264   - 'ver': '1.0',
265   - }
266   - data = {
267   - 'params': json.dumps(params)
268   - }
269   - r = self.post_content('https://os.line.naver.jp/talk/m/upload.nhn', data=data, files=files)
270   - if r.status_code != 201:
271   - raise Exception('Upload Gif failure.')
272   - return True
273   -
274   - def sendGifWithURL(self, to_, url):
275   - path = 'pythonLiness.data'
276   - r = requests.get(url, stream=True)
277   - if r.status_code == 200:
278   - with open(path, 'w') as f:
279   - shutil.copyfileobj(r.raw, f)
280   - else:
281   - raise Exception('Download Gif failure.')
282   - try:
283   - self.sendGif(to_, path)
284   - except Exception as e:
285   - raise e
286   -
287   - def sendEvent(self, messageObject):
288   - return self.Talk.client.sendEvent(0, messageObject)
289   -
290   - def sendChatChecked(self, mid, lastMessageId):
291   - return self.Talk.client.sendChatChecked(0, mid, lastMessageId)
292   -
293   - def getMessageBoxCompactWrapUp(self, mid):
294   - return self.Talk.client.getMessageBoxCompactWrapUp(mid)
295   -
296   - def getMessageBoxCompactWrapUpList(self, start, messageBox):
297   - return self.Talk.client.getMessageBoxCompactWrapUpList(start, messageBox)
298   -
299   - def getRecentMessages(self, messageBox, count):
300   - return self.Talk.client.getRecentMessages(messageBox.id, count)
301   -
302   - def getMessageBox(self, channelId, messageboxId, lastMessagesCount):
303   - return self.Talk.client.getMessageBox(channelId, messageboxId, lastMessagesCount)
304   -
305   - def getMessageBoxList(self, channelId, lastMessagesCount):
306   - return self.Talk.client.getMessageBoxList(channelId, lastMessagesCount)
307   -
308   - def getMessageBoxListByStatus(self, channelId, lastMessagesCount, status):
309   - return self.Talk.client.getMessageBoxListByStatus(channelId, lastMessagesCount, status)
310   -
311   - def getMessageBoxWrapUp(self, mid):
312   - return self.Talk.client.getMessageBoxWrapUp(mid)
313   -
314   - def getMessageBoxWrapUpList(self, start, messageBoxCount):
315   - return self.Talk.client.getMessageBoxWrapUpList(start, messageBoxCount)
316   -
317   - def getCover(self,mid):
318   - h = self.getHome(mid)
319   - objId = h["result"]["homeInfo"]["objectId"]
320   - return "http://dl.profile.line-cdn.net/myhome/c/download.nhn?userid=" + mid+ "&oid=" + objId
321   -
322   - """Contact"""
323   -
324   -
325   - def blockContact(self, mid):
326   - return self.Talk.client.blockContact(0, mid)
327   -
328   -
329   - def unblockContact(self, mid):
330   - return self.Talk.client.unblockContact(0, mid)
331   -
332   -
333   - def findAndAddContactsByMid(self, mid):
334   - return self.Talk.client.findAndAddContactsByMid(0, mid)
335   -
336   -
337   - def findAndAddContactsByMids(self, midlist):
338   - for i in midlist:
339   - self.Talk.client.findAndAddContactsByMid(0, i)
340   -
341   - def findAndAddContactsByUserid(self, userid):
342   - return self.Talk.client.findAndAddContactsByUserid(0, userid)
343   -
344   - def findContactsByUserid(self, userid):
345   - return self.Talk.client.findContactByUserid(userid)
346   -
347   - def findContactByTicket(self, ticketId):
348   - return self.Talk.client.findContactByUserTicket(ticketId)
349   -
350   - def getAllContactIds(self):
351   - return self.Talk.client.getAllContactIds()
352   -
353   - def getBlockedContactIds(self):
354   - return self.Talk.client.getBlockedContactIds()
355   -
356   - def getContact(self, mid):
357   - return self.Talk.client.getContact(mid)
358   -
359   - def getContacts(self, midlist):
360   - return self.Talk.client.getContacts(midlist)
361   -
362   - def getFavoriteMids(self):
363   - return self.Talk.client.getFavoriteMids()
364   -
365   - def getHiddenContactMids(self):
366   - return self.Talk.client.getHiddenContactMids()
367   -
368   - def CloneContactProfile(self, mid):
369   - contact = self.getContact(mid)
370   - profile = self.getProfile()
371   - profile.displayName = contact.displayName
372   - profile.statusMessage = contact.statusMessage
373   - profile.pictureStatus = contact.pictureStatus
374   - self.updateDisplayPicture(profile.pictureStatus)
375   - return self.updateProfile(profile)
376   -
377   - def updateDisplayPicture(self, hash_id):
378   - return self.Talk.client.updateProfileAttribute(0, 8, hash_id)
379   -
380   -
381   - """Group"""
382   -
383   - def findGroupByTicket(self, ticketId):
384   - return self.Talk.client.findGroupByTicket(ticketId)
385   -
386   - def acceptGroupInvitation(self, groupId):
387   - return self.Talk.client.acceptGroupInvitation(0, groupId)
388   -
389   - def acceptGroupInvitationByTicket(self, groupId, ticketId):
390   - return self.Talk.client.acceptGroupInvitationByTicket(0, groupId, ticketId)
391   -
392   - def cancelGroupInvitation(self, groupId, contactIds):
393   - return self.Talk.client.cancelGroupInvitation(0, groupId, contactIds)
394   -
395   - def createGroup(self, name, midlist):
396   - return self.Talk.client.createGroup(0, name, midlist)
397   -
398   - def getGroup(self, groupId):
399   - return self.Talk.client.getGroup(groupId)
400   -
401   - def getGroups(self, groupIds):
402   - return self.Talk.client.getGroups(groupIds)
403   -
404   - def getGroupIdsInvited(self):
405   - return self.Talk.client.getGroupIdsInvited()
406   -
407   - def getGroupIdsJoined(self):
408   - return self.Talk.client.getGroupIdsJoined()
409   -
410   - def inviteIntoGroup(self, groupId, midlist):
411   - return self.Talk.client.inviteIntoGroup(0, groupId, midlist)
412   -
413   - def kickoutFromGroup(self, groupId, midlist):
414   - return self.Talk.client.kickoutFromGroup(0, groupId, midlist)
415   -
416   - def leaveGroup(self, groupId):
417   - return self.Talk.client.leaveGroup(0, groupId)
418   -
419   - def rejectGroupInvitation(self, groupId):
420   - return self.Talk.client.rejectGroupInvitation(0, groupId)
421   -
422   - def reissueGroupTicket(self, groupId):
423   - return self.Talk.client.reissueGroupTicket(groupId)
424   -
425   - def updateGroup(self, groupObject):
426   - return self.Talk.client.updateGroup(0, groupObject)
427   -
428   - def findGroupByTicket(self,ticketId):
429   - return self.Talk.client.findGroupByTicket(0,ticketId)
430   -
431   - """Room"""
432   -
433   - def createRoom(self, midlist):
434   - return self.Talk.client.createRoom(0, midlist)
435   -
436   - def getRoom(self, roomId):
437   - return self.Talk.client.getRoom(roomId)
438   -
439   - def inviteIntoRoom(self, roomId, midlist):
440   - return self.Talk.client.inviteIntoRoom(0, roomId, midlist)
441   -
442   - def leaveRoom(self, roomId):
443   - return self.Talk.client.leaveRoom(0, roomId)
444   -
445   - """TIMELINE"""
446   -
447   - def new_post(self, text):
448   - return self.channel.new_post(text)
449   -
450   - def like(self, mid, postid, likeType=1001):
451   - return self.channel.like(mid, postid, likeType)
452   -
453   - def comment(self, mid, postid, text):
454   - return self.channel.comment(mid, postid, text)
455   -
456   - def activity(self, limit=20):
457   - return self.channel.activity(limit)
458   -
459   - def getAlbum(self, gid):
460   -
461   - return self.channel.getAlbum(gid)
462   - def changeAlbumName(self, gid, name, albumId):
463   - return self.channel.changeAlbumName(gid, name, albumId)
464   -
465   - def deleteAlbum(self, gid, albumId):
466   - return self.channel.deleteAlbum(gid,albumId)
467   -
468   - def getNote(self,gid, commentLimit, likeLimit):
469   - return self.channel.getNote(gid, commentLimit, likeLimit)
470   -
471   - def getDetail(self,mid):
472   - return self.channel.getDetail(mid)
473   -
474   - def getHome(self,mid):
475   - return self.channel.getHome(mid)
476   -
477   - def createAlbum(self, gid, name):
478   - return self.channel.createAlbum(gid,name)
479   -
480   - def createAlbum2(self, gid, name, path):
481   - return self.channel.createAlbum(gid, name, path, oid)
482   -
483   -
484   - def __validate(self, mail, passwd, cert, token, qr):
485   - if mail is not None and passwd is not None and cert is None:
486   - return 1
487   - elif mail is not None and passwd is not None and cert is not None:
488   - return 2
489   - elif token is not None:
490   - return 3
491   - elif qr is True:
492   - return 4
493   - else:
494   - return 5
495   -
496   - def loginResult(self, callback=True):
497   - if callback is True:
498   - callback = def_callback
499   -
500   - prof = self.getProfile()
501   -
502   - print("===============[Chucky_Bot]================")
503   - print(" Thanks for TCR and my friend")
504   - print("===============[© By_Nadya]================")
505   - print("mid -> " + prof.mid)
506   - print("name -> " + prof.displayName)
507   - print("authToken -> " + self.authToken)
508   - print("cert -> " + self.cert if self.cert is not None else "")