-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmint-blog-checker-sample.py
executable file
·107 lines (83 loc) · 3.2 KB
/
mint-blog-checker-sample.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
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# Copyright 2019 Scott Caudle
#
# This file is part of mint-blog-checker-sample.
#
# mint-blog-checker-sample is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# mint-blog-checker-sample is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mint-blog-checker-sample. If not, see <https://www.gnu.org/licenses/>.
import gtk
import subprocess
import glib
class BlogCheckerThingy():
global icon
def __init__(self):
self.icon = gtk.StatusIcon()
self.set_icon_off()
self.icon.connect('popup-menu', self.on_right_click)
self.icon.connect('activate', self.on_left_click)
self.check_blog_for_newrss()
#6 hour timer
glib.timeout_add_seconds(21600, self.check_blog_for_newrss)
def open_blog(self, data=None):
self.set_icon_off()
subprocess.call(['xdg-open', "https://blog.linuxmint.com/"])
def close_app(self, data=None):
gtk.main_quit()
def make_menu(self, event_button, event_time, data=None):
menu = gtk.Menu()
open_item = gtk.MenuItem("View Blog")
close_item = gtk.MenuItem("Close App")
#Append the menu items
menu.append(open_item)
menu.append(close_item)
#add callbacks
open_item.connect_object("activate", self.open_blog, "Open App")
close_item.connect_object("activate", self.close_app, "Close App")
#Show the menu items
open_item.show()
close_item.show()
#Popup the menu
menu.popup(None, None, None, event_button, event_time)
def on_right_click(self, data, event_button, event_time):
self.make_menu(event_button, event_time)
def on_left_click(self, event):
self.open_blog()
def compare_time_from_parsed_blog_file(self):
#check oldtime file
with open('oldtime', 'r') as oldtime:
old = oldtime.read()
#open new time file
with open('time', 'r') as time:
new = time.read()
#compare times
#if they are different there is new blog entry
if new != old:
from shutil import copyfile
copyfile("time", "oldtime")
return True #to turn on blog-on icon
#else they are the same then nothing new
else:
return False
def check_blog_for_newrss(self):
subprocess.call(['sh', "get-blog-time"])
if self.compare_time_from_parsed_blog_file():
self.set_icon_on()
return True #restart timeout again
def set_icon_on(self):
self.icon.set_from_file("rss-on.png")
self.icon.set_title("on")
def set_icon_off(self):
self.icon.set_from_file("rss-off.png")
self.icon.set_title("off")
test3 = BlogCheckerThingy()
gtk.main()