· 4 years ago · Sep 06, 2021, 05:04 AM
1import redditclass as rc
2import requests
3import json
4import PySimpleGUI as sg
5
6CLIENT_ID = '#'
7SECRET_KEY = '#'
8USERNAME = '#'
9PASSWORD = '#'
10
11reddit = rc.Reddit(CLIENT_ID, SECRET_KEY, USERNAME, PASSWORD)
12
13reddit.connect()
14
15userinfo = reddit.user_information(reddit.headers)
16
17print(userinfo['total_karma'])
18
19for x,y in userinfo.items():
20 print(x,y)
21
22
23rednotifs = reddit.user_inbox(reddit.headers)
24def redditnotifications(rednotifications):
25 mdata = rednotifications
26 notifications = []
27 for i in range(len(mdata)):
28 mail_data = mdata[i]
29 mytext = f"[Subreddit: {mail_data['subreddit']}] | [Author: {mail_data['author']}]"
30 notifications.append(mytext)
31 return notifications
32
33
34file_list_column = [[
35 sg.Listbox(
36 values = [a for a in redditnotifications(rednotifs)],
37 enable_events=True,
38 size=(100, 50),
39 key="-NOTIFICATIONS-"
40 )],]
41
42notification_viewer_column = [[sg.Text("Choose a notification from the list on left:", key="ap")]]
43
44layout = [[
45 sg.Column(file_list_column),
46 sg.VSeperator(),
47 sg.Column(notification_viewer_column),
48 ]]
49
50sg.theme('DarkAmber')
51window = sg.Window("Reddit Notifications", layout)
52
53
54while True:
55
56 event, values = window.read()
57 if event == "-NOTIFICATIONS-":
58 notification = values['-NOTIFICATIONS-'][0]
59 print(event)
60 print(values)
61 window.Element('ap').Update(values)
62 if event == "Exit" or event == sg.WIN_CLOSED:
63
64 break