summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db_proxy.py4
-rw-r--r--omegle.py4
-rw-r--r--proxy.py10
3 files changed, 15 insertions, 3 deletions
diff --git a/db_proxy.py b/db_proxy.py
index f21b363..9e5273e 100644
--- a/db_proxy.py
+++ b/db_proxy.py
@@ -15,7 +15,7 @@ class DBThread(Thread):
def __init__(self,conn_str):
Thread.__init__(self)
# dbconn = ...("dbname='yvesf' user='dbuser' host='localhost' password='dbpass'")
- self.conn = pyPgSQL.PgSQL.connect(conn_str)
+ self.conn = pyPgSQL.PgSQL.connect(conn_str, client_encoding="utf-8", unicode_results=1)
self.queue = Queue.Queue()
self.running = True
def run(self):
@@ -25,13 +25,13 @@ class DBThread(Thread):
msg = self.queue.get(block=True,timeout=2)
except Queue.Empty:
continue
- logging.getLogger("").debug("Insert %s" % msg)
cur = self.conn.cursor()
sql = """INSERT INTO omegle_messages(send_time,from_ident,to_ident,message)
VALUES (CURRENT_TIMESTAMP, %s, %s, %s)"""
cur.execute(sql,(msg['from_ident'],msg['to_ident'],msg['message']))
cur.close()
self.conn.commit()
+ logging.getLogger("").debug("commit" % msg)
def add_message(self,from_ident,to_ident,message):
self.queue.put_nowait({'from_ident':from_ident,'to_ident':to_ident,'message':message})
diff --git a/omegle.py b/omegle.py
index 4f5e327..422c587 100644
--- a/omegle.py
+++ b/omegle.py
@@ -155,7 +155,7 @@ class OmegleChat(RESTClient):
try:
data_set=json.read(body.decode("utf8"))
if not data_set:
- self.logger.debug("event: no data received")
+ self.on_idle()
return
for data in data_set:
if data[0] == "typing":
@@ -179,6 +179,8 @@ class OmegleChat(RESTClient):
except json.ReadException:
self.logger.error("Json ReadException. Body: %s" % body)
+ def on_idle(self):
+ self.logger.debug("event: no data received")
def on_message(self,message):
"""To be overwritten"""
self.logger.info("<<< %s" % message)
diff --git a/proxy.py b/proxy.py
index 2d5fb60..efb4a90 100644
--- a/proxy.py
+++ b/proxy.py
@@ -15,6 +15,7 @@ class OmegleProxyChat(OmegleChat):
self.disconnect_event = disconnect_event
self.name = name
self.color = color
+ self.idlecount = 0
def c(self,str,bold=False):
if bold:
@@ -25,7 +26,16 @@ class OmegleProxyChat(OmegleChat):
def set_partner(self,partner):
self.partner = partner
+ def on_idle(self):
+ self.idlecount += 1
+ if self.idlecount > 8:
+ self.logger.info("Idle > 8. disconnect()")
+ self.disconnect()
+ else:
+ self.logger.info("Idle count %s/8" % self.idlecount)
+
def on_message(self,message):
+ self.idlecount = 0
print self.c("%s [MSG] %s: %s" %(time.strftime("%H:%M:%S"), self.name, message),bold=True)
if self.partner.is_connected:
self.partner.send(message)