-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8d7f912
Showing
6 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e65ac427", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from flask import Flask, request\n", | ||
"import pandas as pd\n", | ||
"import numpy as np\n", | ||
"import smtplib\n", | ||
"import getpass\n", | ||
"app = Flask(__name__)\n", | ||
"\n", | ||
"@app.route('/submit', methods=['POST'])\n", | ||
"def submit():\n", | ||
" email = request.json['email']\n", | ||
" price = request.json['price']\n", | ||
" \n", | ||
" print('Email:', email)\n", | ||
" print('Price:', price)\n", | ||
" data = pd.read_csv(r\"C:\\\\Users\\\\DELL\\\\GPTEXTENSION\\\\data.csv\",index_col=0)\n", | ||
"# print(column_array)\n", | ||
"# print(column_array[-2])\n", | ||
"# print(column_array[-1])\n", | ||
" dat = np.array(data)\n", | ||
" current_price=dat[len(dat)-1]\n", | ||
"# print(required_price)\n", | ||
" if(int(price) > int(current_price)):\n", | ||
" HOST = \"smtp-mail.outlook.com\"\n", | ||
" PORT = 587\n", | ||
"\n", | ||
" FROM_EMAIL = \"<email>\"\n", | ||
" TO_EMAIL = email\n", | ||
" PASSWORD = \"<password>\"\n", | ||
"\n", | ||
" MESSAGE = \"\"\"Subject: <add mail subject here>\n", | ||
" <add mail content here>\"\"\"\n", | ||
"\n", | ||
" smtp = smtplib.SMTP(HOST, PORT)\n", | ||
"\n", | ||
" status_code, response = smtp.ehlo()\n", | ||
" print(f\"[*] Echoing the server: {status_code} {response}\")\n", | ||
"\n", | ||
" status_code, response = smtp.starttls()\n", | ||
" print(f\"[*] Starting TLS connection: {status_code} {response}\")\n", | ||
"\n", | ||
" status_code, response = smtp.login(FROM_EMAIL, PASSWORD)\n", | ||
" print(f\"[*] Logging in: {status_code} {response}\")\n", | ||
"\n", | ||
" smtp.sendmail(FROM_EMAIL, TO_EMAIL, MESSAGE)\n", | ||
" smtp.quit()\n", | ||
" return { 'success': True }\n", | ||
"\n", | ||
"if __name__ == '__main__':\n", | ||
" app.run(debug=True)\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# app.py | ||
from selenium.webdriver.chrome.service import Service | ||
from selenium.webdriver.chrome.options import Options | ||
from selenium.webdriver.common.keys import Keys | ||
from selenium.webdriver import Chrome | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.common.by import By | ||
# import time | ||
import json | ||
import requests | ||
import re | ||
from bs4 import BeautifulSoup | ||
import plotly.graph_objs as go | ||
from flask import Flask, request, send_file | ||
from flask import Flask, request, jsonify, make_response | ||
import io | ||
import pandas as pd | ||
|
||
|
||
service = Service('/home/uday/Chromedriver') | ||
service.start() | ||
options = Options() | ||
options.add_argument('--no-sandbox') | ||
options.add_argument('--disable-dev-shm-usage') | ||
options.add_argument('--headless') | ||
browser = Chrome(service=service, options=options) | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/generate_graph') | ||
def generate_graph(): | ||
# Get product URL from request | ||
product_url = request.args.get('product_url') | ||
# print(f"Product URL :- {product_url}") | ||
|
||
browser.get('https://www.pricebefore.com/') | ||
print("Ok") | ||
|
||
search_box = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'search-box-home'))) | ||
search_box.send_keys(product_url) | ||
search_box.send_keys(Keys.RETURN) | ||
|
||
# time.sleep(7) | ||
|
||
new_url = browser.current_url | ||
# print('New URL:', new_url) | ||
|
||
r = requests.get(new_url) | ||
htmlcontent = r.content | ||
|
||
soup = BeautifulSoup(htmlcontent,'html.parser') | ||
title = soup.title | ||
# print(title) | ||
|
||
paras = soup.find_all('canvas') | ||
|
||
paras1 = None | ||
scripts = soup.find_all('script') | ||
for script in scripts: | ||
if 'var data' in script.text: | ||
paras1 = script.text | ||
break | ||
|
||
if paras1: | ||
match = re.search(r'var\s+data\s*=\s*(.*?);', paras1) | ||
if match: | ||
data_str = match.group(1) | ||
# print(data_str) | ||
data = json.loads(data_str) | ||
dates_list = data["dates"] | ||
prices_list = data["prices"] | ||
df = pd.DataFrame({'col1': dates_list, 'col2': prices_list}) | ||
df.to_csv('output.csv',index=False) | ||
|
||
return generate_and_return_graph(dates_list, prices_list) | ||
|
||
def generate_and_return_graph(x_data, y_data): | ||
trace = go.Scatter(x=x_data, y=y_data, mode='lines+markers') | ||
fig = go.Figure(data=[trace]) | ||
fig.update_layout(hovermode='x') | ||
|
||
# Generate the plot using plotly | ||
fig.show() | ||
|
||
# Save the plot to a PNG file | ||
buf = io.BytesIO() | ||
fig.write_image(buf, format='png') | ||
buf.seek(0) | ||
# Return the file as a Flask response | ||
return send_file(buf, mimetype='image/png') | ||
|
||
if __name__ == '__main__': | ||
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
chrome.browserAction.onClicked.addListener(function(tab) { | ||
chrome.tabs.executeScript({ | ||
file: 'popup.js' | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"manifest_version": 2, | ||
"name": "Price History Graph", | ||
"version": "1.0", | ||
"description": "Displays a graph of price history for a product.", | ||
"browser_action": { | ||
"default_title": "Price History Graph", | ||
"default_popup": "popup.html" | ||
}, | ||
"permissions": [ | ||
"activeTab", | ||
"http://localhost:5000/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Product Graph</title> | ||
<style> | ||
*{ | ||
background-color: white; | ||
} | ||
</style> | ||
</head> | ||
<body bgcolor=""> | ||
<h1>Product Price History Graph</h1> | ||
<img id="graph" src="" /> | ||
<script src="popup.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
var graph = document.getElementById('graph'); | ||
var detailsForm = document.getElementById('detailsForm'); | ||
detailsForm.addEventListener('submit', function(event) { | ||
event.preventDefault(); | ||
var email = detailsForm.email.value; | ||
var price = detailsForm.price.value; | ||
console.log('Email:', email); | ||
console.log('Price:', price); | ||
}); | ||
|
||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { | ||
var product_url = tabs[0].url; | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', 'http://localhost:5000/generate_graph?product_url=' + encodeURIComponent(product_url), true); | ||
xhr.responseType = 'blob'; | ||
xhr.onload = function(e) { | ||
if (this.status == 200) { | ||
var blob = this.response; | ||
var objectURL = URL.createObjectURL(blob); | ||
graph.src = objectURL; | ||
} | ||
}; | ||
xhr.send(); | ||
}); | ||
}); |