Skip to content

Commit e46cf0f

Browse files
committed
update function display price
1 parent 8e24c0a commit e46cf0f

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

FunPy02_SanDealTiki/DealHunter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from threading import Thread
22
from Helper import getItemFromHtmlElement
3+
from Helper import numberToStrPrice
34
import time
45
import random
56
import requests
@@ -37,7 +38,7 @@ def findTheBestDeal(self):
3738
print(self.target.name + ": " + str(len(listItem)) + " items:")
3839
for item in listItem:
3940
# print(self.target.name + ": " + str(item.price) + "\n" + item.url)
40-
print(self.target.name + ": " + str(item.price))
41+
print(self.target.name + " (" + numberToStrPrice(self.target.maxPrice) + "): " + numberToStrPrice(item.price))
4142

4243
def run(self):
4344
i = 0

FunPy02_SanDealTiki/Helper.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,22 @@ def getItems(fileName):
2323

2424
return listItem
2525

26-
def correctNumber(price):
27-
price = price.replace('.', '')
28-
price = price.replace('đ', '')
29-
return int(price)
26+
def correctNumber(strPrice):
27+
strPrice = strPrice.replace('.', '')
28+
strPrice = strPrice.replace('đ', '')
29+
return int(strPrice)
30+
31+
def numberToStrPrice(intPrice):
32+
strPrice = str(intPrice)
33+
n = len(strPrice)
34+
k = int((n-1) / 3)
35+
# print("k = " + str(k) + " n = " + str(n))
36+
i = 0
37+
while i < k:
38+
i += 1
39+
index = (-3) * i - (i-1)
40+
strPrice = strPrice[:index] + "." + strPrice[index:]
41+
return strPrice
3042

3143
def getItemFromHtmlElement(itemHtml):
3244
newItem = Item()

FunPy02_SanDealTiki/Test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import requests
2+
from Helper import numberToStrPrice
23
from bs4 import BeautifulSoup
34

45
URL = "https://tiki.vn/search?q=Apple%20AirPods%202&_lc=Vk4wMzQwMjcwMDM=&headphone_type=108271"
5-
6+
7+
8+
print(numberToStrPrice(100))
9+
print(numberToStrPrice(1000))
10+
print(numberToStrPrice(1000000))
11+
pass
612
req = requests.get(URL)
713

814
soup = BeautifulSoup(req.text, "lxml")

0 commit comments

Comments
 (0)