-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitterPython.py
More file actions
73 lines (65 loc) · 2.36 KB
/
GitterPython.py
File metadata and controls
73 lines (65 loc) · 2.36 KB
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
from tkinter import *
import requests
window = Tk()
window.title("GitterApp")
window.geometry("800x600+50+50")
try:
fobject=open("gpFile.txt","r")
token=fobject.readline()
fobject.close()
fobject=open("gpFile2.txt","r")
roomName=fobject.readline()
roomid=fobject.readline()
fobject.close()
canvas=Canvas(window,bg="lightgray")
scrollbar=Scrollbar(window,command=canvas.yview)
scrollbar.pack(side=RIGHT,fill=Y)
frame=Frame(canvas)
txt = Label(frame,text="Welcome to GitterPython\nRoomName: "+roomName,bg="lightgray",font=("consolas",12),fg="red")
txt.pack(fill="x")
window.update_idletasks() #Used to update idletasks
content=""
temp=""
i=0
url="https://api.gitter.im/v1/rooms/"+roomid
url=url+"/chatMessages?access_token="+token
msg=requests.get(url).json()
try:
while (msg[i]['text']):
if(msg[i]['unread']):
color="darkred"
else:
color="blue"
content=content+"\n*****************************\nMessage from: "+msg[i]['fromUser']['displayName']+"\n"
content=content+"Username: "+msg[i]['fromUser']['username']+"\n*****************************\n\n"
for p in msg[i]['text']:
try:
content=content+p
temp=temp+p
window.update_idletasks() #Used to update idletasks
if(p=='\n'):
temp=""
if(len(temp)>(window.winfo_width()/5.5)):
temp=""
content=content+"\n"
except:
print(" UCS-2 codec here")
content=content+"\n\n"
txt.pack(fill="x")
if(i%2==0):
txt = Label(frame,text=content,anchor="w",justify=LEFT,fg=color,bg="lightgray")
else:
txt = Label(frame,text=content,anchor="w",justify=LEFT,fg=color,bg="gray")
content=""
i=i+1
#print(len(content))
except:
print("\n\nReached the end")
frame.pack(fill="both")
canvas.pack(fill="both")
canvas.create_window((0,0),window=frame,anchor='nw')
canvas.configure(scrollregion=canvas.bbox("all"),width=800,height=600)
window.mainloop()
except:
print("Files missing! Please rum GitterPythonMain.py")
window.destroy()