def _add_episodes(self, series_id, new_episodes, series_title, init='current'): "add new episodes" for (episode_link, episode_number, episode_name,) in new_episodes: try: self.cursor.execute("INSERT INTO episodes(" \ 'series_id,' \ 'episode_link,' \ 'episode_name,' \ 'episode_number,'\ 'Date) ' \ 'VALUES(%s,%s,%s,%s,%s) RETURNING id' ,(series_id, episode_link, episode_name, episode_number, datetime.now(),)) episode_id = self.cursor.fetchone()[0] self._send_to_queue(series_id, episode_id, episode_number) self.db.commit() if init == 'current': announce("New Series Episode", series_title, episode_number) except psycopg2.IntegrityError: logging.error("episode already exists")
def released_movies(data, cursor, db): "insert new movies" if not data: logging.info("Unable to get newly released movies") elif data["status"] == "error": logging.info("api status error") else: for movie_detail in movie_compare(cursor, data['data']['movies']): if fetch_image(movie_detail["medium_cover_image"], movie_detail['title']): try: genre_id = get_movie_genre(movie_detail["genres"][0], cursor, db) cursor.execute("INSERT INTO movies(genre_id,title,link,date_added,yify_id,year) "\ 'VALUES(%s,%s,%s,%s,%s,%s) RETURNING id', (genre_id, movie_detail['title'], movie_detail["imdb_code"], datetime.now(), movie_detail["id"], movie_detail["year"],)) row_id = cursor.fetchone()[0] cursor.execute("INSERT INTO movie_torrent_links(movie_id,link,hash_sum) "\ "VALUES(%s,%s,%s)", (row_id, movie_detail["torrents"][0]["url"], movie_detail["torrents"][0]["hash"],)) if image_record_exists(movie_detail['title'], cursor): pass else: cursor.execute("INSERT INTO movie_images(title,path) VALUES(%s,%s)", (movie_detail['title'], movie_detail['title']+".jpg",)) db.commit() announce('Newly Released Movie', "{} ({})".format(movie_detail["title"], movie_detail["genres"][0]), "http://www.imdb.com/title/{}".format(movie_detail["imdb_code"])) except psycopg2.IntegrityError as e: db.rollback() logging.exception(e) except Exception as e: db.rollback() logging.exception(e)