# #2011-10-14 # import os import serial import threading import time import Gnuplot import MySQLdb from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler HEAD_HTML = """ SMS Log > """ END_HTML = """
idPhoneTimeDateMsgS1S21
""" class MySQLDB(): conn = MySQLdb.connect(host='localhost',db='SMS_DAKA',user='root',passwd='nosoup4u') curs = conn.cursor() def getAllSMS(self): MySQLDB.curs.execute("SELECT * FROM SMS_Log WHERE MSGStatus > 0 ORDER BY Date,Time") result = MySQLDB.curs.fetchall() return result def getSMSby(self,phoneno): MySQLDB.curs.execute("SELECT * FROM SMS_Log WHERE MSGStatus > 0 AND Phone = %s ORDER BY Date,Time",(phoneno)) result = MySQLDB.curs.fetchall() return result # The web server. Supports /graph (page containing the graph) # and static web pages class MyHandler(SimpleHTTPRequestHandler): myMySQLDB = MySQLDB() def do_GET(self): if self.path == '/smslog': return self.allsms() # Static file return SimpleHTTPRequestHandler.do_GET(self) # Generate and display the graph def allsms(self): MyHandler.myMySQLDB.getAllSMS() result = MyHandler.myMySQLDB.getSMSby('+886937893102') self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write(HEAD_HTML) for record in result: #print record self.wfile.write("%s%s%s%s%s%s%s" \ % (record[0],record[1],record[2],record[3],record[4],record[5],record[6])) self.wfile.write(END_HTML) def main(): #myMySQLDB = MySQLDB() #myMySQLDB.getAllSMS() #qdata = myMySQLDB.getSMSby('+886937893102') server = HTTPServer(('', 80), MyHandler) print 'Starting server' server.serve_forever() if __name__=='__main__': main()