-
Notifications
You must be signed in to change notification settings - Fork 5
ORM created now #48
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
johnnvij
wants to merge
10
commits into
evuventures:primary
Choose a base branch
from
James-Cheaper:orm_setup
base: primary
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ORM created now #48
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
df869db
no secrets
dendenso b25bd60
removed cached files and ignore compilation removed testing method
dendenso 59249db
removing testing method in main
dendenso 50414e4
reset pyc and pycache files
dendenso 37ee253
place files back in
dendenso 534f0d6
direct commit
dendenso 83a4e06
Merge branch 'primary' into EbaySearch
James-Cheaper c6a4df5
Merge pull request #6 from James-Cheaper/EbaySearch
James-Cheaper 54265bb
Merge branch 'primary' of https://github.com/James-Cheaper/cheaper in…
dendenso fbe2803
Orms created UserAccount Product models with prod list view
johnnvij 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
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,3 @@ | ||
| *.env | ||
| *.pyc | ||
| __pycache__/ |
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,14 @@ | ||
| { | ||
| "python.analysis.extraPaths": [ | ||
| "./webscraper/ABC" | ||
| ], | ||
| "python.testing.unittestArgs": [ | ||
| "-v", | ||
| "-s", | ||
| "./webscraper", | ||
| "-p", | ||
| "*test*.py" | ||
| ], | ||
| "python.testing.pytestEnabled": false, | ||
| "python.testing.unittestEnabled": true | ||
| } |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
55 changes: 55 additions & 0 deletions
55
accounts/migrations/0002_remove_product_name_remove_product_source_url_and_more.py
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,55 @@ | ||
| # Generated by Django 5.2 on 2025-05-05 19:14 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("accounts", "0001_initial"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RemoveField( | ||
| model_name="product", | ||
| name="name", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="product", | ||
| name="source_url", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="useraccount", | ||
| name="password", | ||
| ), | ||
| migrations.AddField( | ||
| model_name="product", | ||
| name="product_name", | ||
| field=models.CharField(default="Unnamed Product", max_length=255), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="product", | ||
| name="url", | ||
| field=models.TextField(default="https://example.com"), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="product", | ||
| name="user", | ||
| field=models.ForeignKey( | ||
| null=True, | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| to="accounts.useraccount", | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="useraccount", | ||
| name="password_hash", | ||
| field=models.CharField(default="defaultpass123", max_length=100), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="product", | ||
| name="price", | ||
| field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10), | ||
| ), | ||
| ] |
Binary file not shown.
Binary file not shown.
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,3 +1,10 @@ | ||
| from django.shortcuts import render | ||
| from django.http import JsonResponse | ||
| from .models import Product | ||
|
|
||
| def product_list(request): | ||
| products = Product.objects.all() | ||
| data = [{"name": p.product_name, "price": float(p.price), "url": p.url} for p in products] | ||
| return JsonResponse(data, safe=False) | ||
|
|
||
| # Create your views here. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Binary file not shown.
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 @@ | ||
| from abc import ABC,abstractmethod | ||
|
|
||
| class EbayApi(ABC): | ||
|
|
||
| @abstractmethod | ||
| def retrieve_access_token() -> 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: | ||
| """ retrieves a json of large data with category ids, names, parentcategorynodes """ | ||
| pass |
Binary file not shown.
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,55 @@ | ||
| import requests | ||
| from requests.auth import HTTPBasicAuth | ||
| from dotenv import load_dotenv | ||
| import os | ||
|
|
||
|
|
||
| load_dotenv() #initialize | ||
|
|
||
| class EbayAPI: | ||
|
|
||
| client_secret_key = os.getenv("clientsecret") | ||
| client_id_key = os.getenv("clientid") | ||
|
|
||
| get_user_key = HTTPBasicAuth(client_id_key, client_secret_key) | ||
|
|
||
|
|
||
| def retrieve_access_token(): | ||
| try: | ||
| response = requests.post("https://api.sandbox.ebay.com/identity/v1/oauth2/token", | ||
| headers = {"Content-Type":"application/x-www-form-urlencoded"}, | ||
| data = { | ||
| "grant_type": "client_credentials", | ||
| "scope": "https://api.ebay.com/oauth/api_scope" | ||
| }, | ||
| auth=EbayAPI.get_user_key | ||
| ) | ||
| access_token = response.json().get("access_token") | ||
| status_code = response.status_code | ||
| if(status_code == 404): | ||
| raise Exception("404 error here") | ||
| return access_token | ||
| except Exception as e: | ||
| raise e | ||
|
|
||
| def retrieve_ebay_response(httprequest:str,query:str): | ||
| auth = EbayAPI.retrieve_access_token() | ||
| try: | ||
| response = requests.get(httprequest, | ||
| headers={ | ||
| "Authorization": f"Bearer {auth}", | ||
| "Content-Type": "application/json" | ||
| }, | ||
| params= { | ||
| "q": query, | ||
| "category_tree_id": 0 | ||
| } | ||
| ) | ||
| status_code = response.status_code | ||
| if(status_code == 404): | ||
| raise Exception("not found 404 error") | ||
|
|
||
| return response.json() | ||
| except Exception as e: | ||
| raise e | ||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,35 @@ | ||
| import unittest | ||
| from unittest.mock import patch,Mock | ||
| import requests | ||
| from webscraper.api.EbayAPI import EbayAPI | ||
|
|
||
| class EbayTestApi(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.EbayAPI = EbayAPI | ||
|
|
||
|
|
||
| def test_retrieve_access_token(self): | ||
| self.EbayAPI.retrieve_access_token() | ||
| self.assertEqual(type(self.EbayAPI.retrieve_access_token()),str) | ||
|
|
||
| @patch("webscraper.api.EbayAPI.requests.post") | ||
| def test_retrieve_access_token_invalid(self,mock_post): | ||
| mock_response = Mock() | ||
| mock_response.status_code = 404 | ||
| mock_response.json.return_value ={"error": "not found"} | ||
| mock_post.return_value = mock_response | ||
|
|
||
| with self.assertRaises(Exception): | ||
| self.EbayAPI.retrieve_access_token() | ||
|
|
||
|
|
||
|
|
||
| @patch("webscraper.api.EbayAPI.requests.get") | ||
| def test_retrieve_ebay_response_invalid(self,mock_get): | ||
| self.EbayAPI.retrieve_ebay_response("https://test","item") | ||
| self.assertRaises(Exception) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
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,4 +1,3 @@ | ||
|
|
||
| import json | ||
| #import time // for testing | ||
| # i added htese imports below becasue when i ran it it wasnt finding the folders | ||
|
|
@@ -9,16 +8,19 @@ | |
|
|
||
|
|
||
| def main(): | ||
|
|
||
|
|
||
|
|
||
|
|
||
| # 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) | ||
|
|
||
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue: The line results = CheaperScraper.scraper.scrape(pages) incorrectly attempts to access scraper as a class variable. Suggestion: results = scraper.scrape(pages) already correctly invokes the instance method. |
||
| results = CheaperScraper.scraper.scrape(pages) | ||
|
|
||
| # Show the output in the terminal | ||
| for path, items in results.items(): | ||
|
|
||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concern: Using a default plaintext password ('defaultpass123') is insecure.
Suggestion: Avoid setting a default password, especially one that’s hardcoded and predictable. If necessary for testing, override it in fixtures or during test setup instead.