-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal_ticker.py
93 lines (81 loc) · 3.28 KB
/
terminal_ticker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# standard library
import curses
import sqlite3
import threading
# term ticker
import commands
import tools.thread_manager as thread_manager
import tools.twitter_tools as twitter_tools
import ui
def start_terminal_ticker(stdscr):
# Set up windows
window_dict = ui.set_window_parameters()
input_window = window_dict['input']
for name, window in window_dict.items():
if name is not 'input':
window.border()
window.addstr(0, 0, name)
window.refresh()
window.scrollok(True)
# Get dict stuff
commands_dict = commands.set_commands_dict()
connection = sqlite3.connect('term_ticker.db',
check_same_thread=False)
twitter_keys = twitter_tools.read_keys()
# Create a global dict to pass stuff around the threads
# and to pass the lock/queues when completing commands
termticker_dict = {
'connection' : connection,
'input_window' : input_window,
'lock' : threading.Lock(),
'twitter_keys' : twitter_keys,
'window_dict' : window_dict
}
# Create threads
term_threads = thread_manager.TermTickerThreadManager(termticker_dict)
threads = ['twitter_thread', 'rss_thread']
for thread in threads:
term_threads.add_thread(thread)
application_running = True
while application_running:
try:
curses.noecho()
input_window.keypad(1)
input_edit = curses.textpad.Textbox(input_window)
input_edit.edit()
message = input_edit.gather().strip()
window_key, command_key, args = commands.parse_input_text(message)
if window_key in window_dict:
if command_key in commands_dict[window_key]:
commands_dict[window_key][command_key](termticker_dict,
window_key,
args)
elif command_key in term_threads.commands_dict:
term_threads.commands_dict[command_key](window_key,
command_key,
args)
else:
commands.print_warning(input_window,
'Command does not exist. \
Press any key to continue')
elif window_key == 'all' and command_key == 'quit':
application_running = False
else:
commands.print_warning(input_window,
'Window does not exist. \
Press any key to continue')
# elif window_key == 'all':
# all_commands[command_key](args)
input_window.clear()
except KeyboardInterrupt:
return
curses.endwin()
connection.close()
def main(stdscr):
curses.curs_set(0)
start_terminal_ticker(curses.initscr())
if __name__ == '__main__':
# this needs to run first in case this is the first use,
# and user needs to use browser to get access keys
twitter_tools.read_keys()
curses.wrapper(main)