|
| 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 | + |
0 commit comments