From 3cb70f62336bbe5c7c9ae738d6fc5f682420d846 Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Sat, 10 Apr 2021 00:40:12 +0200 Subject: [PATCH 01/10] Add documentation for new argument "--visualize-name" and fix typos --- README.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cefd8c7f..0535d6ef 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ python3 main.py -a -c -u -c -u **OBS**: The category can only be one word, so add a underscore instead of a space if needed.
**OBS**: The url must have the "https://" part.
-**OBS**: If an error occures when adding a product, then the error might happen because the url has a "&" in it, when this happens then just put quotation mark around the url. This should solve the problem. If this doesn't solve the problem then summit a issue.
+**OBS**: If an error occures when adding a product, then the error might happen because the url has a "&" in it, when this happens then just put quotation marks around the url. This should solve the problem. If this doesn't solve the problem then summit a issue.

@@ -147,7 +147,7 @@ To visualize your data, just run main.py with the ```-v``` or ```--visualize``` - ```-va``` or ```--visualize-all``` to visualize all your products - ```-vc [ [ ...]]``` or ```--visualize-category [ [ ...]]``` to visualize all products in one or more categories - ```-id [ [ ...]]``` or ```--visualize-id [ [ ...]]``` to visualize one or more products with the specified id(s) - +- ```-vn [ [ ...]]``` or ```--visualize-name [ ...]]``` to visualize one or more products with the specified name(s) ### Command examples @@ -178,7 +178,22 @@ To show graphs for all products in one category, run the following command where python3 main.py -v -vc ``` -For multiple categories, just add another flag, like so: +For multiple categories, just add another category, like so: ``` python3 main.py -v -vc ``` + + +**Show graps for products with a specific name** + +To show graphs for product(s) with a specific name, run the following command where `````` is the name of the product(s) you want graphs for: +``` +python3 main.py -v -vn +``` + +For multiple products with different names, just add another name, like so: +``` +python3 main.py -v -vn +``` + +If the name of a product has multiple words in it, then just add quotation marks around the name. From baa89971dc3d0ce004dc304d0724fcc491b01375 Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Sat, 10 Apr 2021 00:42:42 +0200 Subject: [PATCH 02/10] Update Copyright to 2021 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index e90df8a5..6fd18d84 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Crinibus +Copyright (c) 2021 Crinibus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 916d8989f066e1cb1c269eea3d33261f017aad7d Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Sat, 10 Apr 2021 18:15:40 +0200 Subject: [PATCH 03/10] Add print statement in function "visualize" --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index cf461dd6..cb5cf075 100644 --- a/main.py +++ b/main.py @@ -76,6 +76,7 @@ def add_products(args): def visualize(args): + print("Visualizing...") if args.show_all: scraper.show_all_products() From 33fd34d3185f5359dcb9033988f6df76f2bb408f Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Sat, 10 Apr 2021 18:18:26 +0200 Subject: [PATCH 04/10] Add print statements in every 'show_..' function --- scraper/visualize.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scraper/visualize.py b/scraper/visualize.py index b1f5c380..8422ac79 100644 --- a/scraper/visualize.py +++ b/scraper/visualize.py @@ -4,6 +4,7 @@ def show_id(id: str) -> None: + print(f"Visualizing product with id: {id}") data = format_data() for category_name, category_info in data.items(): @@ -34,6 +35,7 @@ def show_id(id: str) -> None: def show_category(category: str) -> None: + print(f"Visualizing products in category: {category}") data = format_data() for category_name, category_info in data.items(): @@ -64,6 +66,7 @@ def show_category(category: str) -> None: def show_name(name: str) -> None: + print(f"Visualizing product with name: {name}") data = format_data() for category_name, category_info in data.items(): @@ -94,6 +97,7 @@ def show_name(name: str) -> None: def show_all_products() -> None: + print("Visualizing all products") data = format_data() for category_name, category_info in data.items(): From bbb841cd58273fa856211a33443fe928b23041fd Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Sat, 10 Apr 2021 18:26:57 +0200 Subject: [PATCH 05/10] test commit --- scraper/visualize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scraper/visualize.py b/scraper/visualize.py index 8422ac79..f8edcef1 100644 --- a/scraper/visualize.py +++ b/scraper/visualize.py @@ -7,6 +7,7 @@ def show_id(id: str) -> None: print(f"Visualizing product with id: {id}") data = format_data() + # test for category_name, category_info in data.items(): for product_name, product_info in category_info.items(): for website_name, website_info in product_info.items(): From 864cd0f50b354033d8fadbb066f8961d754ead6f Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Sat, 10 Apr 2021 18:27:22 +0200 Subject: [PATCH 06/10] test commit --- scraper/visualize.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scraper/visualize.py b/scraper/visualize.py index f8edcef1..8422ac79 100644 --- a/scraper/visualize.py +++ b/scraper/visualize.py @@ -7,7 +7,6 @@ def show_id(id: str) -> None: print(f"Visualizing product with id: {id}") data = format_data() - # test for category_name, category_info in data.items(): for product_name, product_info in category_info.items(): for website_name, website_info in product_info.items(): From 79903230aaa272e226516639508892a10049374c Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Sun, 11 Apr 2021 23:54:21 +0200 Subject: [PATCH 07/10] Small fix to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0535d6ef..c5a0da61 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ pip3 install -r requirements.txt ## Start from scratch -If you want to start from scratch with no data in the records.json file, then just run the following command: +If you want to start from scratch with no data in the records.json and products.csv files, then just run the following command: ``` python3 main.py --hard-reset ``` From 3dee58a6f44ea8782bad600f885b8c5d259edf48 Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Mon, 12 Apr 2021 22:29:34 +0200 Subject: [PATCH 08/10] Replace static method "Filemanager.get_root_path" with class field "Filemanage.root_path" --- main.py | 4 ++-- scraper/filemanager.py | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index cb5cf075..707cd8fe 100644 --- a/main.py +++ b/main.py @@ -119,8 +119,8 @@ def hard_reset(): if __name__ == "__main__": logging.config.fileConfig( - fname=f"{scraper.Filemanager.get_root_path()}/scraper/logging.ini", - defaults={"logfilename": f"{scraper.Filemanager.get_root_path()}/scraper/logfile.log"} + fname=f"{scraper.Filemanager.root_path}/scraper/logging.ini", + defaults={"logfilename": f"{scraper.Filemanager.root_path}/scraper/logfile.log"} ) main() diff --git a/scraper/filemanager.py b/scraper/filemanager.py index 504c8c97..5698efcd 100644 --- a/scraper/filemanager.py +++ b/scraper/filemanager.py @@ -6,10 +6,8 @@ class Filemanager: - @staticmethod - def get_root_path() -> str: - """Return root path of this repository""" - return pathlib.Path(__file__).parent.parent.absolute() + # root path of this repository + root_path = pathlib.Path(__file__).parent.parent.absolute() @staticmethod def read_json(filename: str) -> dict: @@ -36,20 +34,20 @@ def clear_csv(filename: str): @staticmethod def get_record_data() -> dict: data = Filemanager.read_json( - f"{Filemanager.get_root_path()}/scraper/records.json" + f"{Filemanager.root_path}/scraper/records.json" ) return data @staticmethod def save_record_data(data: dict) -> None: Filemanager.write_json( - f"{Filemanager.get_root_path()}/scraper/records.json", data + f"{Filemanager.root_path}/scraper/records.json", data ) @staticmethod def get_products_data() -> pd.DataFrame: df = pd.read_csv( - f"{Filemanager.get_root_path()}/scraper/products.csv", sep=",", header=0 + f"{Filemanager.root_path}/scraper/products.csv", sep=",", header=0 ) return df @@ -57,12 +55,12 @@ def get_products_data() -> pd.DataFrame: def add_product_to_csv(category: str, url: str) -> None: data = [category, url] Filemanager.append_csv( - f"{Filemanager.get_root_path()}/scraper/products.csv", data + f"{Filemanager.root_path}/scraper/products.csv", data ) @staticmethod def clear_product_csv(): - Filemanager.clear_csv(f"{Filemanager.get_root_path()}/scraper/products.csv") + Filemanager.clear_csv(f"{Filemanager.root_path}/scraper/products.csv") Filemanager.add_product_to_csv( "category", "url" ) # header for csv to use in pandas.DataFrame @@ -83,7 +81,7 @@ def write(filename: str, config: configparser.ConfigParser) -> None: @staticmethod def get_user_product_names() -> configparser.SectionProxy: """Get section 'ChangeName' from settings.ini file""" - config = Config.read(f"{Filemanager.get_root_path()}/scraper/settings.ini") + config = Config.read(f"{Filemanager.root_path}/scraper/settings.ini") return config["ChangeName"] @staticmethod From 8d598ba0169af90004cef86761f7662bc3c3a7c1 Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Mon, 12 Apr 2021 22:49:08 +0200 Subject: [PATCH 09/10] Change data format and add new argument README.md: - Add section about new data format in version v1.1 scraper/format.py: - import Filemanager from scraper.filemanager - Create static method "format_old_records_to_new" to format data in records.json from pre version v1.1 to new data format in version v1.1 scraper/scrape.py: - reflect changes to data format in records.json in method "Scraper.update_data" scraper/visualize.py: - reflect changes to data format in records.json in function "format_data" scraper/add_product.py: - Create function "check_if_product_exits" - Simplify funciton "add_product_to_records" - Update function "add_product" scraper/arguments.py: - add new argument "--clean-data" Create scraper/clean_data.py: - Add function "clean_data" to remove unnecessary datapoints in new data format scraper/__init__.py: - import function "clean_data" from scraper.clean_data main.py: - reflect changes to data format in records.json in function "reset" - add if-statement for if arguments "--clean-data" is used in function "main" --- README.md | 22 ++++++++++++++++- main.py | 5 +++- scraper/__init__.py | 1 + scraper/add_product.py | 55 ++++++++++++++++++++++-------------------- scraper/arguments.py | 7 ++++++ scraper/clean_data.py | 29 ++++++++++++++++++++++ scraper/format.py | 19 ++++++++++++++- scraper/scrape.py | 2 +- scraper/visualize.py | 5 ++-- 9 files changed, 112 insertions(+), 33 deletions(-) create mode 100644 scraper/clean_data.py diff --git a/README.md b/README.md index c5a0da61..06e2ec37 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ - [User settings](#user-settings) - [Visualize data](#visualize-data) - [Command examples](#command-examples) +- [Clean up data](#clean-up-data)
@@ -26,6 +27,16 @@ Feel free to fork the project and create a pull request with new features or ref
+## UPDATE TO HOW DATA IS STORED IN V1.1 +In version v1.1, I have changed how data is stored in "records.json". "dates" under each product have been changed to "datapoints" and now a list containing dicts with "date" and "price" keys.
+If you want to update your data to be compatible with version v1.1, then open a interactive python session where this repository is located and run the following commands: +``` +>>> from scraper.format import Format +>>> Format.format_old_records_to_new() +``` + +
+ ## First setup Clone this repository and move into the repository: ``` @@ -57,7 +68,7 @@ If you just want to reset your data for each product, just delete all data-point ``` python3 main.py --reset ``` -This deletes all the data inside each product, such as id, url and and dates with prices. +This deletes all the data inside each product, such as id, url and all datapoints.
@@ -197,3 +208,12 @@ python3 main.py -v -vn ``` If the name of a product has multiple words in it, then just add quotation marks around the name. + +
+ + +## Clean up data +If you want to clean up your data, meaning you want to remove unnecessary datapoints (datapoints that have the same price as the datapoint before and after it), then run the following command: +``` +python3 main.py --clean-data +``` diff --git a/main.py b/main.py index 707cd8fe..16bb706e 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,9 @@ def main(): args = scraper.argparse_setup() + if args.clean_data: + scraper.clean_data() + if args.visualize: visualize(args) @@ -103,7 +106,7 @@ def reset(): for product in category.values(): for website in product.values(): website["info"] = {"id": "", "url": "", "currency": ""} - website["dates"] = {} + website["datapoints"] = [] scraper.Filemanager.save_record_data(data) diff --git a/scraper/__init__.py b/scraper/__init__.py index da16d82e..399ab4bc 100644 --- a/scraper/__init__.py +++ b/scraper/__init__.py @@ -3,5 +3,6 @@ from .add_product import add_product from .filemanager import Filemanager from .visualize import show_id, show_category, show_all_products, show_name +from .clean_data import clean_data __author__ = "Crinibus" diff --git a/scraper/add_product.py b/scraper/add_product.py index d328996d..9b66e1de 100644 --- a/scraper/add_product.py +++ b/scraper/add_product.py @@ -19,54 +19,57 @@ def add_product(category, url) -> None: new_product = Scraper(category, url) new_product.scrape_info() - is_product_added = add_product_to_records(new_product) + product_exists = check_if_product_exits(new_product) - if is_product_added: + if not product_exists: + add_product_to_records(new_product) Filemanager.add_product_to_csv(new_product.category, new_product.url) new_product.save_info() else: - logger.info("Adding product cancelled") + user_input = input("A product with the same name and from the same website already exist in your data, do you want to override this product? (y/n) > ") + if user_input.lower() in ("y", "yes"): + print("Overriding product...") + add_product_to_records(new_product) + Filemanager.add_product_to_csv(new_product.category, new_product.url) + new_product.save_info() + else: + print("Product was not added nor overrided") + logger.info("Adding product cancelled") -def add_product_to_records(product: Scraper) -> bool: +def check_if_product_exits(product: Scraper) -> bool: data = Filemanager.get_record_data() - category_exist = True if data.get(product.category) else False + # Check category + if data.get(product.category): + # Check product name + if data[product.category].get(product.info.name): + # Check product website name + if data[product.category][product.info.name].get(product.website_name): + return True - if category_exist: - product_name_exist = ( - True if data[product.category].get(product.info.name) else False - ) - if product_name_exist: - product_and_website_exist = ( - True - if data[product.category][product.info.name].get(product.website_name) - else False - ) + return False - if product_and_website_exist: - user_input = input( - "A product with the same name and from the same website already exist in your data, do you want to override this product? (y/n) > " - ) - if user_input.lower() in ("n", "no"): - print("Product was not overridden") - return False +def add_product_to_records(product: Scraper) -> None: + data = Filemanager.get_record_data() + + if data.get(product.category): + if data[product.category].get(product.info.name): data[product.category][product.info.name].update( - {product.website_name: {"info": {}, "dates": {}}} + {product.website_name: {"info": {}, "datapoints": []}} ) else: data[product.category].update( - {product.info.name: {product.website_name: {"info": {}, "dates": {}}}} + {product.info.name: {product.website_name: {"info": {}, "datapoints": []}}} ) else: data.update( { product.category: { - product.info.name: {product.website_name: {"info": {}, "dates": {}}} + product.info.name: {product.website_name: {"info": {}, "datapoints": []}} } } ) Filemanager.save_record_data(data) - return True diff --git a/scraper/arguments.py b/scraper/arguments.py index 8d106a42..74dd67b4 100644 --- a/scraper/arguments.py +++ b/scraper/arguments.py @@ -93,6 +93,13 @@ def argparse_setup() -> ArgumentParser.parse_args: metavar="name" ) + parser.add_argument( + "--clean-data", + help="clean data, so unnecessary datapoints is removed from records", + action="store_true", + dest="clean_data", + ) + validate_arguments(parser) return parser.parse_args() diff --git a/scraper/clean_data.py b/scraper/clean_data.py new file mode 100644 index 00000000..eb9803a7 --- /dev/null +++ b/scraper/clean_data.py @@ -0,0 +1,29 @@ +from scraper.filemanager import Filemanager + + +def clean_data() -> None: + print("Cleaning data...") + records_data = Filemanager.get_record_data() + + for category_info in records_data.values(): + for product_info in category_info.values(): + for website_info in product_info.values(): + datapoints = website_info["datapoints"] + + new_datapoints = [] + + for index, datapoint in enumerate(datapoints): + if index in (0, len(datapoints) - 1): + new_datapoints.append(datapoint) + continue + + # Skip unnecessary datapoints + if datapoint["price"] == datapoints[index - 1]["price"] and datapoint["price"] == datapoints[index + 1]["price"]: + continue + + new_datapoints.append(datapoint) + + website_info["datapoints"] = new_datapoints + + Filemanager.save_record_data(records_data) + print("Done cleaning data") diff --git a/scraper/format.py b/scraper/format.py index 82eab8ee..480aa316 100644 --- a/scraper/format.py +++ b/scraper/format.py @@ -1,6 +1,6 @@ from dataclasses import dataclass import logging -from scraper.filemanager import Config +from scraper.filemanager import Config, Filemanager @dataclass @@ -57,3 +57,20 @@ def get_user_product_name(product_name: str) -> str: return user_product_names[value_key] return product_name + + @staticmethod + def format_old_records_to_new() -> None: + """Format records data from pre v1.1 to new records data format in v1.1""" + records_data = Filemanager.get_record_data() + + for category_info in records_data.values(): + for product_info in category_info.values(): + for website_info in product_info.values(): + website_info.update({"datapoints": []}) + + for date_name, date_info in website_info["dates"].items(): + website_info["datapoints"].append({"date": date_name, "price": float(date_info["price"])}) + + website_info.pop("dates") + + Filemanager.save_record_data(records_data) diff --git a/scraper/scrape.py b/scraper/scrape.py index ac650452..49a67774 100644 --- a/scraper/scrape.py +++ b/scraper/scrape.py @@ -63,6 +63,6 @@ def update_data(self) -> dict: product_id = self.info.partnum if self.info.partnum else self.info.asin product_info["info"].update({"url": short_url, "id": product_id, "currency": self.info.currency}) - product_info["dates"].update({date: {"price": self.info.price}}) + product_info["datapoints"].append({"date": date, "price": self.info.price}) return data diff --git a/scraper/visualize.py b/scraper/visualize.py index 8422ac79..c7d7577d 100644 --- a/scraper/visualize.py +++ b/scraper/visualize.py @@ -135,11 +135,10 @@ def format_data() -> dict: data.update({category_name: {}}) for product_name, product_info in category_info.items(): data[category_name].update({product_name: {}}) - for website_name, website_info in product_info.items(): - dates = [date for date in website_info["dates"]] - prices = [website_info["dates"][date]["price"] for date in dates] + dates = [datapoint["date"] for datapoint in website_info["datapoints"]] + prices = [datapoint["price"] for datapoint in website_info["datapoints"]] id = website_info["info"]["id"] data[category_name][product_name].update( From 6072d1167117aa9a0552f4f85de1ba834942ffc4 Mon Sep 17 00:00:00 2001 From: Crinibus <57172157+Crinibus@users.noreply.github.com> Date: Mon, 12 Apr 2021 23:11:59 +0200 Subject: [PATCH 10/10] Format with Black --- scraper/add_product.py | 14 +++++++++++--- scraper/arguments.py | 2 +- scraper/clean_data.py | 8 +++++++- scraper/filemanager.py | 17 +++++------------ scraper/format.py | 4 +++- scraper/scrape.py | 4 +++- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/scraper/add_product.py b/scraper/add_product.py index 9b66e1de..438abb98 100644 --- a/scraper/add_product.py +++ b/scraper/add_product.py @@ -26,7 +26,9 @@ def add_product(category, url) -> None: Filemanager.add_product_to_csv(new_product.category, new_product.url) new_product.save_info() else: - user_input = input("A product with the same name and from the same website already exist in your data, do you want to override this product? (y/n) > ") + user_input = input( + "A product with the same name and from the same website already exist in your data, do you want to override this product? (y/n) > " + ) if user_input.lower() in ("y", "yes"): print("Overriding product...") add_product_to_records(new_product) @@ -61,13 +63,19 @@ def add_product_to_records(product: Scraper) -> None: ) else: data[product.category].update( - {product.info.name: {product.website_name: {"info": {}, "datapoints": []}}} + { + product.info.name: { + product.website_name: {"info": {}, "datapoints": []} + } + } ) else: data.update( { product.category: { - product.info.name: {product.website_name: {"info": {}, "datapoints": []}} + product.info.name: { + product.website_name: {"info": {}, "datapoints": []} + } } } ) diff --git a/scraper/arguments.py b/scraper/arguments.py index 74dd67b4..12c92842 100644 --- a/scraper/arguments.py +++ b/scraper/arguments.py @@ -90,7 +90,7 @@ def argparse_setup() -> ArgumentParser.parse_args: type=str, nargs="*", dest="visualize_names", - metavar="name" + metavar="name", ) parser.add_argument( diff --git a/scraper/clean_data.py b/scraper/clean_data.py index eb9803a7..28f09eaf 100644 --- a/scraper/clean_data.py +++ b/scraper/clean_data.py @@ -17,8 +17,14 @@ def clean_data() -> None: new_datapoints.append(datapoint) continue + previous_datapoint = datapoints[index - 1] + next_datapoint = datapoints[index + 1] + # Skip unnecessary datapoints - if datapoint["price"] == datapoints[index - 1]["price"] and datapoint["price"] == datapoints[index + 1]["price"]: + if ( + datapoint["price"] == previous_datapoint["price"] + and datapoint["price"] == next_datapoint["price"] + ): continue new_datapoints.append(datapoint) diff --git a/scraper/filemanager.py b/scraper/filemanager.py index 5698efcd..e535fa21 100644 --- a/scraper/filemanager.py +++ b/scraper/filemanager.py @@ -33,16 +33,12 @@ def clear_csv(filename: str): @staticmethod def get_record_data() -> dict: - data = Filemanager.read_json( - f"{Filemanager.root_path}/scraper/records.json" - ) + data = Filemanager.read_json(f"{Filemanager.root_path}/scraper/records.json") return data @staticmethod def save_record_data(data: dict) -> None: - Filemanager.write_json( - f"{Filemanager.root_path}/scraper/records.json", data - ) + Filemanager.write_json(f"{Filemanager.root_path}/scraper/records.json", data) @staticmethod def get_products_data() -> pd.DataFrame: @@ -54,16 +50,13 @@ def get_products_data() -> pd.DataFrame: @staticmethod def add_product_to_csv(category: str, url: str) -> None: data = [category, url] - Filemanager.append_csv( - f"{Filemanager.root_path}/scraper/products.csv", data - ) + Filemanager.append_csv(f"{Filemanager.root_path}/scraper/products.csv", data) @staticmethod def clear_product_csv(): Filemanager.clear_csv(f"{Filemanager.root_path}/scraper/products.csv") - Filemanager.add_product_to_csv( - "category", "url" - ) # header for csv to use in pandas.DataFrame + # header for csv to use in pandas.DataFrame + Filemanager.add_product_to_csv("category", "url") class Config: diff --git a/scraper/format.py b/scraper/format.py index 480aa316..a747c948 100644 --- a/scraper/format.py +++ b/scraper/format.py @@ -69,7 +69,9 @@ def format_old_records_to_new() -> None: website_info.update({"datapoints": []}) for date_name, date_info in website_info["dates"].items(): - website_info["datapoints"].append({"date": date_name, "price": float(date_info["price"])}) + website_info["datapoints"].append( + {"date": date_name, "price": float(date_info["price"])} + ) website_info.pop("dates") diff --git a/scraper/scrape.py b/scraper/scrape.py index 49a67774..9bd6e915 100644 --- a/scraper/scrape.py +++ b/scraper/scrape.py @@ -62,7 +62,9 @@ def update_data(self) -> dict: # Get product id either from info.partnum or info.asin (only Amazon) product_id = self.info.partnum if self.info.partnum else self.info.asin - product_info["info"].update({"url": short_url, "id": product_id, "currency": self.info.currency}) + product_info["info"].update( + {"url": short_url, "id": product_id, "currency": self.info.currency} + ) product_info["datapoints"].append({"date": date, "price": self.info.price}) return data