Skip to content

Aws changes #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.pyc
.vscode/
products.json
__pycache__
geckodriver.log
.env

## env
/conda-env
35 changes: 34 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from price_scraper import scrape_amazon_search, best_deal
from flask import Flask, request, render_template, jsonify
import requests
import boto3
from botocore.exceptions import NoCredentialsError
from dotenv import load_dotenv
from datetime import datetime
import requests
import json
import os

# Set .env vars
load_dotenv()

app = Flask(__name__)

app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
Expand All @@ -18,8 +25,34 @@ def scrape():

search_term = str(request.form['test'])

now = datetime.now()
dt_str = now.strftime("%H:%M:%S %B %d, %Y ")

ACCESS_KEY = os.getenv("AWSAccessKeyId")
SECRET_KEY = os.getenv("AWSSecretKey")
BUCKET_NAME = "amazon-search-results"
FILE_NAME = dt_str + "searched_products.json"

products = scrape_amazon_search(search_term)

with open('products.json', 'w') as json_file:
json.dump(products, json_file, sort_keys=True, indent=4)

s3 = boto3.resource(
's3',
aws_access_key_id = ACCESS_KEY,
aws_secret_access_key = SECRET_KEY,
)


try:
s3.Bucket(BUCKET_NAME).upload_file("products.json", FILE_NAME)
print("Upload Successful")
except FileNotFoundError:
print("The file was not found")
except NoCredentialsError:
print("Credentials not available")

best_deal_item = best_deal(products)

#return jsonify(products)
Expand Down
2 changes: 1 addition & 1 deletion price_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def scrape_amazon_search(search_term):
# print("exception")
should_add = False

product = {"Name": name, "Price": price, "Previous price": prev_price,
product = {"Search term": search_term, "Name": name, "Price": price, "Previous price": prev_price,
"Discount": discount, "URL": link, "Prime product": prime}
if should_add:
products.append(product)
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
boto3==1.9.66
certifi==2020.11.8
chardet==3.0.4
click==7.1.2
Expand All @@ -7,8 +8,8 @@ idna==2.10
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
python-dotenv==0.15.0
requests==2.25.0
selenium==3.141.0
urllib3==1.26.2
Werkzeug==1.0.1
wincertstore==0.2
Werkzeug==1.0.1