#!/usr/bin/env python # -*- coding: utf-8 -*- import feedparser import collections import shelve import os.path from urllib import request LINK = 'http://torrentrss.net/getrss.php?rsslink=Lxye6Z' #вставляем свою ссылку с http://torrentrss.net/ folder_to_save = '~/TDownload/torrent' #куда сохранять торрент файлы folder_to_save = os.path.expanduser(folder_to_save) data_file = 'data.she' #название файла shelve TORRENTS = collections.namedtuple('Torrents', 'serial series torrent_url torrent_name') def torrent_nametuple(f): serial = f['summary_detail']['value'] series = f['title'] series = series.replace('Финал','').replace('Сезона','').replace('сезона','').replace('WEBDLRip','').replace('|','').replace('/','').strip() torrent_name = "{}_{}.torrent".format(serial,series.replace('.','')) torrent_url = f['link'] return TORRENTS(serial,series,torrent_url,torrent_name) def main(): print('\n'*10) d = shelve.open(data_file) feed = feedparser.parse( LINK ) for f in feed['entries'][::-1]: #делаем итерацию по данным в rss torrent = torrent_nametuple(f) try: serial_dict = d[torrent.serial] #переходим к dict сериала except KeyError: #если нету ещо такого сериала d[torrent.serial] = {} #создаем новый dict serial_dict = d[torrent.serial] #и даем сылку на него if serial_dict.pop(torrent.series, None) is not None: continue #значит уже ету серию скачало else: print("качаю новый файл:\n {}\n {}".format(torrent.serial,torrent.series)) request.urlretrieve( torrent.torrent_url , os.path.join(folder_to_save,torrent.torrent_name) ) print("файл скачан добавляю его данные в базу...") serial_dict[torrent.series] = torrent d.close() return 0 if __name__ == '__main__': main()
https://docs.python.org/3.4/library/shelve.html
помогите