-
Notifications
You must be signed in to change notification settings - Fork 0
/
JabongPriceTracker.py
96 lines (77 loc) · 2.34 KB
/
JabongPriceTracker.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
import lxml.html as html
import requests
import time
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from robobrowser import RoboBrowser
from requests import Session
session = Session()
session.verify = False
url = input("Enter the url : ")
br = RoboBrowser(parser = 'lxml')
import re
br.open(url)
brand = str(br.select('span.brand')[0])
pat = r'.*>(.*)<.*'
res = re.match(pat, brand)
brand = res.group(1)
product = str(br.select('span.product-title')[0])
res = re.match(pat, product)
product = res.group(1)
mrp = str(br.select('span.standard-price')[1])
res = re.match(pat, mrp)
mrp = int(res.group(1))
sp = str(br.select('span.actual-price')[0])
res = re.match(pat, sp)
sp = int(res.group(1))
wallet = str(br.select('span.wallet-title')[0])
res = re.match(pat, wallet)
wallet = res.group(1)
offer = str(br.select('span.wallet-desc')[0])
res = re.match(pat, offer)
offer = res.group(1)
print('Product Brand : %s'%(brand))
print('Product Description : %s'%(product))
print('MRP of the product : %d'%(mrp))
print('Current Selling Price : %d'%(sp))
print('%s %s'%(wallet,offer))
print('-------------------------Tracking Started-------------------------')
xaxis = []
actual_price = []
selling_price = []
matplotlib.rc('font', size=8)
matplotlib.rc('font', family='sans-serif')
c=1
while(c<48):
br.open(url)
mrp = str(br.select('span.standard-price')[1])
res = re.match(pat, mrp)
mrp = int(res.group(1))
sp = str(br.select('span.actual-price')[0])
res = re.match(pat, sp)
sp = int(res.group(1))
wallet = str(br.select('span.wallet-title')[0])
res = re.match(pat, wallet)
wallet = res.group(1)
offer = str(br.select('span.wallet-desc')[0])
res = re.match(pat, offer)
offer = res.group(1)
actual_price.append(mrp)
selling_price.append(sp)
t = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
xaxis.append(t)
print('Current Price : %d %s %s Time : %s' %(sp, wallet, offer, t))
time.sleep(900)
c+=1
x_pos = np.arange(len(xaxis))
plt.title('Price Variation')
plt.xlabel('Time')
plt.ylabel('Price')
plt.xticks(x_pos, xaxis, rotation=90)
plt.plot(xaxis, actual_price , label='original')
plt.plot(xaxis, selling_price , label='discounted', marker='o')
plt.legend()
plt.grid(color='lightblue', linestyle='-.')
plt.tight_layout()
plt.savefig('output.png', dpi=600)