summaryrefslogtreecommitdiff
path: root/netto.py
blob: 3f1beb234b42e8f77c3effedd7ffccd38bc84b56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3

from urllib.request import urlopen, Request
from datetime import datetime
from bs4 import BeautifulSoup
import sys


def netto(store_id):
    url = "https://www.netto-online.de/ueber-netto/Online-Prospekte.chtm/" + str(
        store_id
    )
    res = urlopen(Request(url))
    soup = BeautifulSoup(res, features="html.parser")

    # messages = soup.find_all('div', attrs={'class': 'tgme_widget_message_wrap'})
    message = soup.find("a", attrs={"class": "flipbook_pdf_flipbook"})

    url = message["href"].split("?")[0]
    year = str(datetime.now().year)
    title = url[url.find(year) : url.find(year) + 7]

    return {
        title: "Netto Angebote für " + store_id,
        url: "https://www.netto-online.de/ueber-netto/Online-Prospekte.chtm/"
        + store_id,
        description: "PDF der neuen Netto Angebote für den Laden um die Ecke.",
        content: [
            {
                "title": "Angebote für " + title,
                "url": url,
                "content": "Angebote für " + title + " finden sich unter " + url,
            }
        ],
    }


def main(store_id=9110):
    print(netto(store_id))


if __name__ == "__main__":
    main()