-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSFW_File_Download_Bot.py
More file actions
57 lines (47 loc) · 1.73 KB
/
Copy pathSFW_File_Download_Bot.py
File metadata and controls
57 lines (47 loc) · 1.73 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
from urllib.request import urlopen, Request
import bs4 as bs
import random
import urllib.request
import requests
import shutil
import sys
while 1==1:
dir1 = "C:/Path/To/IMG Sorter/all_data/" #Path to all data folder
dir2 = "C:/Path/To/IMG Sorter/New_Data/" #Path to new data folder
dir3 = "C:/Path/To/IMG Sorter/train/" #Path to train data folder
list1 = os.listdir(dir1)
list2 = os.listdir(dir2)
list3 = os.listdir(dir3)
number_files = len(list1)
if number_files > 400:
sys.exit()
else:
name_file = str(number_files)
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3'}
reg_url = "https://nekos.life"
req = Request(url = reg_url, headers = headers)
#Pinging Site For Images
ping = urlopen(req)
pinger = bs.BeautifulSoup(ping, 'lxml')
source_frag2 = []
for img in pinger.find('img').attrs['src']:
source_frag1 = (img)
source_frag2.append(source_frag1)
source = ''.join(source_frag2)
print("Downloading", source)
#Saving File To Folder
name = "sfw." + name_file + ".jpg"
new_name = name_file + ".jpg"
full_name1 = os.path.join(dir2, new_name)
full_name2 = os.path.join(dir1, name)
full_name3 = os.path.join(dir3, name)
f = open(full_name1, 'wb')
f.write(requests.get(source).content)
f.close()
f = open(full_name2, 'wb')
f.write(requests.get(source).content)
f.close()
f = open(full_name3, 'wb')
f.write(requests.get(source).content)
f.close()