def import_opml(self, filename): RssDb.init(Globals.rss_dbfile) import OPML opml = OPML.parse(filename) for o in opml.outlines: c = RssDb.Category.get_by(title=o['title']) if not c: c = RssDb.Category(o['title']) c.commit() for i in o.children: f = RssDb.Feed.get_by(category_id=c.id, link=i['xmlUrl']) if f: f.title = i['title'] f.homelink = i.get('htmlUrl', '') f.description = i.get('description', '') f.commit() else: c.feeds.append( RssDb.Feed(title=i['title'], link=i['xmlUrl'], homelink=i.get('htmlUrl', ''), imagelink='', description=i.get('description', ''))) RssDb.objectstore.commit() item, node = self.sharewin.get_cur_node() self.sharewin.reset_cur_item()
def import_opml(self, filename): RssDb.init(Globals.rss_dbfile) import OPML opml = OPML.parse(filename) for o in opml.outlines: c = RssDb.Category.get_by(title=o['title']) if not c: c = RssDb.Category(o['title']) c.commit() for i in o.children: f = RssDb.Feed.get_by(category_id=c.id, link=i['xmlUrl']) if f: f.title = i['title'] f.homelink = i.get('htmlUrl', '') f.description = i.get('description', '') f.commit() else: c.feeds.append(RssDb.Feed(title=i['title'], link=i['xmlUrl'], homelink=i.get('htmlUrl', ''), imagelink='', description=i.get('description', ''))) RssDb.objectstore.commit() item, node = self.sharewin.get_cur_node() self.sharewin.reset_cur_item()
__author__ = 'houjunwei' import OPML opml = OPML.parse('/Users/houjunwei/Downloads/rss-itnews.opml') #1:ITNEWS 2:DATABASES tag_id = 1 import MySQLdb CONF={ 'user':'******', 'passwd':'gogoreader', 'port':5002, 'host':'192.168.2.108', 'db':'gogoreader', 'charset':'utf8' } conn = MySQLdb.connect(**CONF) cursor = conn.cursor() cursor.execute('set autocommit=1') for item in opml.outlines: print item['title'] for i in item.children: title=i['title'].replace("\\","\\\\").replace("'","''") xmlurl=i['xmlUrl'].replace("\\","\\\\").replace("'","''") insertsql="insert ignore into links_rsssource(title,published_time,description,tag_id,url) " \ "values('%s',now(),'%s',%d,'%s')"%(title,title,tag_id,xmlurl) print insertsql cursor.execute(insertsql) cursor.close() conn.close()