diff --git a/README.md b/README.md index 9220fae..60fcde1 100644 --- a/README.md +++ b/README.md @@ -24,17 +24,22 @@ This repo contains scripts for the following sites: - GOAT - eBay - Depop -- BUMP ## How to use These scripts can be run via the command line. The general structure is as follows +#### Windows ``` python [script name] [argument 1] [argument 2] ``` +#### Linux/Mac +``` +python3 [script name] [argument 1] [argument 2] +``` + With most of the tools, you will only need to pass 1 argument, with the exception of `eBayBot.py` which takes 2. An example of how to pass arguments is shown below: ``` @@ -47,3 +52,4 @@ An example is shown below: ``` python eBayBot.py current 'yeezy 350 creams' ``` +including the single quotations around the item is important to the accuracy of your results. diff --git a/src/BumpBot.py b/src/BumpBot.py deleted file mode 100644 index cd80f4f..0000000 --- a/src/BumpBot.py +++ /dev/null @@ -1,38 +0,0 @@ -import requests as rq -from bs4 import BeautifulSoup -import statistics -import sys - - -def get_current_prices(item): - current_listings = [] - try: - url = 'https://sobump.com/search?q=' + item.replace(' ', '%20') - html = rq.get(url=url) - soup = BeautifulSoup(html.text, 'html.parser') - - for item in soup.find_all('div', - attrs={'class': lambda e: e.startswith('_2nKHUq_PMQN8oVVOxfpkmd') if e else False}): - print(1) - price = item.find('div', {'class': '_1x9zBkhxPTMCCPbDAx9sB_'}).text - current_listings.append(float(price.replace('€', '').replace('£', ''))) - return current_listings - except Exception as e: - print(e) - return 'Exception' - - -def summary_of_prices(data): - print('Max: ', max(data)) - print('Min: ', min(data)) - print('Average: ', sum(data)/len(data)) - print('Standard Deviation: ', statistics.stdev(data)) - print('Number of listings: ', len(data)) - - -if __name__ == '__main__': - output = get_current_prices(sys.argv[1]) - if output != 'Exception' and output != []: - summary_of_prices(output) - else: - print('Please check first argument variable') \ No newline at end of file diff --git a/src/DepopBot.py b/src/DepopBot.py index 85e3868..14361ea 100644 --- a/src/DepopBot.py +++ b/src/DepopBot.py @@ -8,11 +8,13 @@ def scrape_site(item): current_listings = [] try: - url = f'https://webapi.depop.com/api/v1/search/?what={item.replace(" ", "%20")}&country=gb&limit=200' + #change country_code to your countries two letter code (eg. gb for great britain) + country_code = 'gb' + url = f'https://webapi.depop.com/api/v2/search/products/?what={item.replace(" ", "+")}&itemsPerPage=40&country={country_code}&sort=relevance' html = rq.get(url=url) output = json.loads(html.text) for i in output['products']: - price = i['price']['price_amount'] + price = i['price']['priceAmount'] current_listings.append(float(price)) return current_listings except Exception as e: @@ -28,11 +30,14 @@ def clean_data(data): def summary_of_prices(data): - print('Max: ', max(data)) - print('Min: ', min(data)) - print('Average: ', sum(data) / len(data)) - print('Standard Deviation: ', statistics.stdev(data)) - print('Number of listings: ', len(data)) + try: + print('Max: ', max(data)) + print('Min: ', min(data)) + print('Average: ', (sum(data) / len(data)).__round__(2)) + print('Standard Deviation: ', statistics.stdev(data).__round__(2)) + print('Number of listings: ', len(data)) + except ValueError: + print('Not enough listings to calculate statistics') if __name__ == '__main__': diff --git a/src/eBayBot.py b/src/eBayBot.py index c64bebb..4ffd4ef 100644 --- a/src/eBayBot.py +++ b/src/eBayBot.py @@ -15,7 +15,8 @@ def get_current_prices(item): try: current_listings.append(float(price.replace('£', ''))) except: - price = price.replace(' to', '').replace('£', '') + #replaces dollar sign and pound sign + price = price.replace(' to', '').replace('£', '').replace(',', '').replace('$', '') price = price.split() prices = [float(item) for item in price] current_listings.append(statistics.mean(prices)) @@ -29,7 +30,9 @@ def get_sold_prices(item): sold_listings = [] try: - url = f'https://www.ebay.co.uk/sch/i.html?_nkw={item.replace(" ", "+")}&_ipg=200&rt=nc&LH_Sold=1' + #to use USA ebay replace .co.uk with .com + base_url = 'https://www.ebay.co.uk' + url = f'{base_url}/sch/i.html?_nkw={item.replace(" ", "+")}&_ipg=200&rt=nc&LH_Sold=1' html = rq.get(url=url) soup = BeautifulSoup(html.text, 'html.parser') @@ -38,7 +41,7 @@ def get_sold_prices(item): try: sold_listings.append(float(price.replace('£', ''))) except: - price = price.replace(' to', '').replace('£', '') + price = price.replace(' to', '').replace('£', '').replace(',', '').replace('$', '') price = price.split() sold_listings.append(statistics.mean([float(item) for item in price])) return sold_listings @@ -50,8 +53,8 @@ def get_sold_prices(item): def summary_of_prices(data): print('Max: ', max(data)) print('Min: ', min(data)) - print('Average: ', sum(data) / len(data)) - print('Standard Deviation: ', statistics.stdev(data)) + print('Average: ', (sum(data) / len(data)).__round__(2)) + print('Standard Deviation: ', statistics.stdev(data).__round__(2)) print('Number of listings: ', len(data)) @@ -67,4 +70,4 @@ def summary_of_prices(data): if output != 'Exception' and output != []: summary_of_prices(output) else: - print('Please check second argument variable') + print('Please check second argument variable') \ No newline at end of file