diff --git a/egg_price _tracker/.gitignore b/egg_price _tracker/.gitignore new file mode 100644 index 0000000..2ff8f74 --- /dev/null +++ b/egg_price _tracker/.gitignore @@ -0,0 +1,34 @@ +/netcup_egg_tracker.egg-info +**/build/ +**/dist/ +**/log/ +**/config/ +.vscode/* +**/__pycache__/ +*.ini +!__ini__.py +*eggs_* + +# Git Ignore File +# +# This file is used to specify files and directories that should be ignored by Git. +# You can use various operators and patterns to match files and directories. +# +# Here are some examples of patterns you can use: +# +# * Matches zero or more characters in a filename or path segment. +# ? Matches any single character in a filename or path segment. +# ** Matches any number of directories (including none) in a pathname. +# ! Negates a pattern, so files that match will not be ignored. +# # Indicates a comment, which is ignored by Git. +# +# Here are some examples of how to use these patterns: +# +# *.pyc Matches any files ending with .pyc. +# test/ Matches the directory 'test'. +# **/test/ Matches any directory named 'test', regardless of where it is in the directory tree. +# build/* Matches any files in the 'build' directory, but not the directory itself. +# !build/*.txt Does not ignore any .txt files in the 'build' directory, even though 'build/' is ignored. +# +# For more information on Git ignore patterns, see the Git documentation: +# https://git-scm.com/docs/gitignore \ No newline at end of file diff --git a/egg_price _tracker/README.md b/egg_price _tracker/README.md new file mode 100644 index 0000000..b9ae82e --- /dev/null +++ b/egg_price _tracker/README.md @@ -0,0 +1,34 @@ +# Price Tracker + +This script is designed to track prices on the Netcup website. It makes requests to specific pages on the site, retrieves product information, and saves it in a structured format for later analysis. + +## Features + +- Tracks prices for a predefined list of pages on the Netcup website. +- Saves product information in a structured JSON format. +- Organizes data by year and product type for easy access and analysis. +- Handles exceptions and logs errors for easy debugging. + + +## Dependencies +This script requires the following Python libraries: +- requests +- json +- time +- os +- logging +- datetime +Make sure to install these dependencies before running the script. + +## Usage + +To run the script, simply execute the following command: + +```bash +python main.py
+ +## Note +This script is intended for educational purposes only. Please use responsibly and respect the terms of service of the website. + + +I hope this helps! Let me know if you need any further assistance. 😊 \ No newline at end of file diff --git a/egg_price _tracker/README_img/Readme_top.png b/egg_price _tracker/README_img/Readme_top.png new file mode 100644 index 0000000..1291431 Binary files /dev/null and b/egg_price _tracker/README_img/Readme_top.png differ diff --git a/egg_price _tracker/README_img/demo.png b/egg_price _tracker/README_img/demo.png new file mode 100644 index 0000000..3956b44 Binary files /dev/null and b/egg_price _tracker/README_img/demo.png differ diff --git a/egg_price _tracker/egg_tracker/egg_tracker.py b/egg_price _tracker/egg_tracker/egg_tracker.py new file mode 100644 index 0000000..c9eb597 --- /dev/null +++ b/egg_price _tracker/egg_tracker/egg_tracker.py @@ -0,0 +1,100 @@ +import requests +import json +import time +import os +import logging +from datetime import datetime + +logging.basicConfig(level=logging.INFO) + +refs = [ + "/vserver/vserver_images.php", + "/vserver/vps.php", + "/vserver/", + "/vserver/root-server-erweiterungen.php", + "/", + "/hosting", + "/bestellen/domainangebote.php", + "/bestellen/softwareangebote.php", + "/ssl-zertifikate/", + "/ueber-netcup/", + "/ueber-netcup/hardware-infrastruktur.php", + "/ueber-netcup/ddos-schutz-filter.php", + "/ueber-netcup/auszeichnungen.php", + "/ueber-netcup/zertifizierungen.php", + "/ueber-netcup/partner.php", + "/groupware/", + "/professional/", + "/professional/dedizierte-server/", + "/professional/managed-server/", + "/professional/colocation/", + "/professional/softwareentwicklung/", +] + +def get_price_formatted(price): + return price.replace(",", ".").replace("€", "EUR").replace(" ", "") + +def sanitize_filename(filename): + return filename.replace("/", "_").replace("|", "_").replace("\\", "_").replace(":", "_").replace("*", "_").replace("?", "_").replace('"', "_").replace("<", "_").replace(">", "_") + +def main(): + current_year = datetime.now().year + folder_path = f"eggs_{current_year}" + + if not os.path.exists(folder_path): + os.makedirs(folder_path) + + while True: + + for r in refs: + + try: + resp = requests.post("https://www.netcup.de/api/eggs", data={"requrl": r}) + response_text = json.loads(resp.text)["eggs"] + if response_text is None or not response_text: + continue + + egg = response_text[0] + if egg['title'][-1] == " ": + egg['title'] = egg['title'][:-1] + + price = get_price_formatted(egg["price"]) + file_name = sanitize_filename(f"{price}_{egg['id']}.json") + sub_folder = sanitize_filename(f"{egg['title']}").replace(" ","_") + + full_folder_path = os.path.join(folder_path, sub_folder) + if not os.path.exists(full_folder_path): + os.makedirs(full_folder_path) + + path = os.path.join(full_folder_path, file_name) + + egg['original_url'] = f"https://www.netcup.de/bestellen/produkt.php?produkt={egg['product_id']}&ref=230003&hiddenkey={egg['product_key']}" + egg['found_url'] = f"https://www.netcup.de{r}" + egg['found_unix_time'] = int(time.time()) + with open(path, "w") as file: + json.dump(egg, file, indent=4) + + logging.info(f"{'-' * 10}") + logging.info(f"{egg['title']}") + logging.info(f"{price}") + logging.info(f"{egg['original_url']}") + logging.info(f"{egg['found_url']}") + logging.info(f"Found Unix Time: {egg['found_unix_time']}") + logging.info(f"{'-' * 10}") + + except requests.exceptions.RequestException as e: + logging.error(f"Request failed: {e}") + continue + except json.JSONDecodeError as e: + logging.error(f"Failed to decode JSON: {e}") + continue + except Exception as e: + logging.error(f"An unexpected error occurred: {e}") + continue + + logging.info(f"\n\n Time Sleep - {2*60}") + time.sleep(2 * 60) + +if __name__ == "__main__": + main() + diff --git a/egg_price _tracker/requirements.txt b/egg_price _tracker/requirements.txt new file mode 100644 index 0000000..074d954 --- /dev/null +++ b/egg_price _tracker/requirements.txt @@ -0,0 +1,10 @@ +requests/netcup_egg_tracker.egg-info +**/build/ +**/dist/ +**/log/ +**/config/ +.vscode/* +**/__pycache__/ +*.ini +!__ini__.py +*eggs_* \ No newline at end of file