def print_list(num): bottom = (num - 1) * 5 top = 1 if (num * 5 - 1) < len(arr): top = num * 5 else: top = len(arr) screen.erase() screen.addstr(0, 10, "Please enjoy using it!", curses.A_REVERSE) current = 3 screen.move(current, 0) counter = 1 for i in range(bottom, top): # print (str(counter)+".").ljust(3),arr[i].title current = current + 3 screen.addstr((str(counter) + ".").ljust(3) + " " + arr[i].title) screen.move(current, 0) process_call.read_text(str(counter)) temp_str = "" for character in arr[i].title: if ( ord(character) not in range(48, 57) and ord(character) not in range(65, 90) and ord(character) not in range(97, 122) ): temp_str += " " else: temp_str += character process_call.read_text(temp_str) counter = counter + 1
def main(): # event = screen.getch() page_reenter = False process_call.read_text("Welcome to Soundi. What would you like to search?") screen.addstr(0, 10, "Welcome to Soundi. What would you like to search?", curses.A_REVERSE) # print 'What do you want to search?' screen.move(y - 1, 0) screen.insdelln(1) screen.insdelln(2) screen.addstr(">") curses.echo() screen.refresh() init = screen.getstr(y - 1, 1, 20) # init = raw_input() init = string.replace(init, " ", "+") init_url = "https://www.youtube.com/results?search_query=" + init + "&page=" page_number = 1 while page_number < 3: url = init_url + str(page_number) html_doc = pull_webpage(url) try: soup = get_soup(html_doc) except: return crawler2(soup) page_number = page_number + 1 addition = 0 while True: if page_reenter == False: process_call.read_text("You are currently on page " + str(short_page_number + addition)) process_call.read_text("Videos on this page are ") print_list(short_page_number + addition) # page_reenter = True process_call.read_text("Press W to watch video, N for next page, P for previous page, or Q to quit") # print '\nPress N, P or Q: ' screen.move(y - 3, 0) screen.addstr("Press W to watch video, N for next page, P for previous page, or Q to quit") # typein = raw_input() typein = screen.getch() if typein == ord("q"): process_call.read_text("Thanks for using. Have a nice day") # print 'Thanks for using. Have a nice day' break elif typein == ord("w"): # and str(typein)[1] == " ": screen.move(y - 1, 0) screen.insdelln(1) screen.insdelln(2) screen.addstr(">") curses.echo() screen.refresh() event = screen.getstr(y - 1, 1) screen.insdelln(1) screen.insdelln(2) screen.move(y - 1, 0) screen.addstr(">") watch_video(short_page_number + addition, int(event)) page_reenter = True # break elif typein == ord("n") or typein == ord("N"): addition = addition + 1 elif typein == ord("p") or typein == ord("P"): if short_page_number + addition > 1: addition = addition - 1 else: print "invalid command" break curses.endwin()