Beispiel #1
0
	def runJob(self):
		self.logInfo(logging.INFO, "extract data from quickOrder", 20)

#		time.sleep(3)

		res=postgresql.extractChefMenu( host=self.env["QuickOrder DB"]["host"], 
								dbName=self.env["QuickOrder DB"]["dbname"],
								User=self.env["QuickOrder DB"]["user"],
								Pass=self.env["QuickOrder DB"]["password"] )

		startersContent, firstsContent, secondsContent = "", "", ""
		for row in res:
			if row['category']=='antipasto':
				startersContent+=row['description']+' '+str(row['price'])+'<br>'
			elif row['category']=='primo':
				firstsContent+=row['description']+' '+str(row['price'])+'<br>'
			elif row['category']=='secondo':
				secondsContent+=row['description']+' '+str(row['price'])+'<br>'

		self.logInfo(logging.INFO, "build mail content", 30)

		ms = MailSnake( self.env["mailChimp"]['apikey'] )

		menuContent='<h3>Antipasti</h3>'+startersContent+'<h3>Primi</h3>'+firstsContent+'<h3>Secondi</h3>'+secondsContent

		self.logInfo(logging.INFO, "duplicate mail", 40)
		campaignsResult = ms.call('campaigns', params = {'filters': { 'title': 'MenuChef '+ self.today.strftime("%d-%m-%Y"), 'type': 'regular', 'status': 'save' } } )
		if campaignsResult['total'] == 1:
			cid = campaignsResult['data'][0]['id']
			ms.call('campaignUpdate', params = {'cid': cid, 'name': 'content', 'value': { 'html_std_content00': menuContent } } )
		elif campaignsResult['total'] == 0:
			cid = ms.call('campaignReplicate', params = { 'cid': '0a66ed0baa' } )
			if ms.call('campaignUpdate', params = {'cid': cid, 'name': 'title', 'value': 'MenuChef '+ self.today.strftime("%d-%m-%Y") } ):
				ms.call('campaignUpdate', params = {'cid': cid, 'name': 'content', 'value': { 'html_std_content00': menuContent } } )

		if self.test is True:
			self.logInfo(logging.INFO, "send test mail to "+self.env["mailChimp"]["mailstest"], 80)
			ms.call('campaignSendTest', params = {'cid': cid, 'test_emails': [ self.env["mailChimp"]["mailstest"] ] } )
		else: 
			self.logInfo(logging.INFO, "send mail", 80)
			ms.call('campaignSendTest', params = {'cid': cid, 'test_emails': [ self.env["mailChimp"]["mailstest"] ] } )
Beispiel #2
0
    def runJob(self):
        if not self.requestStop:
            print resource_filename("filomanager.stages", "templates/menu-chef.ott")
            document = odf_new_document(resource_filename("filomanager.stages", "templates/menu-chef.ott"))
            body = document.get_body()
            t_starters = body.get_table(name=self.env["Menu-chef"]["starters-list-name"])
            r_starters = t_starters.get_row(0).clone()
            t_firsts = body.get_table(name=self.env["Menu-chef"]["first-courses-list-name"])
            r_firsts = t_firsts.get_row(0).clone()
            t_seconds = body.get_table(name=self.env["Menu-chef"]["second-courses-list-name"])
            r_seconds = t_seconds.get_row(0).clone()

        if not self.requestStop:
            self.logInfo(logging.INFO, "extract data from quickOrder", 20)

            res = postgresql.extractChefMenu(
                host=self.env["QuickOrder DB"]["host"],
                dbName=self.env["QuickOrder DB"]["dbname"],
                User=self.env["QuickOrder DB"]["user"],
                Pass=self.env["QuickOrder DB"]["password"],
            )

            i_starters, i_firsts, i_seconds = 0, 0, 0
            for row in res:
                if row["category"] == "antipasto":
                    r = r_starters
                    t = t_starters
                    i = i_starters
                    i_starters += 1
                elif row["category"] == "primo":
                    r = r_firsts
                    t = t_firsts
                    i = i_firsts
                    i_firsts += 1
                elif row["category"] == "secondo":
                    r = r_seconds
                    t = t_seconds
                    i = i_seconds
                    i_seconds += 1

                descCell = r.get_cell(0)
                if self.translate is None:
                    text = row["description"]
                else:
                    text = gtranslate.translate(row["description"], src="it", to=self.translate)
                descCell.set_value(text.decode("utf-8"))
                priceCell = r.get_cell(1)
                priceCell.set_value(row["price"])
                r.set_cell(0, descCell)
                r.set_cell(1, priceCell)
                t.insert_row(i, r)
        # 				print row['category'] + " " + row['description'] + " " + str(row['price'])

        if not self.requestStop:
            if self.translate is None:
                lang = "it"
            else:
                lang = self.translate
            outputFileName = (
                self.env["Menu-chef"]["file-output-dir"]
                + "/"
                + self.today.strftime("%d-%m-%Y")
                + "-"
                + lang
                + "_"
                + self.env["Menu-chef"]["file-output-name"]
                + "."
                + self.env["Menu-chef"]["file-output-format"]
            )
            document.save(outputFileName)
            self.logInfo(logging.INFO, "open document " + outputFileName, 75)
            os.system("lowriter " + outputFileName)