def DaMaCaiDMCJackPot(): """DaMaCaiDMCJackPot Methods!""" # Connect to Source url='https://www.gidapp.com/lottery/malaysia/damacai' data=get(url) # Find latest Result latest_result_date=sel(text=data.text).xpath('.//*[@id="result-jackpotdmc"]/div/div/h5[1]/b/time/text()').get() # Winning numbers 1 jp1_winning_numbers= "Jackpot1 Winning Numbers\n\n" for i in range(1,(len(sel(text=data.text).xpath('//*[@id="result-jackpotdmc"]/table[1]/tbody/tr/td/p[1]/span')))+1): result=sel(text=data.text).xpath('.//*[@id="result-jackpotdmc"]/table[1]/tbody/tr/td/p[1]/span'+"["+str(i)+"]"+'//text()').getall() result=''.join(result) jp1_winning_numbers+=result + " " # Winning numbers 2 jp2_winning_numbers= "\n\nJackpot2 Winning Numbers\n\n" for i in range(1,(len(sel(text=data.text).xpath('//*[@id="result-jackpotdmc"]/table[2]/tbody/tr/td/p[1]/span')))+1): result=sel(text=data.text).xpath('.//*[@id="result-jackpotdmc"]/table[2]/tbody/tr/td/p[1]/span'+"["+str(i)+"]"+'//text()').getall() result=''.join(result) jp2_winning_numbers+=result + " " # Create Reply chat_reply = "<b>Latest DaMaCai DMC JackPot Draw Results on " + latest_result_date + "</b> \n\n" chat_reply += jp1_winning_numbers chat_reply += jp2_winning_numbers chat_reply += "\n\n No need check la sure never win!" return chat_reply
def PetrolPrice(): """DaMaCaiDMCJackPot Methods!""" # Connect to Source url='https://hargapetrol.my/malaysia-petrol-prices-list.html' data=get(url,headers={'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3','Accept-Encoding': 'gzip, deflate, br','Accept-Language': 'en-GB,en;q=0.9,en-US;q=0.8,zh-TW;q=0.7,zh;q=0.6','Cache-Control': 'max-age=0','Connection': 'keep-alive','DNT': '1','Upgrade-Insecure-Requests': '1','User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'}) # Find the valid range date_from=sel(text=data.text).xpath('.//div[@class="daterange active"][1]/text()').get() date_till=sel(text=data.text).xpath('.//div[@class="daterange active"][2]/text()').get() # Price ron95=sel(text=data.text).xpath('//div[@class="ron95 active"][1]/text()').get() ron97=sel(text=data.text).xpath('//div[@class="ron97 active"][1]/text()').get() diesel=sel(text=data.text).xpath('//div[@class="diesel active"][1]/text()').get() ron95_lw=sel(text=data.text).xpath('.//span[2]//span[@itemprop="priceComponent"]//div[@class="ron95"]/text()').get() ron97_lw=sel(text=data.text).xpath('.//span[2]//span[@itemprop="priceComponent"]//div[@class="ron97"]/text()').get() diesel_lw=sel(text=data.text).xpath('.//span[2]//span[@itemprop="priceComponent"]//div[@class="diesel"]/text()').get() ron95_diff=round((float(ron95)-float(ron95_lw))) ron95_diff='+'+'{:.2f}'.format(ron95_diff) if ron95_diff>=0 else'-'+str(ron95_diff) ron97_diff=round((float(ron97)-float(ron97_lw)),3) ron97_diff='+'+'{:.2f}'.format(ron97_diff) if ron97_diff>=0 else'-'+str(ron97_diff) diesel_diff=round((float(diesel)-float(diesel_lw)),3) diesel_diff='+'+'{:.2f}'.format(diesel_diff) if diesel_diff>=0 else'-'+str(diesel_diff) prices = "RON95 - " + "RM"+str(ron95)+"({})".format(ron95_diff) + "\nRON97 - " + "RM"+str(ron97)+"({})".format(ron97_diff) + "\nDiesel - " + "RM"+str(diesel)+"({})".format(diesel_diff) # Create Reply chat_reply = "<b>Petrol prices from " + str(date_from) + " until " + str(date_till) + "</b> \n\n" chat_reply += prices return chat_reply
def DaMaCai3D(): """DaMaCai3D Methods!""" # Connect to Source url='https://www.gidapp.com/lottery/malaysia/damacai' data=get(url) # Find latest Result latest_result_date=sel(text=data.text).xpath('.//*[@id="result-prizes3"]/div/div/h5[1]/b/time/text()').get() # TOP PRIZES first=sel(text=data.text).xpath('.//*[@id="result-prizes3"]/table/tbody/tr/td[1]/p/span/text()').get() second=sel(text=data.text).xpath('.//*[@id="result-prizes3"]/table/tbody/tr/td[1]/p/span/text()').get() third=sel(text=data.text).xpath('.//*[@id="result-prizes3"]/table/tbody/tr/td[1]/p/span/text()').get() top_text = "1st - " + first + "\n2nd - " + second + "\n3rd - " + third # Create Reply chat_reply = "<b>Latest DaMaCai 3D Draw Results on " + latest_result_date + "</b> \n\n" chat_reply += top_text chat_reply += "\n\n No need check la sure never win!" return chat_reply
def DaMaCai4D(): """DaMaCai4D Methods!""" # Connect to Source url='https://www.gidapp.com/lottery/malaysia/4d' data=get(url) # Find latest Result latest_result_date=sel(text=data.text).xpath('.//article/div/div[3]/header/div/h5[1]/time/text()').get() # TOP PRIZES first=sel(text=data.text).xpath('.//article/div/div[3]/table/tbody/tr[2]/td[1]/span/text()').get() second=sel(text=data.text).xpath('.//article/div/div[3]/table/tbody/tr[2]/td[2]/span/text()').get() third=sel(text=data.text).xpath('.//article/div/div[3]/table/tbody/tr[2]/td[3]/span/text()').get() top_text = "1st - " + first + "\n2nd - " + second + "\n3rd - " + third + "\n\n" # SPECIAL PRIZE special_prize_ls=sel(text=data.text).xpath('.//article/div/div[3]/table/tbody/tr[4]/td//text()').getall() special_prize_ls=list(filter(lambda a: a !=' ', special_prize_ls)) special_prize = "Special/Starter Prizes\n\n" for i in special_prize_ls: special_prize += i + " " # CONSOLATION PRIZE consol_prize_ls=sel(text=data.text).xpath('.//article/div/div[3]/table/tbody/tr[6]/td//text()').getall() consol_prize_ls=list(filter(lambda a: a !=' ', consol_prize_ls)) consol_prize = "\n\nConsolation Prizes\n\n" for i in consol_prize_ls: consol_prize += i + " " # Create Reply chat_reply = "<b>Latest DaMaCai 4D Draw Results on " + latest_result_date + "</b> \n\n" chat_reply += top_text chat_reply += special_prize chat_reply += consol_prize chat_reply += "\n\n No need check la sure never win!" return chat_reply