-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.py
66 lines (54 loc) · 1.51 KB
/
test2.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
import socket
import sys
import string
import matplotlib.pyplot as plt
from datetime import datetime
import urllib2
import threading
import thread
threads = []
def twitchchat():
HOST="irc.twitch.tv"
PORT=6667
NICK="him229"
IDENT="him229"
PASS= "oauth:s5gbwbjaj61bb95zfbtaxrgnyv0ssr"
REALNAME = "him229"
CHANNEL = "#starladder1"
readbuffer = ""
msg = ""
s = socket.socket()
s.connect((HOST, PORT))
s.send("PASS %s\r\n" % PASS)
s.send("NICK %s\r\n" % NICK)
s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
s.send("JOIN %s\r\n" % CHANNEL)
number_of_messages=[]
time=[]
current = datetime.now()
count = 0
while 1:
if (datetime.now() - current).seconds >= 1:
print "TIME: " + str(datetime.now() - current) + " COUNT: " + str(count) + " " + ("#"*count)
count = 0
current = datetime.now()
readbuffer=readbuffer+s.recv(1024)
temp=string.split(readbuffer, "\r\n")
index = temp[0].find(":", 1)
msg = (temp[0])[index+1:]
#print(msg)
# plt.plot(time,number_of_messages)
# plt.show()
readbuffer=temp.pop( )
for line in temp:
line=string.rstrip(line)
line=string.split(line)
if(line[0]=="PING"):
s.send("PONG %s\r\n" % line[1])
count+=1
def main():
t = threading.Thread(target=twitchchat)
threads.append(t)
t.start()
if __name__ == "__main__":
main()