title: How to perform raster scan of the curses screen to the file in python
body: <p>I am creating one call flow based on the content from one input file to the curses screen (window). I could successfully create the call flow to the curses screen. I would like to perform the raster scan of the curses screen and to write into the output file which i am giving.  Could you please help in this regards. 
  Please find the python code snippet below.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#! /usr/bin/python2.6
  import sys, getopt
  import curses
  from curses import wrapper
  
  def call(stdscr):
          inputFile = ''
          try:
              opts, args = getopt.getopt(sys.argv[1:],"hi:o:",["ifile=","ofile="])
          except getopt.GetoptError:
              print 'my_box.py -i &lt;inputFile_With_Path&gt;'
              sys.exit(2)
          for opt, arg in opts:
              if opt == '-h':
                  print 'my_box.py -i &lt;inputFile_With_Path&gt;'
                  sys.exit()
              elif opt == '-i':
                  inputFile = arg
  
          output_file = open("/home/vparamasivam/Training/Python/n.txt", "wb+")
          my_Dict = { }
          cur_y = 3
          cur_sbc = 30
          cur_EP1 = 10
          cur_uas = 50
          cur_UAC = 10
          sbc_cur = 24
          cur_poi = 2
          RED_TEXT = 1
          endPointCount = 0
          callCount = 0
          count = 0
          if not curses.has_colors():
              curses.endwin()
              print "no colors"
              sys.exit()
          else:
              curses.start_color()
  
          curses.init_pair(RED_TEXT, curses.COLOR_RED, curses.COLOR_BLACK)
  
          window = curses.newwin(1500, 1500, 0, 0)
  
          fo = open(inputFile, "r");
  
          print "Name of the file :", fo.name
          print "File closed or not :", fo.closed
  
  
          window.addstr(1, 29, "SBC", curses.color_pair(RED_TEXT))
          window.vline(cur_y, cur_sbc, '|', 1500)
          for line in fo:
              if (line.find("Receive Msg From:") != -1) :
                  ip, l, p, s, msg = line.split(',')
                  ipc, ip = ip.rsplit(' ',1)
                  ip, port = ip.split('/')
                  ipPort = ip + ':' + port
                  s, msg, req_uri = msg.split(' ', 2)
                  print "\n SIP message : ", msg, ' '
                  print "Received from IP : ", ipPort, ' '
                  callCount += 1
                  if not my_Dict.has_key(ipPort):
                      endPointCount +=1
                      if endPointCount == 1:
                          window.addstr(1, 4, ipPort, curses.color_pair(RED_TEXT))
                          window.vline(cur_y, cur_EP1, '|', 1500)
                          new = {ipPort:cur_EP1}
                          my_Dict.update(new)
                          cur_EP1 += 7
                          cur_poi += 1
                          window.addstr(cur_poi, cur_EP1, msg, curses.color_pair(RED_TEXT))
                          cur_poi += 1
                          cur_EP1 -= 6
                          window.hline(cur_poi, cur_EP1, '-', 18)
                          cur_EP1 += 18
                          window.addstr(cur_poi, cur_EP1, '&gt;')
                      else :
                          sbc_cur +=20
                          if endPointCount != 2:
                              cur_uas +=20
                          window.addstr(1, sbc_cur, ipPort, curses.color_pair(RED_TEXT))
                          window.vline(cur_y, cur_uas, '|', 1500)
                          new = {ipPort:cur_uas}
                          my_Dict.update(new)
                          cur_poi +=2
                          cur_uas -=13
                          window.addstr(cur_poi, cur_uas, msg, curses.color_pair(RED_TEXT))
                          cur_uas +=13
                          cur_poi +=1
                          cur_sbc +=1
                          window.addstr(cur_poi, cur_sbc, '&lt;')
                          count = cur_uas - cur_sbc - 1
                          cur_sbc +=1
                          window.hline(cur_poi, cur_sbc, '-', count)
                          cur_sbc -=2
                  else :
                      ep = my_Dict[ipPort]
                      if ep == cur_UAC :
                          ep += 7
                          window.addstr(cur_poi, ep, msg, curses.color_pair(RED_TEXT))
                          cur_poi += 1
                          ep -= 6
                          window.hline(cur_poi, ep, '-', 18)
                          ep += 18
                          window.addstr(cur_poi, ep, '&gt;')
                          cur_poi += 1
                      else :
                          cur_poi +=1
                          ep -=13
                          window.addstr(cur_poi, ep, msg, curses.color_pair(RED_TEXT))
                          ep +=13
                          cur_poi +=1
                          cur_sbc +=1
                          window.addstr(cur_poi, cur_sbc, '&lt;')
                          count = ep - cur_sbc - 1
                          cur_sbc +=1
                          window.hline(cur_poi, cur_sbc, '-', count)
                          cur_sbc -=2
  
              elif (line.find("Send Msg to:") != -1) :
                  ip, l, p, s, msg = line.split(',')
                  s, msg, status = msg.split(' ', 2)
                  ipc, ip = ip.rsplit(' ',1)
                  ip, port = ip.split('/')
                  ipPort = ip + ':' + port
                  print "\n SIP message : ", msg, ' '
                  print "Sent to IP : ", ipPort, ' '
                  callCount += 1
                  if not my_Dict.has_key(ipPort):
                      endPointCount +=1
                      if endPointCount == 1:
                          window.addstr(1, 9, ipPort, curses.color_pair(RED_TEXT))
                          window.vline(cur_y, cur_EP1, '|', 1500)
                          new = {ipPort:cur_EP1}
                          my_Dict.update(new)
                          cur_poi +=1
                          cur_EP1 +=7
                          window.addstr(cur_poi, cur_EP1, msg, curses.color_pair(RED_TEXT))
                          cur_poi +=1
                          cur_EP1 -=6
                          window.addstr(cur_poi, cur_EP1, '&lt;')
                          cur_EP1 +=1
                          window.hline(cur_poi, cur_EP1, '-', 18)
                      else :
                          sbc_cur +=20
                          if endPointCount != 2:
                              cur_uas +=20
                          window.addstr(1, sbc_cur, ipPort, curses.color_pair(RED_TEXT))
                          window.vline(cur_y, cur_uas, '|', 1500)
                          new = {ipPort:cur_uas}
                          my_Dict.update(new)
                          cur_poi +=1
                          cur_uas -=13
                          window.addstr(cur_poi, cur_uas, msg, curses.color_pair(RED_TEXT))
                          cur_uas +=13
                          cur_poi +=1
                          cur_sbc +=1
                          count = cur_uas - cur_sbc - 1
                          window.hline(cur_poi, cur_sbc, '-', count)
                          cur_uas -=1
                          window.addstr(cur_poi, cur_uas, '&gt;')
                          cur_uas +=1
                          cur_sbc -=1
                  else :
                      ep = my_Dict[ipPort]
                      if ep == cur_UAC :
                          cur_poi +=1
                          ep +=7
                          window.addstr(cur_poi, ep, msg, curses.color_pair(RED_TEXT))
                          cur_poi += 1
                          ep -= 6
                          window.addstr(cur_poi, ep, '&lt;')
                          ep +=1
                          window.hline(cur_poi, ep, '-', 18)
                          cur_poi += 1
                      else :
                          cur_poi +=1
                          ep -=13
                          window.addstr(cur_poi, ep, msg, curses.color_pair(RED_TEXT))
                          ep +=13
                          cur_poi +=1
                          cur_sbc +=1
                          count = ep - cur_sbc - 1
                          window.hline(cur_poi, cur_sbc, '-', count)
                          ep -=1
                          window.addstr(cur_poi, ep, '&gt;')
                          cur_sbc -=1
  
          inchar = window.getch()
    
          ''' Place where i want to perfomr raster scan of the curses screen '''
  
  def main(stdscr):
  
      call(stdscr)
  
  wrapper(main)</code></pre>
  </div>
  </div>
  </p>