aboutsummaryrefslogtreecommitdiff
path: root/bot4chan.py
blob: f1ebbab64d3a20bd5c16f76c67202bf5107ca873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
# -*-coding:utf-8 -*

import re
import os
import sys
import tempfile

sujet = []
sujetT = []

new_file, filename = tempfile.mkstemp()
if not new_file:
    filename = "index.html"

os.system("wget " + sys.argv[1] + "  -O " + filename + " -N -q")
os.system("sed -i 's/<\\/a>/<\\/a>\\n/g' " + filename)

regex = '<span class="filesize">(File : |File)<a href="(.*?)" \
         target="_blank">(.*?)</a>'
regex = '<a class="fileThumb" href="(.*?)" target="_blank">'

dumpDir = "dump"

if len(sys.argv) >= 3:
    dumpDir = sys.argv[2]

os.system("mkdir -p " + dumpDir)
with open(filename, 'r') as f:
    for line in f:
        yes = re.search(regex, line)
        if yes:
            print(yes.group(1))
            sujetT.append([yes.group(1)])
            print("Téléchargement de : " + yes.group(1))
            os.system("wget " + 'http:' + yes.group(1) + " -N -q")
            os.system("mv " + yes.group(1)[yes.group(1).rfind('/')+1:] + " " +
                      dumpDir)


os.remove(filename)