Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAneesh Dogra <lionaneesh@gmail.com>2012-12-25 15:08:45 (GMT)
committer Aneesh Dogra <lionaneesh@gmail.com>2012-12-25 15:10:13 (GMT)
commitd6e91536ec016f743f55195067c105a3515bd14a (patch)
treefd75a3c0708f0ab3c8f24e42fd230b638824f9f3
parent91dd534f02121c74f22fd7ee8d4d1007333fafcd (diff)
Only export the current article to the journal.
-rw-r--r--JournalExport.py50
-rw-r--r--activity.py11
2 files changed, 27 insertions, 34 deletions
diff --git a/JournalExport.py b/JournalExport.py
index 3c71d00..3002647 100644
--- a/JournalExport.py
+++ b/JournalExport.py
@@ -40,34 +40,34 @@ class JournalExport:
self.dataretriever = dataretriever.DataRetriever(system_id, confvars['path'])
self.confvars = confvars
- def export_all(self, progressbar):
- article_list = self.search('') # get all articles
- for index in range(0, len(article_list)):
+ def export_article(self, article):
+ article_list = self.search(article) # get all articles
+ if len(article_list) == 0: # no such article
+ return
+ title = article_list[0]
+ article_text = self.wikidb.getRawArticle(title).encode('utf8')
+ article_text = self.wikidb.expandArticle(article_text, title)
+ tokens = scanner.tokenize(article_text, title)
+ wiki_parsed = parser.Parser(tokens, title).parse()
+ wiki_parsed.caption = title
+ out = StringIO.StringIO()
+ w = htmlwriter.HTMLWriter(out)
+ w.write(wiki_parsed)
+ htmloutput = out.getvalue()
+ filename = os.path.join(instance_dir, title + '.html')
- article_text = self.wikidb.getRawArticle(article_list[index]).encode('utf8')
- article_text = self.wikidb.expandArticle(article_text, article_list[index])
- tokens = scanner.tokenize(article_text, article_list[index])
- wiki_parsed = parser.Parser(tokens, article_list[index]).parse()
- wiki_parsed.caption = article_list[index]
- out = StringIO.StringIO()
- w = htmlwriter.HTMLWriter(out)
- w.write(wiki_parsed)
- htmloutput = out.getvalue()
- filename = os.path.join(instance_dir, article_list[index] + '.html')
- print filename
- fp = open(filename, 'w')
- fp.write(htmloutput)
- fp.close()
+ fp = open(filename, 'w')
+ fp.write(htmloutput)
+ fp.close()
- journal_entry = datastore.create()
- journal_entry.metadata['title'] = article_list[index]
- journal_entry.metadata['title_set_by_user'] = '1'
- journal_entry.metadata['mime_type'] = 'text/html'
- journal_entry.file_path = filename
- datastore.write(journal_entry)
+ journal_entry = datastore.create()
+ journal_entry.metadata['title'] = title
+ journal_entry.metadata['title_set_by_user'] = '1'
+ journal_entry.metadata['mime_type'] = 'text/html'
+ journal_entry.file_path = filename
+ datastore.write(journal_entry)
- progressbar.set_fraction((index + 1) / len(article_list))
- os.remove(filename)
+ os.remove(filename)
def search(self, article_title):
return self.wikidb.dataretriever.search(article_title)
diff --git a/activity.py b/activity.py
index d4fc79e..16e5212 100644
--- a/activity.py
+++ b/activity.py
@@ -17,7 +17,6 @@
from gettext import gettext as _
from JournalExport import JournalExport
-from gi.repository import Gtk # for progressbar
import os
import sys
@@ -97,18 +96,12 @@ class WikipediaActivity(webactivity.WebActivity):
if hasattr(self._primary_toolbar, '_add_tab'):
self._primary_toolbar._add_tab.hide()
- #XXX: Find a way to display this on the screen.
- self.progressbar = Gtk.ProgressBar() # used with Journal Exporter
- self.progressbar.set_fraction(0.0)
-
self.searchtoolbar.show()
def _export_to_journal_cb(self, widget):
+ browser = self._get_browser()
je = JournalExport(self.confvars)
- # As this takes a hell lot of time, its preferable to display a
- # progressbar, let's create that
- self.progressbar.show()
- je.export_all(self.progressbar)
+ je.export_article(browser.props.title)
def _get_browser(self):
if hasattr(self, '_browser'):