Skip to content

Commit

Permalink
Merge pull request #111 from Crinibus/dev
Browse files Browse the repository at this point in the history
Update README and refactor a function
  • Loading branch information
Crinibus authored Oct 15, 2020
2 parents fdfdecc + ff9e622 commit 5c8b59b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Table of contents
- [Contributing](#contributing)
- [First setup](#first-setup)
- [Tech scraper](#tech-scraper)
- [Scrape products](#scrape-products)
Expand All @@ -10,6 +11,11 @@

<br/>

## Contributing <a name="contributing"></a>
Feel free to fork the project and create a pull request with new features or refactoring of the code. Also feel free to make a issue with problems or suggestions to a new feature.

<br/>

## First setup <a name="first-setup"></a>
First make sure you have the modules, run this in the terminal:

Expand Down
44 changes: 18 additions & 26 deletions tech_scraper/add_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,32 +162,24 @@ def save_json(category, product_name):

def find_domain(domain):
"""Return the domain name of the url. Used to determine which class to call in scrape_link.py"""
if domain == domains['komplett']:
return 'Komplett'
elif domain == domains['proshop']:
return 'Proshop'
elif domain == domains['computersalg']:
return 'Computersalg'
elif domain == domains['elgiganten']:
return 'Elgiganten'
elif domain == domains['avxperten']:
return 'AvXperten'
elif domain == domains['av-cables']:
return 'AvCables'
elif domain == domains['amazon']:
return 'Amazon'
elif domain == domains['ebay']:
return 'eBay'
elif domain == domains['power']:
return 'Power'
elif domain == domains['expert']:
return 'Expert'
elif domain == domains['mm-vision']:
return 'MMVision'
elif domain == domains['coolshop']:
return 'Coolshop'
elif domain == domains['sharkgaming']:
return 'Sharkgaming'

class_domains = {
"www.komplett.dk": "Komplett",
"www.proshop.dk": "Proshop",
"www.computersalg.dk": "Computersalg",
"www.elgiganten.dk": "Elgiganten",
"www.avxperten.dk": "AvXperten",
"www.av-cables.dk": "AvCables",
"www.amazon.com": "Amazon",
"www.ebay.com": "eBay",
"www.power.dk": "Power",
"www.expert.dk": "Expert",
"www.mm-vision.dk": "MMVision",
"www.coolshop.dk": "Coolshop",
"sharkgaming.dk": "Sharkgaming",
}

return class_domains[domain]


def add_to_scraper(category, link, url_domain):
Expand Down
20 changes: 16 additions & 4 deletions tech_scraper/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ def __init__(self, category, URL):
try:
self.get_response()
except Exception as err:
self.logger.error(f'Failed in method "{self.__class__.__name__}.get_response()": {err}', exc_info=True)
self.logger.error(
f'Failed in method "{self.__class__.__name__}.get_response()": {err}',
exc_info=True
)

try:
self.get_info()
except Exception as err:
self.logger.error(f'Failed in method "{self.__class__.__name__}.get_info()": {err}', exc_info=True)
self.logger.error(
f'Failed in method "{self.__class__.__name__}.get_info()": {err}',
exc_info=True
)

self.name = change_æøå(change_name(self.name))
self.date = str(datetime.today().strftime('%Y-%m-%d'))
Expand All @@ -58,7 +64,10 @@ def __init__(self, category, URL):
try:
self.save_record()
except Exception as err:
self.logger.error(f'Failed in method "{self.__class__.__name__}.save_record()": {err}', exc_info=True)
self.logger.error(
f'Failed in method "{self.__class__.__name__}.save_record()": {err}',
exc_info=True
)

def get_info(self): # gets overwritten
"""Get name and price of product."""
Expand Down Expand Up @@ -225,7 +234,10 @@ def change_name(name):


def change_æøå(name):
"""Change the letters æ, ø and å to international letters to avoid unicode and return the new name."""
"""
Change the letters æ, ø and å to international letters to avoid unicode and
return the new name.
"""
replace_letters = {
"æ": "ae",
"ø": "oe",
Expand Down

0 comments on commit 5c8b59b

Please sign in to comment.