-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_program.py
122 lines (94 loc) · 6.14 KB
/
main_program.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from skroutz_scraper import skroutz_scraper
from best_price_scraper import best_price_scraper
from colorama import Fore
from colorama import init as colorama_init
if(__name__=="__main__"):
colorama_init(autoreset=True)
print(Fore.GREEN + """
:::::::: ::: ::: ::::::::: :::::::: ::: ::: ::::::::::: ::::::::: ::::::::: :::::::::: :::::::: ::::::::::: ::::::::: ::::::::: ::::::::::: :::::::: :::::::::: :::::::: :::::::: ::::::::: ::: ::::::::: :::::::::: :::::::::
:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
+#++:++#++ +#++:++ +#++:++#: +#+ +:+ +#+ +:+ +#+ +#+ +#++:++#++:++ +#++:++#+ +#++:++# +#++:++#++ +#+ +#++:++#+ +#++:++#: +#+ +#+ +#++:++# +#++:++#++ +#+ +#++:++#: +#++:++#++: +#++:++#+ +#++:++# +#++:++#:
+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+#
######## ### ### ### ### ######## ######## ### ######### ######### ########## ######## ### ########## ### ### ### ########### ######## ########## ######## ######## ### ### ### ### ### ########## ### ###
""")
print("Welcome to this Webscraping program. Here are the functionalities of the program")
print("----------------------------------------------------------")
print("1. Find the cheapest product on Skroutz")
print("2. Find the cheapest product on Best Price")
print("3. Compare Skroutz and Best Price Prices")
print("4. Show reviews from Skroutz and Best Price")
print("5. Monitor the price of a certain product")
print("6. Save product info of all products in a specific category")
print("----------------------------------------------------------")
choice = input("Choose the desired functionality number: ")
while(choice not in ['1','2','3','4','5','6']):
choice = input("Wrong input. Please enter the desired functionality number: ")
print() # empty line
if(choice=='1'):
skroutz = skroutz_scraper()
skroutz.lowest_price()
elif(choice=='2'):
best_price = best_price_scraper()
best_price.lowest_price()
elif(choice=='3'):
all_products = []
# Select skroutz products
skroutz = skroutz_scraper()
answer = ' '
while(answer not in ['no','n']):
skroutz.select_products()
answer = input("Do you want to select another product? (Y/N) ")
answer.lower()
while(answer not in ["yes","no","y","n"]):
answer = input("Wrong answer, enter again: ")
all_products.extend(skroutz.selected_products)
print() # empty line
# Select best price products
best_price = best_price_scraper()
answer = ' '
while (answer not in ['no', 'n']):
best_price.select_products()
answer = input("Do you want to select another product?(Y/N) ")
answer.lower()
while (answer not in ["yes", "no", "y", "n"]):
answer = input("Wrong answer, enter again: ")
all_products.extend(best_price.selected_products)
all_products.sort(key=lambda product: product["price"])
cheapest_product = all_products[0]
review_score = "Not Available"
if(cheapest_product["review_score"]!=0):
review_score = str(cheapest_product["review_score"])
print("Cheapest product details:" + "\n" +
"- Name: " + cheapest_product["name"] + "\n" +
"- Price: " + str(cheapest_product["price"]) + " €" + "\n" +
"- Review score: " + review_score + '\n' +
"- Link: " + cheapest_product["link"])
print("-----------------------------")
elif(choice=='4'):
all_products = []
skroutz = skroutz_scraper()
best_price = best_price_scraper()
skroutz.select_products()
best_price.select_products()
all_products.extend(skroutz.selected_products)
all_products.extend(best_price.selected_products)
total_review_count = total_weighted_score = 0
for product in all_products:
total_review_count += product["reviews_count"]
total_weighted_score += product["review_score"] * product["reviews_count"]
weighted_average_review_score = 0
if total_review_count!=0:
weighted_average_review_score = total_weighted_score / total_review_count
print("Revie Score: " + str(round(weighted_average_review_score,2)) if weighted_average_review_score !=0 else "Not Available")
print("Reviews Count: " + str(total_review_count))
print("-----------------------------")
elif(choice=='5'):
minutes = int(input("How frequently do you want to check for a price change in minutes? "))
seconds = minutes*60
skroutz = skroutz_scraper()
skroutz.monitor_product(checking_frequency=seconds)
elif(choice=='6'):
skroutz = skroutz_scraper()
skroutz.save_products_to_csv()