Skip to content

Commit d00e2f3

Browse files
Refactored names, fixed some functions, added background process (#36)
* check if git ignore works * refactorin * shell for background service * refactoring, editing for best practice, and retrieving ebay item * resolving Abraham Forz's comments --------- Co-authored-by: James Cacapit <jamescacapit@gmail.com>
1 parent 29e9cc4 commit d00e2f3

32 files changed

Lines changed: 198 additions & 87 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ venv/
2424
.vscode/
2525

2626
# === macOS system files ===
27-
.DS_Store
27+
*.DS_Store
2828

2929
# === Pytest and test cache ===
3030
htmlcov/
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from abc import ABC,abstractmethod
22

3-
class EbayApi(ABC):
3+
class RetailerApi(ABC):
44

55
@abstractmethod
6-
def retrieve_access_token() -> str:
6+
def retrieve_access_token(self) -> str:
77
""" retrieves the user access token for sandbox environment it's a long line
88
of text, numbers, symbols
99
"""
1010
pass
1111

1212
@abstractmethod
13-
def retrieve_ebay_response(httprequest:str,query:str) -> dict:
13+
def retrieve_response(self,httprequest:str,query:str) -> dict:
1414
""" retrieves a json of large data with category ids, names, parentcategorynodes """
1515
pass
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
from urllib.parse import urlparse
55
import logging
66
from typing import Dict, List, Optional
7-
from webscraper.ABC.base_scraper import BaseScraper
8-
from webscraper.src.robot_check import RoboCheck
9-
from webscraper.api.interface import ScraperAPIInterface
10-
from webscraper.src.fetch_utils import cached_get
7+
from cheaper_main.ABC.base_scraper import BaseScraper
8+
from cheaper_main.Scraper.robot_check import RoboCheck
9+
from cheaper_main.Scraper.fetch_utils import cached_get
1110
from functools import lru_cache
12-
from webscraper.api.EbayAPI import EbayItem
1311

1412

1513

1614

17-
class CheaperScraper(BaseScraper, ScraperAPIInterface):
15+
class CheaperScraper(BaseScraper):
1816
def __init__(self, base_url: str = "", user_agent: str = "CheaperBot/0.1", delay: float = 2.0) -> None:
1917
"""Initialize the scraper with base parameters.
2018

cheaper_main/api/Etsy/EtsyApi.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from cheaper_main.ABC.RetailerApi import RetailerApi
2+
import requests
3+
import os
4+
from generate_code_challenge import generate_code_challenge
5+
6+
7+
keystring = os.getenv("etsykeystring")
8+
sharedsecret = os.getenv("etsysharedsecret")
9+
10+
class Etsy(RetailerApi):
11+
def retrieve_access_token(self):
12+
# most likely this url will change and I will have a parameter set for it
13+
# otherwise this default url will be used for testing purposes and development
14+
try:
15+
response = requests.post("https://api.etsy.com/v3/public/oauth/token",
16+
headers={"Content-Type': 'application/x-www-form-urlencoded"},
17+
data = {"grant_type":"client_credentials",
18+
"scope":"listings_r",
19+
"client_id":f"{keystring}",
20+
"code_challenge":f"{generate_code_challenge.generate_code_challenge()}",
21+
"code_challenge_method":"S256"
22+
}
23+
24+
)
25+
if(response.status_code == 200):
26+
data = response.json()
27+
except Exception as e:
28+
raise e
29+
30+
def retrieve_response(self):
31+
raise NotImplementedError

0 commit comments

Comments
 (0)