Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- import feedparser
- import collections
- import shelve
- import os.path
- from urllib import request
- LINKS = [ #вставляем свою ссылку с http://torrentrss.net/
- 'http://torrentrss.net/getrss.php?rsslink=Lxye6Z',
- 'http://torrentrss.net/getrss.php?rsslink=PALCu9'
- ]
- folder_to_save = '~/TDownload/torrent' #куда сохранять торрент файлы
- folder_to_save = os.path.expanduser(folder_to_save)
- data_file = 'data.she' #название файла shelve
- loadfmt = "\nкачаю новый файл:\n {}\n {}"
- 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, writeback=True)
- x= 0
- for LINK in LINKS:
- feed = feedparser.parse( LINK )
- for f in feed['entries'][::-1]: #делаем итерацию по данным в rss
- torrent = torrent_nametuple(f)
- if torrent.serial in d:
- serial_dict = d[torrent.serial]
- else:
- serial_dict = d[torrent.serial] = {}
- if torrent.series not in serial_dict:
- print(loadfmt.format(torrent.serial, torrent.series))
- request.urlretrieve(
- torrent.torrent_url,
- os.path.join(folder_to_save, torrent.torrent_name)
- )
- serial_dict[torrent.series] = tuple(torrent)
- print("файл скачан добавляю его данные в базу...")
- else:
- x += 1
- d.close()
- print('Старых файлов: {}'.format(x))
- return 0
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment