forked from evuventures/cheaper
-
Notifications
You must be signed in to change notification settings - Fork 3
Refactored names, fixed some functions, added background process #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
96855cc
check if git ignore works
dendenso 10db992
Merge branch 'primary' of https://github.com/James-Cheaper/cheaper in…
dendenso b0ba645
refactorin
dendenso 642af11
Merge branch 'primary' of https://github.com/James-Cheaper/cheaper in…
dendenso 18cf882
shell for background service
dendenso 281d987
Merge remote-tracking branch 'origin/primary' into Create
dendenso e9cf697
refactoring, editing for best practice, and retrieving ebay item
dendenso 76c9e4d
Merge branch 'primary' of https://github.com/James-Cheaper/cheaper in…
dendenso 1506b91
Merge branch 'primary' of https://github.com/James-Cheaper/cheaper in…
dendenso f9e9d0b
resolving Abraham Forz's comments
dendenso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| from abc import ABC,abstractmethod | ||
|
|
||
| class EbayApi(ABC): | ||
| class RetailerApi(ABC): | ||
|
|
||
| @abstractmethod | ||
| def retrieve_access_token() -> str: | ||
| def retrieve_access_token(self) -> str: | ||
| """ retrieves the user access token for sandbox environment it's a long line | ||
| of text, numbers, symbols | ||
| """ | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def retrieve_ebay_response(httprequest:str,query:str) -> dict: | ||
| def retrieve_response(self,httprequest:str,query:str) -> dict: | ||
| """ retrieves a json of large data with category ids, names, parentcategorynodes """ | ||
| pass |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,31 @@ | ||
| from cheaper_main.ABC.RetailerApi import RetailerApi | ||
| import requests | ||
| import os | ||
| from generate_code_challenge import generate_code_challenge | ||
|
|
||
|
|
||
| keystring = os.getenv("etsykeystring") | ||
| sharedsecret = os.getenv("etsysharedsecret") | ||
|
|
||
| class Etsy(RetailerApi): | ||
| def retrieve_access_token(self): | ||
| # most likely this url will change and I will have a parameter set for it | ||
| # otherwise this default url will be used for testing purposes and development | ||
| try: | ||
| response = requests.post("https://api.etsy.com/v3/public/oauth/token", | ||
| headers={"Content-Type': 'application/x-www-form-urlencoded"}, | ||
| data = {"grant_type":"client_credentials", | ||
| "scope":"listings_r", | ||
| "client_id":f"{keystring}", | ||
| "code_challenge":f"{generate_code_challenge.generate_code_challenge()}", | ||
| "code_challenge_method":"S256" | ||
| } | ||
|
|
||
| ) | ||
| if(response.status_code == 200): | ||
| data = response.json() | ||
| except Exception as e: | ||
| raise e | ||
|
|
||
| def retrieve_response(self): | ||
| raise NotImplementedError |
Empty file.
This file contains hidden or 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,15 @@ | ||
| import secrets | ||
| import hashlib | ||
| import base64 | ||
|
|
||
|
|
||
| class generate_code_challenge: | ||
| # Will most likely be used only for APIs that require it | ||
| # If it gets used more than once I will make an Abstract Base Class | ||
| def generate_code_challenge() -> str: | ||
| code_client = secrets.token_urlsafe(64) | ||
| code_challenge = base64.urlsafe_b64encode(hashlib.sha256(code_client.encode()) | ||
| .digest()).rstrip(b'=').decode() | ||
| return code_challenge | ||
|
|
||
|
|
Empty file.
Empty file.
James-Cheaper marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,16 @@ | ||
| import os | ||
| from cheaper_main.ABC import RetailerApi | ||
|
|
||
| best_buy = os.getenv("bestbuysecret") | ||
|
|
||
|
|
||
| class best_buy_api(RetailerApi): | ||
|
|
||
| def retrieve_access_token(self): | ||
|
|
||
| return | ||
|
|
||
|
|
||
| def retrieve_response(self): | ||
|
|
||
| return |
This file contains hidden or 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
Empty file.
This file contains hidden or 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
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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,72 @@ | ||
| from flask import Flask, request , jsonify | ||
| import json | ||
| #import time # for testing | ||
| # i added these imports below because when i ran it it wasnt finding the folders | ||
| import sys | ||
| import os | ||
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
| from cheaper_main.Scraper.Cheaper_Scraper import CheaperScraper | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
| #python main.py will run it in the background git bash | ||
| #to stop put pm2 stop Cheaper in git bash | ||
| @app.route('/') | ||
| def scrape(): | ||
|
|
||
| # Set up the scraper for a simple legal-to-scrape website | ||
| scraper = CheaperScraper("https://books.toscrape.com", | ||
| user_agent="CheaperBot/0.1", | ||
| delay=2.0) | ||
|
|
||
| # Define which pages you want to scrape (you can use "/" for homepage) | ||
| pages = ["/"] | ||
|
|
||
| # Use the scraper to fetch and parse the pages | ||
| results = scraper.scrape(pages) | ||
|
|
||
| # Show the output in the terminal | ||
| for path, items in results.items(): | ||
| print(f"\nScraped from {path}:") | ||
| for item in items: | ||
| print("-", item) | ||
|
|
||
| # Save the output to a JSON file | ||
| #with open("output.json", "w") as f: | ||
| #json.dump(results, f, indent=2) | ||
| return jsonify(results) | ||
|
|
||
| @app.route('/api/products/search', methods=['GET']) | ||
| def ebay_search(): | ||
| try: | ||
| from api.ebay_api.EbayAPI import EbayAPI | ||
| #instantiate object | ||
| ebay_api = EbayAPI() | ||
|
|
||
| product = request.args.get('product') | ||
| #The route will look like this | ||
| # http://127.0.0.1:5000/api/products/search?product= | ||
| #after product= type any generic item to receive json like ?product=clothes | ||
| #put that in the address bar | ||
|
|
||
| print(f"product = {product}") | ||
| if not product: | ||
| return jsonify({"error": "missing ?product=parameter"}),400 | ||
| response = ebay_api.search_item(product) | ||
|
|
||
| return jsonify({ | ||
| "name": response.name, | ||
| "price": response.price, | ||
| "currency": response.currency, | ||
| "url": response.url | ||
| }) | ||
|
|
||
| except Exception as e: | ||
| print("failed to import",e) | ||
| return jsonify({"error": str(e)}), 500 | ||
|
|
||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__":# | ||
| app.run(debug=True) |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,40 @@ | ||
| #!/bin/bash | ||
|
|
||
| APP_NAME="Cheaper" | ||
| APP_FILE="main.py" | ||
| LOG_DIR="$HOME/CheaperLogs" | ||
|
|
||
| # Allow user to override PYTHON_PATH by setting it externally | ||
| if [ -z "$PYTHON_PATH" ]; then | ||
| PYTHON_PATH=$(command -v python3) | ||
| fi | ||
|
|
||
| if [ -z "$PYTHON_PATH" ]; then | ||
| PYTHON_PATH=$(command -v python) | ||
| fi | ||
|
|
||
| # Final fallback for Windows users (optional) | ||
| if [ -z "$PYTHON_PATH" ] && [ -f "/c/Users/$USERNAME/AppData/Local/Programs/Python/Python39/python.exe" ]; then | ||
| PYTHON_PATH="/c/Users/$USERNAME/AppData/Local/Programs/Python/Python39/python.exe" | ||
| fi | ||
|
|
||
| # Validate Python path | ||
| if ! "$PYTHON_PATH" --version > /dev/null 2>&1; then | ||
| echo "❌ Python not found. Please install it or set PYTHON_PATH manually." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "✅ Using Python at: $PYTHON_PATH" | ||
|
|
||
| # Create log directory | ||
| mkdir -p "$LOG_DIR" | ||
|
|
||
| # Start with PM2 | ||
| pm2 start "$APP_FILE" \ | ||
| --name "$APP_NAME" \ | ||
| --interpreter="$PYTHON_PATH" \ | ||
| --output "$LOG_DIR/out.log" \ | ||
| --error "$LOG_DIR/err.log" \ | ||
| --watch | ||
|
|
||
| pm2 save |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.