Skip to content

Commit f498db2

Browse files
committed
price tracker added
1 parent c1d34bb commit f498db2

File tree

6 files changed

+178
-0
lines changed

6 files changed

+178
-0
lines changed

egg_price _tracker/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/netcup_egg_tracker.egg-info
2+
**/build/
3+
**/dist/
4+
**/log/
5+
**/config/
6+
.vscode/*
7+
**/__pycache__/
8+
*.ini
9+
!__ini__.py
10+
*eggs_*
11+
12+
# Git Ignore File
13+
#
14+
# This file is used to specify files and directories that should be ignored by Git.
15+
# You can use various operators and patterns to match files and directories.
16+
#
17+
# Here are some examples of patterns you can use:
18+
#
19+
# * Matches zero or more characters in a filename or path segment.
20+
# ? Matches any single character in a filename or path segment.
21+
# ** Matches any number of directories (including none) in a pathname.
22+
# ! Negates a pattern, so files that match will not be ignored.
23+
# # Indicates a comment, which is ignored by Git.
24+
#
25+
# Here are some examples of how to use these patterns:
26+
#
27+
# *.pyc Matches any files ending with .pyc.
28+
# test/ Matches the directory 'test'.
29+
# **/test/ Matches any directory named 'test', regardless of where it is in the directory tree.
30+
# build/* Matches any files in the 'build' directory, but not the directory itself.
31+
# !build/*.txt Does not ignore any .txt files in the 'build' directory, even though 'build/' is ignored.
32+
#
33+
# For more information on Git ignore patterns, see the Git documentation:
34+
# https://git-scm.com/docs/gitignore

egg_price _tracker/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Price Tracker
2+
3+
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.
4+
5+
## Features
6+
7+
- Tracks prices for a predefined list of pages on the Netcup website.
8+
- Saves product information in a structured JSON format.
9+
- Organizes data by year and product type for easy access and analysis.
10+
- Handles exceptions and logs errors for easy debugging.
11+
12+
13+
## Dependencies
14+
This script requires the following Python libraries:
15+
- requests
16+
- json
17+
- time
18+
- os
19+
- logging
20+
- datetime
21+
Make sure to install these dependencies before running the script.
22+
23+
## Usage
24+
25+
To run the script, simply execute the following command:
26+
27+
```bash
28+
python main.py </br>
29+
30+
## Note
31+
This script is intended for educational purposes only. Please use responsibly and respect the terms of service of the website.
32+
33+
34+
I hope this helps! Let me know if you need any further assistance. 😊
2 MB
Loading
20 KB
Loading
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import requests
2+
import json
3+
import time
4+
import os
5+
import logging
6+
from datetime import datetime
7+
8+
logging.basicConfig(level=logging.INFO)
9+
10+
refs = [
11+
"/vserver/vserver_images.php",
12+
"/vserver/vps.php",
13+
"/vserver/",
14+
"/vserver/root-server-erweiterungen.php",
15+
"/",
16+
"/hosting",
17+
"/bestellen/domainangebote.php",
18+
"/bestellen/softwareangebote.php",
19+
"/ssl-zertifikate/",
20+
"/ueber-netcup/",
21+
"/ueber-netcup/hardware-infrastruktur.php",
22+
"/ueber-netcup/ddos-schutz-filter.php",
23+
"/ueber-netcup/auszeichnungen.php",
24+
"/ueber-netcup/zertifizierungen.php",
25+
"/ueber-netcup/partner.php",
26+
"/groupware/",
27+
"/professional/",
28+
"/professional/dedizierte-server/",
29+
"/professional/managed-server/",
30+
"/professional/colocation/",
31+
"/professional/softwareentwicklung/",
32+
]
33+
34+
def get_price_formatted(price):
35+
return price.replace(",", ".").replace("€", "EUR").replace(" ", "")
36+
37+
def sanitize_filename(filename):
38+
return filename.replace("/", "_").replace("|", "_").replace("\\", "_").replace(":", "_").replace("*", "_").replace("?", "_").replace('"', "_").replace("<", "_").replace(">", "_")
39+
40+
def main():
41+
current_year = datetime.now().year
42+
folder_path = f"eggs_{current_year}"
43+
44+
if not os.path.exists(folder_path):
45+
os.makedirs(folder_path)
46+
47+
while True:
48+
49+
for r in refs:
50+
51+
try:
52+
resp = requests.post("https://www.netcup.de/api/eggs", data={"requrl": r})
53+
response_text = json.loads(resp.text)["eggs"]
54+
if response_text is None or not response_text:
55+
continue
56+
57+
egg = response_text[0]
58+
if egg['title'][-1] == " ":
59+
egg['title'] = egg['title'][:-1]
60+
61+
price = get_price_formatted(egg["price"])
62+
file_name = sanitize_filename(f"{price}_{egg['id']}.json")
63+
sub_folder = sanitize_filename(f"{egg['title']}").replace(" ","_")
64+
65+
full_folder_path = os.path.join(folder_path, sub_folder)
66+
if not os.path.exists(full_folder_path):
67+
os.makedirs(full_folder_path)
68+
69+
path = os.path.join(full_folder_path, file_name)
70+
71+
egg['original_url'] = f"https://www.netcup.de/bestellen/produkt.php?produkt={egg['product_id']}&ref=230003&hiddenkey={egg['product_key']}"
72+
egg['found_url'] = f"https://www.netcup.de{r}"
73+
egg['found_unix_time'] = int(time.time())
74+
with open(path, "w") as file:
75+
json.dump(egg, file, indent=4)
76+
77+
logging.info(f"{'-' * 10}")
78+
logging.info(f"{egg['title']}")
79+
logging.info(f"{price}")
80+
logging.info(f"{egg['original_url']}")
81+
logging.info(f"{egg['found_url']}")
82+
logging.info(f"Found Unix Time: {egg['found_unix_time']}")
83+
logging.info(f"{'-' * 10}")
84+
85+
except requests.exceptions.RequestException as e:
86+
logging.error(f"Request failed: {e}")
87+
continue
88+
except json.JSONDecodeError as e:
89+
logging.error(f"Failed to decode JSON: {e}")
90+
continue
91+
except Exception as e:
92+
logging.error(f"An unexpected error occurred: {e}")
93+
continue
94+
95+
logging.info(f"\n\n Time Sleep - {2*60}")
96+
time.sleep(2 * 60)
97+
98+
if __name__ == "__main__":
99+
main()
100+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
requests/netcup_egg_tracker.egg-info
2+
**/build/
3+
**/dist/
4+
**/log/
5+
**/config/
6+
.vscode/*
7+
**/__pycache__/
8+
*.ini
9+
!__ini__.py
10+
*eggs_*

0 commit comments

Comments
 (0)