-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
141 lines (90 loc) · 3.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import requests
import json
from collections import dequencv
neid=0
cid = 0
def getCID(sessionID):
global neid,cid
eid = 0
streamURL = 'https://www.irccloud.com/chat/stream'
cookies = {'session':sessionID}
stream = requests.get('https://www.irccloud.com/chat/stream', cookies = cookies,stream=True)
for line in stream.iter_lines():
message = json.loads(line.decode('utf-8'))
if message['type']=='stat_user':
bufferID = message['last_selected_bid']
elif message['type']== 'oob_include':
url = message['url']
daBacklog = requests.get('https://www.irccloud.com'+message['url'],cookies=cookies)
daBackloginJSON = daBacklog.json()
break
file1 = open("deBacklog.txt","w")
file1.write(daBacklog.text)
file1.close()
for event in daBackloginJSON:
if event['type']=='makeserver':
cid = event['cid']
elif event['bid']==bufferID and event['type']=='buffer_msg':
bid = event['bid']
eid = event['eid']
for event in daBackloginJSON:
if event['eid'] == eid and event['type'] == 'buffer_msg': #condition for printing the unread message
msg = event['msg']
if neid!=eid:
neid=eid
print(msg,bufferID)
getCID(sessionID)
def getToken():
r = requests.post("https://www.irccloud.com/chat/auth-formtoken").json()
token = r['token']
return token
def getSessionID(email,password,token):
loginURL = "https://www.irccloud.com/chat/login"
data = {
'email': email,
'password': password,
'token':token
}
headers = {
'content-type':'application/x-www-form-urlencoded',
'x-auth-formtoken':token
}
auth = requests.post(loginURL,data = data, headers = headers).json()
if auth['success'] == True:
session = auth['session']
return session
else:
return False
def sendMessage(uname,session,cid,msg):
dataSendMessage = {
"msg":"/msg "+uname+" "+msg,
"to":"*",
"cid":cid,
"session":session
}
sendMsgURL = "https://www.irccloud.com/chat/say"
cookies = {'session':session}
sendMsg = requests.post(sendMsgURL,data = dataSendMessage, cookies = cookies).json()
if sendMsg['success'] == True:
return True
else:
return sendMsg
def auth():
token = getToken()
email = input("Enter email id and password to log in :")
password = input()
sessionID = getSessionID(email,password,token)
return sessionID
def main():
sessionID = auth()
global cid
getCID(sessionID)
if sessionID!=False:
msg = input("Enter the message : ")
uname = input("Enter the nick of the receiver : ")
response = sendMessage(uname,sessionID,cid,msg)
if response!=True:
print(response)
else:
print("Authentication Failed")
main()