aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-10-14 06:38:10 +0200
committerache <ache@ache.one>2019-10-14 06:38:10 +0200
commit702ae2da4c4b57773ddaa54e92a1b6326d940b0d (patch)
tree69506eabf070acc4155469f3efcd8e5b3856e22e
parentlight2: Read doesn't need root (diff)
create a temporary file
-rwxr-xr-xbot4chan.py42
1 files 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 = '<span class="filesize">(File : |File)<a href="(.*?)" target="_blank">(.*?)</a>'
+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 :
+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)