-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlazers.py
38 lines (31 loc) · 1.07 KB
/
lazers.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
#requires https://pypi.python.org/pypi/websocket-client/
import websocket
import threading
import json,os,sys,getpass
from BeautifulSoup import *
from ChatExchange.chatexchange.wrapper import *
if("ChatExchangeU" in os.environ):
username=os.environ["ChatExchangeU"]
else:
print "Username: "
username=raw_input()
if("ChatExchangeP" in os.environ):
password=os.environ["ChatExchangeP"]
else:
password=getpass.getpass("Password: ")
wrap=SEChatWrapper("SE")
wrap.login(username,password)
def handlepost(data):
a=json.loads(json.loads(data)['data'])
tags=a['tags']
tagtext=" ".join(["[tag:"+t+"]" for t in tags])
b=BeautifulSoup(a['body']).find('a',{'class':'question-hyperlink'})
s="[ [LAZERS v2](https://github.com/Manishearth/ChatExchange-Scripts/blob/master/lazers.py) ] [%s](%s) %s" % (" ".join(b.contents),"http://gaming.stackexchange.com"+b['href'],tagtext)
print s
wrap.sendMessage("35",s)
ws = websocket.create_connection("ws://sockets.ny.stackexchange.com/")
ws.send("41-questions-newest")
while True:
a=ws.recv()
if(a!= None and a!= ""):
handlepost(a)