def main():
"""
The entry point for the app. Called when music-scraper is typed in terminal.
Starts the GUI and starts the scraping process after the input is given
"""
curses.initscr()
if curses.COLS < 80 or curses.LINES < 5:
curses.endwin()
print('Terminal\'s dimensions are too small')
return
process = CrawlerProcess({'LOG_ENABLED': False})
def gui_input(screen):
GUI.screen = screen
curses.start_color()
GUI.screen.keypad(1)
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
GUI.high_light_text = curses.color_pair(1)
GUI.normal_text = curses.A_NORMAL
GUI.box = curses.newwin(curses.LINES, curses.COLS, 0, 0)
GUI.message = GUI.get_input()
curses.wrapper(gui_input)
s = request.quote(GUI.message)
MusicSpider.start_urls = [
"http://www.google.com/search?q=" + s,
]
process.crawl(MusicSpider)
thread = GUIThread(process, start_gui)
thread.start()
process.start()
if not GUI.gui_stopped:
if len(GUI.strings) == 0:
GUI.box.erase()
GUI.box.addstr(1, 1, "No Results Found... Try with Some other keywords.", GUI.high_light_text)
GUI.add_bottom_menus()
GUI.screen.refresh()
GUI.box.refresh()
else:
GUI.box.addstr(curses.LINES - 2, 1, "Completed Scraping !!", GUI.high_light_text)
GUI.add_bottom_menus()
GUI.screen.refresh()
GUI.box.refresh()
python类LINES的实例源码
def main(stdscr):
config_file = args.config_file if args.config_file is not None else 'zmqchat.cfg'
config = configparser.ConfigParser()
config.read(config_file)
config = config['default']
receiver = zmq.Context().instance().socket(zmq.PAIR)
receiver.bind("inproc://clientchat")
sender = zmq.Context().instance().socket(zmq.PAIR)
sender.connect("inproc://clientchat")
client = ClientChat(args.username, config['server_host'],
config['chat_port'], receiver)
client.run()
display_receiver = zmq.Context().instance().socket(zmq.PAIR)
display_receiver.bind("inproc://clientdisplay")
display_sender = zmq.Context().instance().socket(zmq.PAIR)
display_sender.connect("inproc://clientdisplay")
display = ClientDisplay(config['server_host'], config['display_port'], display_sender)
display.run()
### curses set up
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
# ensure that user input is echoed to the screen
curses.echo()
curses.curs_set(0)
window_height = curses.LINES
window_width = curses.COLS
division_line = int(window_height * 0.8)
# instaniate two pads - one for displaying received messages
# and one for showing the message the user is about to send off
top_pad = stdscr.subpad(division_line, window_width, 0, 0)
bottom_pad = stdscr.subpad(window_height - division_line, window_width, division_line, 0)
top_thread = threading.Thread(target=start_top_window, args=(top_pad, display_receiver))
top_thread.daemon = True
top_thread.start()
bottom_thread = threading.Thread(target=start_bottom_window, args=(bottom_pad, sender))
bottom_thread.daemon = True
bottom_thread.start()
top_thread.join()
bottom_thread.join()