Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

price tracker added #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions egg_price _tracker/.gitignore
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions egg_price _tracker/README.md
Original file line number Diff line number Diff line change
@@ -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 </br>

## 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. 😊
Binary file added egg_price _tracker/README_img/Readme_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added egg_price _tracker/README_img/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions egg_price _tracker/egg_tracker/egg_tracker.py
Original file line number Diff line number Diff line change
@@ -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()

10 changes: 10 additions & 0 deletions egg_price _tracker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
requests/netcup_egg_tracker.egg-info
**/build/
**/dist/
**/log/
**/config/
.vscode/*
**/__pycache__/
*.ini
!__ini__.py
*eggs_*
Loading