aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorcedricbonhomme <devnull@localhost>2012-05-01 18:18:28 +0200
committercedricbonhomme <devnull@localhost>2012-05-01 18:18:28 +0200
commit864d8a49934894fe59ed89517063f1c05d6fb0fc (patch)
treeae46d3115adda02f27ac2ab776526169d137557f /source
parentSpeed improvement. (diff)
downloadnewspipe-864d8a49934894fe59ed89517063f1c05d6fb0fc.tar.gz
newspipe-864d8a49934894fe59ed89517063f1c05d6fb0fc.tar.bz2
newspipe-864d8a49934894fe59ed89517063f1c05d6fb0fc.zip
It is now possible to update information about a feed with the MongoDG database.
Diffstat (limited to 'source')
-rw-r--r--source/mongodb.py7
-rwxr-xr-xsource/pyAggr3g470r.py25
-rwxr-xr-xsource/utils.py38
3 files changed, 20 insertions, 50 deletions
diff --git a/source/mongodb.py b/source/mongodb.py
index b3527794..7bb5c841 100644
--- a/source/mongodb.py
+++ b/source/mongodb.py
@@ -186,6 +186,13 @@ class Articles(object):
for feed_id in self.db.collection_names():
self.mark_as_read(readed, feed_id, None)
+ def update_feed(self, feed_id, changes):
+ """
+ Update a feed.
+ """
+ collection = self.db[str(feed_id)]
+ collection.update({"type": 0, "feed_id":feed_id}, {"$set": changes}, multi=True)
+
def list_collections(self):
"""
List all collections (feed).
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
index f00fe795..48103319 100755
--- a/source/pyAggr3g470r.py
+++ b/source/pyAggr3g470r.py
@@ -656,18 +656,18 @@ class Root:
html += '\n\n<form method=post action="/change_feed_name/">' + \
'<input type="text" name="new_feed_name" value="" ' + \
'placeholder="Enter a new name (then press Enter)." maxlength=2048 autocomplete="on" size="50" />' + \
- """<input type="hidden" name="feed_url" value="%s" /></form>\n""" % \
- (feed["feed_link"],)
+ """<input type="hidden" name="feed_id" value="%s" /></form>\n""" % \
+ (feed["feed_id"],)
html += '\n\n<form method=post action="/change_feed_url/">' + \
'<input type="url" name="new_feed_url" value="" ' + \
'placeholder="Enter a new URL in order to retrieve articles (then press Enter)." maxlength=2048 autocomplete="on" size="50" />' + \
- """<input type="hidden" name="old_feed_url" value="%s" /></form>\n""" % \
- (feed["feed_link"],)
+ """<input type="hidden" name="feed_id" value="%s" /><input type="hidden" name="old_feed_url" value="%s" /></form>\n""" % \
+ (feed["feed_id"], feed["feed_link"])
html += '\n\n<form method=post action="/change_feed_logo/">' + \
- '<input type="url" name="new_feed_logo" value="" ' + \
+ '<input type="text" name="new_feed_logo" value="" ' + \
'placeholder="Enter the URL of the logo (then press Enter)." maxlength=2048 autocomplete="on" size="50" />' + \
- """<input type="hidden" name="feed_url" value="%s" /></form>\n""" % \
- (feed["feed_link"],)
+ """<input type="hidden" name="feed_id" value="%s" /></form>\n""" % \
+ (feed["feed_id"],)
dic = {}
top_words = utils.top_words(articles = self.mongo.get_articles_from_collection(feed_id), n=50, size=int(word_size))
@@ -1101,13 +1101,14 @@ class Root:
remove_feed.exposed = True
- def change_feed_url(self, new_feed_url, old_feed_url):
+ def change_feed_url(self, feed_id, old_feed_url, new_feed_url):
"""
Enables to change the URL of a feed already present in the database.
"""
html = htmlheader()
html += htmlnav
html += """<div class="left inner">"""
+ self.mongo.update_feed(feed_id, {"feed_link":new_feed_url})
utils.change_feed_url(old_feed_url, new_feed_url)
html += "<p>The URL of the feed has been changed.</p>"
html += "<hr />\n"
@@ -1116,14 +1117,14 @@ class Root:
change_feed_url.exposed = True
- def change_feed_name(self, feed_url, new_feed_name):
+ def change_feed_name(self, feed_id, new_feed_name):
"""
Enables to change the name of a feed.
"""
html = htmlheader()
html += htmlnav
html += """<div class="left inner">"""
- utils.change_feed_name(feed_url, new_feed_name)
+ self.mongo.update_feed(feed_id, {"feed_title":new_feed_name})
html += "<p>The name of the feed has been changed.</p>"
html += "<hr />\n"
html += htmlfooter
@@ -1131,14 +1132,14 @@ class Root:
change_feed_name.exposed = True
- def change_feed_logo(self, feed_url, new_feed_logo):
+ def change_feed_logo(self, feed_id, new_feed_logo):
"""
Enables to change the name of a feed.
"""
html = htmlheader()
html += htmlnav
html += """<div class="left inner">"""
- utils.change_feed_logo(feed_url, new_feed_logo)
+ self.mongo.update_feed(feed_id, {"feed_image":new_feed_logo})
html += "<p>The logo of the feed has been changed.</p>"
html += "<hr />\n"
html += htmlfooter
diff --git a/source/utils.py b/source/utils.py
index da68550b..26492b8d 100755
--- a/source/utils.py
+++ b/source/utils.py
@@ -36,7 +36,6 @@ __license__ = "GPLv3"
import os
import re
-import sqlite3
import operator
import urlparse
import calendar
@@ -252,43 +251,6 @@ def change_feed_url(old_feed_url, new_feed_url):
with open("./var/feed.lst", "w") as f:
f.write("\n".join(lines))
- # Replace the URL in the data base.
- try:
- conn = sqlite3.connect(sqlite_base, isolation_level = None)
- c = conn.cursor()
- c.execute("UPDATE articles SET feed_link='" + new_feed_url + "' WHERE feed_link='" + old_feed_url +"'")
- c.execute("UPDATE feeds SET feed_link='" + new_feed_url + "' WHERE feed_link='" + old_feed_url +"'")
- conn.commit()
- c.close()
- except Exception, e:
- print e
-
-def change_feed_name(feed_url, new_feed_name):
- """
- Change the name of a feed given in parameter.
- """
- try:
- conn = sqlite3.connect(sqlite_base, isolation_level = None)
- c = conn.cursor()
- c.execute('UPDATE feeds SET feed_title="' + new_feed_name + '" WHERE feed_link="' + feed_url +'"')
- conn.commit()
- c.close()
- except Exception, e:
- print e
-
-def change_feed_logo(feed_url, new_feed_logo):
- """
- Change the logo of a feed given in parameter.
- """
- try:
- conn = sqlite3.connect(sqlite_base, isolation_level = None)
- c = conn.cursor()
- c.execute('UPDATE feeds SET feed_image_link="' + new_feed_logo + '" WHERE feed_link="' + feed_url +'"')
- conn.commit()
- c.close()
- except Exception, e:
- print e
-
def remove_feed(feed_url):
"""
Remove a feed from the file feed.lst and from the SQLite base.
bgstack15