~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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import feedparser
import pygtk
pygtk.require('2.0')
import gtk
import gtk.glade
import gobject
from GuiTools import Add_dialog, Prefs_dialog
from dbaseclass import DbaseFeed

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,
                   "on_prefs_menu_item_activate": self.on_prefs_menu_item_activate,
                   "on_check_screen_toggled" : self.on_check_screen_toggled,
                   }
        #Glade file init
        self.glade = gtk.glade.XML("Gui.glade", "main_window")
        self.glade.signal_autoconnect(signals)
        self.window = self.glade.get_widget("main_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")
        self.check_screen = self.glade.get_widget("check_screen")
        
        #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 LoadURL(self):
        self.dbase=DbaseFeed()
        self.urls=self.dbase.read()
        #METTERE NOME DA VISUALIZZARE
        print self.urls
        print type(self.urls)
        return self.urls
        
    def parser(self):
            diz = {}
            url=self.LoadURL()
            print "url in parser= ",url
            for sit in url:
                    d = feedparser.parse(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):
        self.LoadURL()
        Add_dialog()
        
    def on_refresh_btn_clicked(self, widget):
        line=1
        feeds=self.parser()
        print "feeds= ",feeds
        for key in feeds.keys():
            self.liststore.append([line,feeds[key][0],feeds[key][1],key])
            line+=1
            
    def on_check_screen_toggled(self, widget):
        if self.check_screen.get_active():
            self.window.fullscreen()
        else:
            self.window.unfullscreen()
            
    def on_prefs_menu_item_activate(self, widget):
        Prefs_dialog()
        
    def main(self):
        gtk.main()

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