-
Notifications
You must be signed in to change notification settings - Fork 2
/
wall.alphacoders.com.py
executable file
·77 lines (71 loc) · 2.92 KB
/
wall.alphacoders.com.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
import sys, getopt
from bs4 import BeautifulSoup
from functions import getSoup, ensureDir, fileDl
def usage():
print("wall.alphacoders.com scraping script. Made by /u/nicba1010")
print("Options and arguments:")
print("\t-h, --help\tShows this printout")
print("\t--update\tStops at first found already downloaded")
print("\t--save-dir=\tStore at this location")
bUrl = "https://wall.alphacoders.com/"
baseUrl = bUrl + "newest_wallpapers.php?page="
baseDir = "/root/wall.alphacoders.com/"
update = False
stop = False
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "update", "save-dir="])
except getopt.GetoptError as err:
print str(err)
usage()
sys.exit()
for o, a in opts:
if o == "--update":
update = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o == "--save-dir":
baseDir = a
else:
usage()
assert False, "unhandled option"
sys.exit()
def processWallpaper(url):
wallpaperSoup = getSoup(url)
wallpaperOriginalUrl = wallpaperSoup.find('span', { "class" : "btn btn-success download-button" })['data-href']
sys.stdout.write("\t\tOriginal Wallpaper Url: " + wallpaperOriginalUrl + "\n\t\t\t")
categories = wallpaperSoup.find('div', { "class" : "floatright" }).findAll('strong')
name = wallpaperSoup.find('div', {'class': 'container center'}).find('div').text.strip().replace("/",".")
tags = wallpaperSoup.findAll('div', {'style': 'padding:5px 10px; margin:1px; display:inline-block;'})
tagArray = [None]*len(tags)
taglist = ""
index = 0
if len(tags) > 0:
for tag in tags:
tagArray[index] = tag.text.strip()
index += 1
tagArray.sort()
for tag in tagArray:
taglist += "[" + tag + "]"
fileName = taglist + name + ((" " if len(taglist) > 0 else "") if len(name) == 0 else " - ") + wallpaperOriginalUrl.split('/')[-4] + "." + wallpaperOriginalUrl.split('/')[-2]
directoryStructure = baseDir
for i in range(0, len(categories)):
sys.stdout.write(categories[i].text.strip() + ("" if i == (len(categories) - 1) else " => "))
directoryStructure += categories[i].text.strip() + "/"
sys.stdout.write("\n\t\t\t\tSaving to: " + directoryStructure + fileName + "\n")
ensureDir(directoryStructure)
retval = fileDl(wallpaperOriginalUrl, directoryStructure, "\t\t\t\t\t", fileName)
if int(retval) == 42 and update:
global stop
stop = True
wallSoup = getSoup(baseUrl + "0")
totalPages = int(wallSoup.find('ul', { "class" : "pagination pagination" }).findAll('li')[-1].find('a')['href'].split('=')[1])
for i in range(0, totalPages+1):
print("Scraping page " + str(i) + "...")
for thumbContainer in getSoup(baseUrl + str(i)).findAll('div', { "class" : "thumb-container-big " }):
wallpaperUrl = bUrl + thumbContainer.find('a')['href']
print ("\tbig.php url: " + wallpaperUrl)
processWallpaper(wallpaperUrl)
if stop:
sys.exit(420)