예제 #1
0
파일: Muspy.py 프로젝트: niekp/Goedemorgen
    def Run(self):
        # Load the database
        self.conn = f.getDatabase(
            self.config_full, "muspy", "CREATE TABLE Muspy (id text, title text, updated text, notified int)")
        cursor = self.conn.cursor()

        # Haal de feed op
        feed = feedparser.parse(self.config["feed"])
        for item in feed["items"]:
            # Werk database bij
            self.UpdateDB(item["id"], item["title"], item["updated"])

        # Opslaan
        self.conn.commit()

        c_update = self.conn.cursor()
        # Zoek alle ongemelde releases voor vandaag, of het verleden. Sqlite heeft geen date functies, maar zo kan het ook
        results = cursor.execute("SELECT id, title, updated FROM Muspy WHERE substr(updated,0, 5) || substr(updated, 6, 2) || substr(updated, 9, 2) < ? and notified = 0;",
                                 (datetime.datetime.now().strftime("%Y%m%d"),))
        for release in results:
            self.hasText = True
            self.text += release[1] + "<br/>"

            # Opslaan dat de notificatie verstuurd is.
            c_update.execute(
                "UPDATE Muspy SET notified = 1 WHERE id = ?", (release[0],))

        # Header toevoegen
        if self.hasText:
            self.conn.commit()
            self.text = "<h2>Nieuwe releases</h2>" + self.text

        cursor.close()
        c_update.close()
        self.conn.close()
예제 #2
0
    def Run(self):
        # Load the syncthing API
        s = SyncthingWrapper(self.config["apikey"], self.config["host"],
                             str(self.config["port"]))

        # Load a database to keep the status
        conn = f.getDatabase(
            self.config_full, "syncthing",
            "CREATE TABLE Syncthing (folder text, file text, modified_date text)"
        )
        cursor = conn.cursor()

        folders_metadata = s.system.config()["folders"]

        for folder_id in self.config["folders"]:
            # Default label als de folder label niet gevonden kan worden
            label = "Nieuwe bestanden"

            # Find the label
            for metadata in folders_metadata:
                if metadata["id"] == folder_id:
                    label = metadata["label"]

            # Load all filenames with API
            for file, metadata in s.database.browse(folder_id).items():
                modified_date = metadata[0]

                # Check if the notification for this file has already been sent
                cursor.execute(
                    "SELECT file FROM Syncthing WHERE folder = ? AND file = ?",
                    (
                        folder_id,
                        file,
                    ))
                result = cursor.fetchone()

                # If not, send the notification and keep history
                if result is None:
                    cursor.execute("INSERT INTO Syncthing values (?, ?, ?)",
                                   (folder_id, file, modified_date))

                    if label:
                        self.text += "<h3>" + label + "</h3>"
                        label = ""

                    self.text += (file + "<br />")
                    self.hasText = True

        cursor.close()

        # Opslaan
        conn.commit()
예제 #3
0
    def Run(self):
        # Generate the API URL
        api_url = "{0}/rest/getNewestPodcasts?u={1}&p={2}&v=1.12.0&c=goedemorgen".format(
            self.config["url"], self.config["user"], self.config["password"])

        # Download the API response
        response = requests.get(api_url, stream=True)
        response.raw.decode_content = True

        # Parse the API response
        parser = etree.XMLParser(ns_clean=True, recover=True)
        tree = etree.parse(response.raw, parser)

        # Load up the database
        self.conn = f.getDatabase(self.config_full, "subsonic",
                                  "CREATE TABLE Subsonic (id text, podcast text, title text)")

        for elem in tree.iter():
            # Filter out the episodes from the result
            if elem.tag.endswith("episode"):
                id = elem.attrib['id']
                podcast = elem.attrib['album']
                title = elem.attrib['title']

                cursor = self.conn.cursor()

                # Check if the episode has already been notified
                cursor.execute(
                    "SELECT title FROM Subsonic WHERE id = ?", (id,))
                result = cursor.fetchone()

                # If not, notify.
                if result is None:
                    cursor.execute(
                        "insert into Subsonic values (?, ?, ?)", (id, podcast, title))
                    self.text += ("{0} - {1}<br />".format(podcast, title))
                    self.hasText = True

                cursor.close()

        self.conn.commit()

        if self.hasText:
            self.text = "<h3>Nieuwe podcasts</h3>" + self.text
예제 #4
0
    def Run(self):
        # Grab 2 pages from sonarr since there is a lot more activity. This should be dynamic but ohwell it works.
        urls = [
            "{0}/history?apikey={1}&sortKey=date&sortDir=desc&pageSize=20&page=1".format(
                self.config["sonarr"]["url"], self.config["sonarr"]["apikey"]),
            "{0}/history?apikey={1}&sortKey=date&sortDir=desc&pageSize=20&page=2".format(
                self.config["sonarr"]["url"], self.config["sonarr"]["apikey"]),
            "{0}/history?apikey={1}&sortKey=date&sortDir=desc&pageSize=20&page=1".format(
                self.config["radarr"]["url"], self.config["radarr"]["apikey"])
        ]

        # Setup DB to keep the notified history
        self.conn = f.getDatabase(
            self.config_full, "sonarrradarr", "CREATE TABLE Records (id text, title text)")
        cursor = self.conn.cursor()

        # Download each api result
        for url in urls:
            with urllib.request.urlopen(url) as url:
                data = json.loads(url.read())
                records = data["records"]

                for record in records:
                    # Only use the 'import' event so you only get notified if the download was successfull
                    if record["eventType"] != "downloadFolderImported":
                        continue

                    # Generate the 'unique' and 'title' values for episodes or movies
                    if "episode" in record:
                        unique = "episode_{0}_{1}".format(
                            record["seriesId"], record["episodeId"])
                        serieTitle = record["series"]["title"]
                        episodeTitle = record["episode"]["title"]
                        episodeNumber = "S{:02}E{:02}".format(
                            record["episode"]["seasonNumber"], record["episode"]["episodeNumber"])

                        title = "{0}: {1} - {2}".format(
                            episodeNumber, serieTitle, episodeTitle)

                    elif "movie" in record:
                        unique = "movie_{0}".format(record["movieId"])
                        title = record["movie"]["title"]
                    else:
                        continue

                    # Check if the episode/movie has already been notified
                    cursor.execute(
                        "SELECT title FROM Records WHERE id = ?", (unique,))
                    result = cursor.fetchone()

                    # If not, notify.
                    if result is None:
                        cursor.execute(
                            "insert into Records values (?, ?)", (unique, title))

                        self.text += ("{0}<br />".format(title))
                        self.hasText = True

        cursor.close()

        # Save the history to sqlite
        self.conn.commit()