From 702ae2da4c4b57773ddaa54e92a1b6326d940b0d Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 14 Oct 2019 06:38:10 +0200 Subject: create a temporary file --- bot4chan.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/bot4chan.py b/bot4chan.py index ecdab75..f1ebbab 100755 --- a/bot4chan.py +++ b/bot4chan.py @@ -1,31 +1,41 @@ #!/usr/bin/python # -*-coding:utf-8 -* -import re, os, sys +import re +import os +import sys +import tempfile sujet = [] sujetT = [] -os.system("wget " + sys.argv[1] + " -O index.html -N -q") -os.system("sed -i 's/<\\/a>/<\\/a>\\n/g' index.html") +new_file, filename = tempfile.mkstemp() +if not new_file: + filename = "index.html" -regex = '(File : |File)(.*?)' +os.system("wget " + sys.argv[1] + " -O " + filename + " -N -q") +os.system("sed -i 's/<\\/a>/<\\/a>\\n/g' " + filename) + +regex = '(File : |File)(.*?)' regex = '' dumpDir = "dump" -if len(sys.argv) >= 3 : +if len(sys.argv) >= 3: dumpDir = sys.argv[2] os.system("mkdir -p " + dumpDir) -with open("index.html",'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) - - +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) -- cgit v1.2.3