~bakrss.developers/bakrss/main

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
import feedparser
import pygtk
pygtk.require('2.0')
import gtk
import gtk.glade
import gobject
from add_dialog import Add_dialog

class Feed:
    #sito="http://feeds.delicious.com/v2/rss/twelvetone"
    #sito="http://feeds.feedburner.com/pollycokenet"
    sito={"Twelvetone":"http://feeds.delicious.com/v2/rss/twelvetone","PollyCoke":"http://feeds.feedburner.com/pollycokenet"}

    def __init__(self):
        #Signals required for glade widgets
        signals = {"gtk_main_quit" : gtk.main_quit,
                   "on_add_btn_clicked" : self.on_add_btn_clicked,
                   "on_refresh_btn_clicked" : self.on_refresh_btn_clicked,
                   }
        #Glade file init
        self.glade = gtk.glade.XML("Gui.glade")
        self.glade.signal_autoconnect(signals)
        self.window = self.glade.get_widget("window")
        self.scrolledwindow = self.glade.get_widget("scrolledwindow")
        self.add_btn = self.glade.get_widget("add_btn")
        self.refresh_btn = self.glade.get_widget("refresh_btn")
        
        #Treeview widget
        self.liststore=gtk.ListStore(int,str,str,str)
        self.treeview=gtk.TreeView(self.liststore)  
        self.colonna_cont=gtk.TreeViewColumn('num')
        self.colonna_nome=gtk.TreeViewColumn('Site')
        self.colonna_date=gtk.TreeViewColumn('Date')
        self.colonna_link=gtk.TreeViewColumn('Link')
        self.treeview.append_column(self.colonna_cont)
        self.treeview.append_column(self.colonna_nome)
        self.treeview.append_column(self.colonna_date)
        self.treeview.append_column(self.colonna_link)
        
        #self.treeview.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)

        self.cella_cont=gtk.CellRendererText()
        self.cella_nome=gtk.CellRendererText()
        self.cella_date=gtk.CellRendererText()
        self.cella_link=gtk.CellRendererText()
        self.cella_cont.set_property('cell-background','cyan')
        self.cella_nome.set_property('cell-background','grey')
        self.cella_date.set_property('cell-background','green')
        self.cella_link.set_property('cell-background','grey')
        self.colonna_cont.pack_start(self.cella_cont,True)
        self.colonna_nome.pack_start(self.cella_nome,True)
        self.colonna_date.pack_start(self.cella_date,True)
        self.colonna_link.pack_start(self.cella_link,True)
        self.colonna_cont.set_attributes(self.cella_cont,text=0)
        self.colonna_nome.set_attributes(self.cella_nome,text=1)
        self.colonna_date.set_attributes(self.cella_date,text=2)
        self.colonna_link.set_attributes(self.cella_link,text=3)
        self.colonna_cont.set_sort_column_id(0)
        self.colonna_nome.set_sort_column_id(0)
        self.colonna_date.set_sort_column_id(0)
        self.colonna_link.set_sort_column_id(0)
        # make treeview searchable
        self.treeview.set_search_column(0)
        # Allow sorting on the column
        self.colonna_cont.set_sort_column_id(0)
        # No reordeding drag and drop
        self.treeview.set_reorderable(False)
        #Treeview added in a scrolledwindow
        self.scrolledwindow.add_with_viewport(self.treeview)
        self.window.show_all()
        
    def parser(self,site):
            diz = {}
            for sit in site.keys():
                    d = feedparser.parse(site[sit])
                    for i in range(0,len(d['items'])):
                            tmp=[]
                            self.title = d['items'][i].title
                            self.news_url = d['items'][i].links[0]['href']
                            self.news_data = d['items'][i].updated [:-5]
                            self.news_data = self.news_data[:-5]
                            tmp.append(sit)
                            tmp.append(self.news_data)
                            tmp.append(self.news_url)
                            diz[self.title] = tmp
            return diz
            
    def on_add_btn_clicked(self, widget):
        Add_dialog()
        
    def on_refresh_btn_clicked(self, widget):
        line=1
        feeds=self.parser(self.sito)
        for key in feeds.keys():
            self.liststore.append([line,feeds[key][0],feeds[key][1],key])
            line+=1
        
    def main(self):
        gtk.main()

#---MAIN---#
if __name__ == "__main__":
    window = Feed()
    window.main()