-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAPP.py
More file actions
92 lines (74 loc) · 2.57 KB
/
Copy pathAPP.py
File metadata and controls
92 lines (74 loc) · 2.57 KB
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
import matplotlib
matplotlib.use('TkAgg')
from MobileCrawler import *
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import *
from tkinter import ttk
class mclass:
def __init__(self, window):
self.window = window
# URL Entry Box
self.urlBox = ttk.Entry(window)
self.urlBox.grid(row=0, column=1, columnspan=10, pady=5, padx=5, sticky=NSEW)
self.urlBox.delete(0, END)
self.urlBox.insert(0, '')
# SUBMIT Button
self.submitBtn = ttk.Button(window, text='Submit')
self.submitBtn.bind('<Button-1>', urlTK)
self.submitBtn.grid(row=1, column=4, columnspan=4, sticky=NSEW)
def urlTK(self):
url = self.urlBox.get()
try:
self.asin = asinGeturl(url)
except:
self.asin = asinGetRX(url)
print('ASIN:', self.asin)
return self.asin
def asinGeturl(self):
""" This function extracts the product's unique ASIN from an amazon.com url. """
self.asin = self.url.split('/')
for i in self.asin:
self.asinNum = i.strip()
if len(self.asinNum) != 10:
continue
else:
self.asinN = self.asinNum
return self.asinN
# Get Page HTML Code
def pageGet(self):
""" This function requests a webpage from the URL provided by the user. """
headers = {
'User-Agent': generate_user_agent(device_type='smartphone')
}
self.url = 'https://www.amazon.com/gp/product/' + self.asin
self.page = requests.get(self.url, timeout=5, headers=headers)
self.soup = bs(self.page.text, 'lxml')
print('Page Status:', self.page.status_code)
return self.soup
# Get Prices
def priceGetAll(self):
""" Combines existing functions into a single one. """
try:
self.price = priceGetMost(self.soup)
except:
self.price = priceGetSome(self.soup)
print('Price: $' + str(self.price))
return self.price
def plot(self):
df = pd.read_csv('CSVs/' + self.ASIN + ".csv")
# set axis
x = df["Date"]
y = df["Price"]
# Plot Data
plt = Figure(figsize=(7, 4))
plt.plot(x, y)
# Add Labels
plt.title("\n".join(wrap(name, 40)), fontsize=18)
plt.xlabel('Date', fontsize=14)
plt.xticks(rotation=90, fontsize=8)
plt.ylabel('Price ($)', fontsize=14)
window = Tk()
start = mclass(window)
window.mainloop()