def rawRegionInterface(request, row, rowlimit, col, collimit, msg): row = int(row) rowlimit = int(rowlimit) col = int(col) collimit = int(collimit) responseMsg = "Running..." try: sock = board.get_connection() board.clear_panel(sock, 1) board.write_region_wrap(sock, 0, row, col, msg, rowlimit, collimit) responseMsg = "Wrote " + msg board.close_connection(sock) except: responseMsg = "Err" finally: board.close_connection(sock) return HttpResponse(content=responseMsg)
def time_stamp(request): secs = time() lastTime = strftime("%a, %d %b %Y %H:%M:%S", localtime(secs) ) timeLen = len('Thu, 28 Jun 2001 14:17:15') try: sock = board.get_connection() #TODO: calculate when clearing is necessary (e.g. when formatted string length changes from prev) #board.write_to_board(sock, 4, 0, 0, " ") board.write_to_board(sock, 4, 0, 0, lastTime) msg = "Hi Teke" board.write_to_board(sock, 5, 11, 32 - len(msg), msg) msg = "Hi ROBERT!" board.write_to_board(sock, 5, 9, 32 - len(msg), msg) board.close_connection(sock) except: board.close_connection(sock) return HttpResponse(content="Written")
def updateAnnouncementBoard(foo, bar): logger.warn("updateAnnouncementBoard called") try: sock = board.get_connection() board.clear_panel(sock, 3) board.write_to_board(sock, 3, 0, 0, " - - - - - - - - - - - - - - - - Announcements - - - - - - - - - - - - - - - - ") curRowNum = 1 announcements = list(Announcement.objects.order_by('-creation_date')) for announcement in announcements: color = chr(29) if announcement.priority == 'M': color = chr(31) elif announcement.priority == 'H': color = chr(30) row = " " + announcement.announcement_text while len(row) < 66: # add some padding spaces row = row + " " row = row + " " + announcement.creation_date.strftime("%a %I:%M%p") while len(row) < 81: row = row + " " board.write_to_board(sock, 3, curRowNum, 0, str(color + row)) curRowNum += 1 except: print "Unexpected error:", sys.exc_info()[0] finally: board.close_connection(sock) return 0
def clear_board(row, **kwargs): try: sock = board.get_connection() board.clear_panel(sock, 0) board.clear_panel(sock, 1) board.close_connection(sock) except: board.close_connection(sock) return False return True
def write_to_board(row, col, msg, **kwargs): try: sock = board.get_connection() board.write_split(sock, 0, row, col, [ msg ]) board.close_connection(sock) except: board.close_connection(sock) # print "Unexpected error:", sys.exc_info()[0] return False return True
def clear_board(request): try: sock = board.get_connection() board.clear_board(sock) board.close_connection(sock) except: board.close_connection(sock) return HttpResponse(content="Cleared")
def rawInterface(request, row, col, msg): row = int(row) col = int(col) try: sock = board.get_connection() board.write_split(sock, 0, row, col, [ msg ]) #board.write_to_board(sock, 0, row, col, msg) board.close_connection(sock) except: board.close_connection(sock) return HttpResponse(content="Wrote " + msg)
def twitter_panel(request): try: sock = board.get_connection() # tb = twitter_board.TwitterBoard() # board.clear_panel(sock, 2) board.write_to_board(sock, 2, 0, 0, "*************** Tweets ********************************************************") curRowNum = 1 for row in twitter.Twitter().getNewTweets(11, 79): board.write_to_board(sock, 2, curRowNum, 0, str(row + ' ')) curRowNum += 1 except: print "Unexpected error:", sys.exc_info()[0] finally: board.close_connection(sock) return HttpResponse(content="Twitter Board Updated")
def board_test(request): sock = board.get_connection() #board.write_to_board(sock, 0, 5, 15, "You have no chance to survive") #board.write_to_board(sock, 0, 6, 20, "Make your time") # board.write_to_board(sock, 0, 7, 20, "Boom zig") # board.write_to_board(sock, 0, 8, 30, "Boom zig") # board.write_to_board(sock, 0, 9, 40, "Boom zig") # board.write_to_board(sock, 0, 10, 50, "Boom zig") #board.write_split(sock, 0, 2, 30, [ "That's gotta be rough", ]) #board.write_split(sock, 0, 3, 40, [ chr(30) + "Sorry, technical difficulties", ]) #board.write_split(sock, 1, 0, 10, chr(30) + "Vertical Text!") #chr(30) + board.write_split(sock, 1, 0, 0, [ "Demerit Board: ", ]) demerits = [ ("@DonohuePatrickE", 6,), ("@IdeaFood", 1,), ("@donmball", 0,), (" ", ' ',), ] rowIdx = 1 for d in demerits: board.write_split(sock, 1, rowIdx, 0, [ " ", ]) board.write_split(sock, 1, rowIdx, 2, [ chr(31) + d[0], ]) # colorStr = '' # if d[1] > 1: # colorStr = chr(31) # if d[1] >= 3: # colorStr = chr(30) board.write_split(sock, 1, rowIdx, 25, [ chr(30) + str(d[1]) + " ", ]) rowIdx += 1 board.close_connection(sock) #updateTwitterBoard(1, 2) return HttpResponse(content="Okay")
def calibrate_displays(request): try: sock = board.get_connection() board.calibrate(sock, 0) board.calibrate(sock, 1) board.calibrate(sock, 2) board.calibrate(sock, 3) board.calibrate(sock, 4) board.calibrate(sock, 5) #board.calibrate(sock, 6) board.close_connection(sock) except: board.close_connection(sock) return HttpResponse(content="Calibrated")
def info_panel(request): try: sock = board.get_connection() # tb = twitter_board.TwitterBoard() board.clear_panel(sock, 4) board.write_to_board(sock, 4, 0, 1, strftime("%a, %d %B %I:%M%p", localtime(time()))) curRowNum = 1 for row in weather.Weather().getCurrentWeather(): print row board.write_to_board(sock, 4, curRowNum, 3, str(row)) curRowNum += 1 except: print "Unexpected error:", sys.exc_info()[0] finally: board.close_connection(sock) return HttpResponse(content="Info Board Updated")
def updateInfoBoard(foo, bar): logger.warn("updateInfoBoard called"); weatherRows = weather.Weather().getCurrentWeather() try: sock = board.get_connection() board.clear_panel(sock, 4) board.write_to_board(sock, 4, 0, 1, strftime("%a, %d %B %I:%M%p", localtime(time()))) curRowNum = 1 for row in weatherRows: print row board.write_to_board(sock, 4, curRowNum, 3, str(row)) curRowNum += 1 except: print "Unexpected error:", sys.exc_info()[0] finally: board.close_connection(sock) return 0
def updateTwitterBoard(foo, bar): logger.warning("updateTwitterBoard called") twitterRows = twitter.Twitter().getNewTweets(11, 79) if len(twitterRows) > 0: try: sock = board.get_connection() board.clear_panel(sock, 2) board.write_to_board(sock, 2, 0, 0, "*************** Tweets ********************************************************") curRowNum = 1 for row in twitterRows: board.write_to_board(sock, 2, curRowNum, 0, str(row + ' ')) curRowNum += 1 except: print "Unexpected error:", sys.exc_info()[0] finally: board.close_connection(sock) return 0
def updateTwitterBoard(foo, bar): logger.warning("updateTwitterBoard called") twitterRows = twitter.Twitter().getNewTweets(11, 79) if len(twitterRows) > 0: try: sock = board.get_connection() # board.clear_panel(sock, 2) board.write_to_board(sock, 2, 0, 0, "*************** Tweets ********************************************************") curRowNum = 1 for row in twitterRows: board.write_to_board(sock, 2, curRowNum, 0, str(row + ' ')) curRowNum += 1 except: print "Unexpected error:", sys.exc_info()[0] finally: board.close_connection(sock) return 0
def updateNetworkStatus(foo=0, bar=0): #logger.warning("updateNetworkStatus called") try: sock = None servers = [ dict(name= 'twitter.com' ), dict(name= 'google.com' ), dict(name= 'cocomsp.com' ), dict(name= 'github.com' ), dict(name= 'reddit.com' ), dict(name= 'facebook.com' ), # dict(name= 'expertocrede.com' ), ] import subprocess import re def do_ping(addr): try: cmdStr = "/bin/ping -c 1 -w 1 %s " % addr p = subprocess.Popen(cmdStr, shell=True, stdout=subprocess.PIPE) p.wait() line = p.stdout.read() match = re.search('(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+) ms', line) if match is None: return -1 return match.group(1) except Exception, e: print 'foo ' + str(e) return -1 for s in servers: s['delay'] = do_ping(s['name']) red = chr(30) green = chr(29) amber = chr(31) sock = board.get_connection() curRowNum = 0 for s in servers: msg = s['name'] + ": " board.write_line_split(sock, 0, curRowNum, 0, msg ) delayNum = float(s['delay']) colorStr = green if delayNum > 250: colorStr = red elif delayNum > 125: colorStr = amber elif delayNum < 0: colorStr = red s['delay'] = "DOWN" delayStr = colorStr + str(s['delay']) + " " board.write_line_split(sock, 0, curRowNum, 20, delayStr ) curRowNum += 1 board.write_line_split(sock, 0, curRowNum, 0, " " )