MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Reddit_Search.py:60–212  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58
59
60def main():
61 while True:
62 # reddit_praw_parameters = settings.get_dict()
63 reddit_praw_parameters = {'client_id' : settings['client_id'], 'client_secret':settings['client_secret'],
64 'user_agent' : settings['user_agent'], 'username' : settings['username'], 'password': settings['password']}
65 try:
66 reddit = praw.Reddit(**reddit_praw_parameters)
67 break
68 except Exception as e:
69 sg.popup('Problem with your settings file', e)
70 if not settings_window():
71 sg.popup_error('Must set settings before can continue')
72 exit()
73
74 # Read your Reddit PRAW configuration from a json file
75 # try:
76 # with open(path.join(path.dirname(__file__), r'praw.cfg'), 'r') as f:
77 # reddit_praw_parameters = load(f)
78 # except:
79 # sg.popup_error('Failed loading the Reddit API login credential file.', 'The File should be named:', path.join(path.dirname(__file__), r'praw.cfg'))
80 # exit()
81 # To use the Reddit APIs you will need to sign up by visiting this site:
82 # https://www.reddit.com/prefs/apps/
83 # You will receive a client_id and client_secret string that you can
84 # enter along with your normal Reddit ID & Password and save into a file named praw.cfg
85
86 sub_names = ('Python', 'learnpython', 'learnprogramming', 'PySimpleGUI', 'madeinpython', 'AskProgramming', 'Coding', 'Programming', 'learnmachinelearning', 'MLQuestions', 'datascience', 'MachineLearning', 'pythontips', 'pystats', 'pythoncoding', 'pythondev', 'scipy')
87
88 sg.theme('Dark Red')
89 num_searches = 1
90 search_layout = [[sg.B('+'), sg.T('Add term')]]
91 search_layout += [make_search_row(i) for i in range(num_searches)]
92 layout = [[sg.Text('Reddit Searcher', font='Any 18')],
93 [sg.Frame('Choose Subs',
94 [[sg.Listbox(sub_names, size=(25, 7), select_mode=sg.SELECT_MODE_MULTIPLE, key='-SUBS-')]]),
95 sg.Frame('Options',
96 [[sg.Checkbox('Look in Comments', True, key='-COMMENTS-')],
97 [sg.Checkbox('Show finds in browser', key='-BROWSER-')],
98 [sg.Checkbox('Show popup', key='-POPUP-')],
99 [sg.Text('Limit: '), sg.Spin(list(range(200, 5000)), size=(4, 1), key='-LIMIT-')]])],
100 [sg.Frame('Search Terms', search_layout, key='-SEARCH FRAME-' )],
101 [sg.Frame('Status',[
102 [sg.Text('Reading Sub:'), sg.Text(size=(25, 1), key='-OUT SUB-')],
103 [sg.Text('Reading Post:'), sg.Text(size=(40, 1), key='-OUT POST-')],
104 [sg.Text('Posts Read:'), sg.Text(size=(25, 1), key='-NUM POSTS-')],
105 [sg.T('Sub Progress', size=(12,1)), sg.ProgressBar(100, orientation='horizontal', size=(30, 20), key='-PROG-')],
106 [sg.T('Overall Progress', size=(12,1)),sg.ProgressBar(100, orientation='horizontal', size=(30, 20), key='-PROG-TOTAL-')],])],
107 [sg.Frame('Results (Click to Lauch in Browser)',
108 [[sg.Listbox([], size=(60,10), key='-LISTBOX-', enable_events=True)]])],
109 [sg.Button('Start Search', bind_return_key=True), sg.B('Settings'), sg.Button('Exit')], ]
110
111 window = sg.Window('Reddit Reader', layout, icon=reddit_icon, use_default_focus=False)
112
113 results = {}
114 while True: # Event Loop
115 event, values = window.read()
116 if event in (None, 'Exit'):
117 break

Callers 1

Calls 10

readMethod · 0.95
refreshMethod · 0.95
extend_layoutMethod · 0.95
closeMethod · 0.95
make_search_rowFunction · 0.85
update_barMethod · 0.80
settings_windowFunction · 0.70
updateMethod · 0.45
getMethod · 0.45
newMethod · 0.45

Tested by

no test coverage detected