def OnCloseWindow(self, event):
        settings.log("SalesGraph starting exit")

        from currency import ExchangeRate
        ExchangeRate.save_currencies()
        ExchangeRate.requestShutdown()

        settings.save_settings()
        self.sales_period.requestShutdown()

        if not self.sales_downloader == None:
            self.sales_downloader.requestShutdown()

        if not self.updater == None:
            self.updater.requestShutdown()

        self.Destroy()
Example #2
0
def do_one_time_debug_init():
    
    # import currency
    # currency.download_all_currencies()
    
    if not os.path.exists(DataDir()):
        os.makedirs(DataDir())
    
    try:
        sales = SalesDir("sales_data")
        os.makedirs(sales)
    except:
        pass
    
    try:
        os.makedirs(DataDir("sales_data/xml/"))
    except:
        pass

    try:
        os.makedirs(SalesDir("double/"))
    except:
        pass
    
    try:
        os.makedirs(DataDir("images/forapps/"))
    except:
        pass

    
    if not os.path.exists(DataDir("currencies.key")):
        import shutil
        shutil.copyfile("currencies.key", DataDir("currencies.key"))
    
    log("DataDir: " + DataDir())
    
    # Create date file
    loc = wx.StandardPaths.Get().GetUserConfigDir()
    if not loc[len(loc)-1] == "/":
        loc = loc + "/"

    # Load currentcy file
    ExchangeRate.get("USD")
   def run(self):
		print "Loading Data"

		for i, product_id in enumerate(self.product_ids):

			if self.shutdown == True:
	  	  		print "Exiting review download thread"
	  	  		return

			if settings.DOWNLOAD_REVIEWS == True:
				if self.shutdown == True:
	  	  		    print "Exiting review download thread"
	  	  		    return

				# print "Retrieving App Number" + i.__str__() + " with id=" + product_id.__str__()
				try:
					itunes7_useragent = "iTunes/4.2 (Macintosh; U; PPC Mac OS X 10.2"

					headers = {
                        "X-Apple-Tz" : "7200",
        	          	"Accept-Language" : "en-us, en;q=0.50",
        	          	"Connection" : "close",
        	          	"Host" : "ax.phobos.apple.com.edgesuite.net"
                   	    }

					request  = urllib2.Request('http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=' + product_id.__str__() + '&pageNumber=0&sortOrdering=2&type=Purple+Software', None, headers)
					opener = urllib2.build_opener()
					opener.addheaders = [('User-agent', itunes7_useragent)]

					fp = opener.open(request)

					html = fp.read()
				except:
					continue

				try:
					os.mkdir(settings.SalesDir("xml"))
				except:
					pass

				f = open(settings.SalesDir("xml/") + product_id.__str__() + ".xml", "w+")
				f.write(html)
				f.close()

			try:
				f = open(settings.SalesDir("xml/") + product_id.__str__() + ".xml", "r+")
			except:
				continue

			if self.shutdown == True:
	  	  		print "Exiting review download thread"
	  	  		return

			parser = xml.sax.make_parser()
			handler = AppInfoParser()
			parser.setContentHandler(handler)
			parser.parse(settings.SalesDir("xml/") + product_id.__str__() + ".xml")

			self.reviews[product_id] = handler.reviews

			image = urllib.URLopener()
			image.retrieve(handler.image_url, settings.DataDir("images/forapps/") + product_id.__str__() + ".jpg")

			try:
				wx.PostEvent(self.notify_window, ResultEvent("RefreshImageAndReviews:" + str(product_id)))
			except:
				pass


		from currency import ExchangeRate
		ExchangeRate.update_currencies()

		print "Image & Review Download Complete"

		wx.PostEvent(self.notify_window, ResultEvent("ReviewDownloadComplete"))