Permalink
Browse files

added the download menu item and dialog

  • Loading branch information...
1 parent b24b714 commit e588daee2b8814bf3ec7964088947e2a8b6a5527 @tecoholic tecoholic committed Jul 22, 2011
Showing with 33 additions and 35 deletions.
  1. +22 −35 downloader.py
  2. +11 −0 gui.py
View
@@ -5,45 +5,32 @@
This script is to automatically look for the latest dump and dowmload it.
'''
-from HTMLParser import HTMLParser
-from urllib2 import urlopen
import os
+import bz2
import re
+import codecs
-class Spider(HTMLParser):
- links = []
- def __init__(self, url):
- HTMLParser.__init__(self)
- req = urlopen(url)
- self.feed(req.read())
- def handle_starttag(self, tag, attrs):
- ''' scans all the links and returns the latest dump url '''
- if tag == 'a' and attrs:
- self.links.append(attrs[0][1])
- def latest_dump(self):
- ''' Print the latest dump url '''
- return self.links[-2].strip('/')
+import wx
+import wx.lib.delayedresult as delayedresult
+import urllib2
-if __name__ == "__main__":
- base_url = 'http://dumps.wikimedia.org/tawiktionary/'
- newd = Spider(base_url)
- # Get the list of files from the location
- # select the latest dump
- dat = latest_dump()
- dump_file = 'tawiktionary-'+dat+'-pages-articles.xml.bz2'
- dump_url = base_url+'/'+dat+'/'+dump_file
- files = os.listdir('wiki-files/')
- for fil in files:
- if os.path.isfile('wiki-files/'+fil):
- if re.match('tawiktionary-[0-9]*-pages-articles.xml.bz2', fil):
- dat2 = fil.lstrip('tawiktionary-').rstrip('-pages-articles.xml.bz2')
- if int(dat) > int(dat2):
- #newer dump available update
- elif int(dat) == int(dat2):
- #both are same don't update
- else:
- pass
+class DownloadDialog(wx.Dialog):
+ def __init__(self, parent, id, title):
+ wx.Dialog.__init__(self, parent, id, title)
+ self.txt = wx.StaticText(self, -1, "Module Under development :)",
+ style = wx.ALIGN_LEFT)
+ # the sizers
+ self.vsizer = wx.BoxSizer(wx.VERTICAL)
+ self.vsizer.Add(self.txt, 0,
+ wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT|wx.BOTTOM,
+ border=10)
+ # layout sizers
+ self.SetSizer(self.vsizer)
+ self.SetAutoLayout(1)
+ self.vsizer.Fit(self)
+
- # TODO: create a download manager, to manage partial downloads
+if __name__ == '__main__':
+ print 'This file is not supposed to be run directly.'
View
11 gui.py
@@ -13,6 +13,7 @@
from searcher import *
from splitter import RunSplitter
from indexer import IndexDialog
+from downloader import DownloadDialog
class MainWindow(wx.Frame):
''' This class defines the basis of the GUI of the entire application '''
@@ -21,6 +22,8 @@ def __init__(self,parent, title):
# Menu
filemenu = wx.Menu()
+ filemenu.Append(wx.ID_FILE3, "&Download",
+ "Download the latest XML dump from Wikimedia")
filemenu.Append(wx.ID_FILE1, "&Split",
"Create smaller chunks from large XML file")
filemenu.Append(wx.ID_FILE2, "&Index",
@@ -61,6 +64,7 @@ def __init__(self,parent, title):
self.Bind(wx.EVT_MENU, self.ShowAbout, id=wx.ID_ABOUT)
self.Bind(wx.EVT_MENU, self.RunSplitter, id=wx.ID_FILE1)
self.Bind(wx.EVT_MENU, self.OpenIndexDialog, id=wx.ID_FILE2)
+ self.Bind(wx.EVT_MENU, self.RunDownloader, id=wx.ID_FILE3)
#sizers for placemnt
self.hsizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -134,6 +138,13 @@ def OpenIndexDialog(self, event):
dia.ShowModal()
dia.Destroy()
return True
+
+ def RunDownloader(self, event):
+ ''' The RunDownloader runs the downloader.py function '''
+ dwn = DownloadDialog(self, -1, "Downloader")
+ dwn.ShowModal()
+ dwn.Destroy()
+ return True
if __name__ == '__main__':

0 comments on commit e588dae

Please sign in to comment.