Skip to content

Commit 832de6c

Browse files
committed
Download function added. DOWNLOAD_DIR existence is not controlled
1 parent 053cb58 commit 832de6c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

mt_scrapper.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
from flask import Flask, request, render_template
22
import string
33
import requests
4+
import urllib2
45
from bs4 import BeautifulSoup
56

7+
8+
DOWNLOAD_DIR = 'Downloads'
9+
10+
def downloadFile(url, directory):
11+
file = urllib2.urlopen(url)
12+
13+
fileName = url[url.rfind('/')+1:len(url)]
14+
fileName = directory + '/' + fileName
15+
16+
localFile = open(fileName, 'w')
17+
localFile.write(file.read())
18+
localFile.close()
19+
20+
621
app = Flask(__name__)
722

823
@app.route("/")
@@ -44,7 +59,6 @@ def show_chapters():
4459
episodios[input.get('name')] = input.get('value')
4560

4661
# Generamos la peticion POST y parseamos los torrents
47-
4862
payload = {'checkall': 'on', 'total_capis': len(episodios), 'tabla': 'series'}
4963
payload = dict(payload.items() + episodios.items())
5064
post = requests.post('http://mejortorrent.com/secciones.php?sec=descargas&ap=contar_varios', payload)
@@ -56,6 +70,9 @@ def show_chapters():
5670
if str(link.get('href'))[0:52] == 'http://www.mejortorrent.com/uploads/torrents/series/':
5771
torrents.append(link.get('href'))
5872

73+
for torrent in torrents:
74+
downloadFile(torrent, DOWNLOAD_DIR)
75+
5976
return render_template('serie.html', section=request.args.get('name', ''),
6077
torrents=torrents,
6178
cover=cover)

templates/serie.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ <h1>{{ section }}</h1>
1414
{% endfor %}
1515
</ul>
1616

17+
<h2>Se han descargado los torrents</h2>
18+
1719
{% endblock %}

0 commit comments

Comments
 (0)