def mangdl(self):
        try:
            mangaLinkMap = pickle.load(open("dbase.txt", 'r'))

            #Go to the main page of the manga title
            #and Download the first chapter. Trial.
            #But, before that, create a new folder dedicated to this
            #particular manga title and aslo a folder for chapter 1
            print "Ore ha koko ni iru"
            x  = namelist[self.val]
            remove_set.add(x+'.html')
            if not os.path.isfile(x + '.html'):
                urllibX.urlretrieve('http://www.mangareader.net'\
                                    +mangaLinkMap[x], x+'.html')
            print 'Node boku mo ', mangaLinkMap[x]
            print "Soshite, sono namae ha ", x
            newDict = chapMap(x+'.html')
            clickable_wind(newDict, x)
        except:
            pass
def chapDL(index, listChap, mangaName):
    print listChap[index], " -<-< Doitsumo Koitsumo"
    urlH = chapDict[listChap[index]]
    print "url ha ", urlH
    print "Manganame ha ", mangaName
    apos = "\'"
    apos+mangaName+apos+" "+ apos+listChap[index]+apos
    os.system("./folcreate.sh "+ apos+mangaName+apos+" "+apos+listChap[index]+apos)

    fileS = './'+mangaName+'/'+listChap[index]+ '/'+listChap[index]+'.html'

    namelist = []
    first = int(sys.argv[1])
    PAGES = int(sys.argv[2]) # Checks for PAGES pages
    for i in range(first, PAGES):
        #Differentiates between old-type and new-type links
        if '-' in urlH and is_int(urlH[urlH.index('-')+1]):
            print "LINKTYPE: Old"
            ind = find_nth(urlH, '-', 2)
            copy = urlH
            digiLen = 2
            copy = copy[:ind+1] + str(i) +'/' +copy[ind+len(str(i))+digiLen:]
            print "OURLINK: ", copy
            urllibX.urlretrieve("http://www.mangareader.net"+copy, fileS)
        else:
            urllibX.urlretrieve("http://www.mangareader.net"+urlH+'/'+str(i), fileS)
        #Open the chapter page
        imgSoup = bs4.BeautifulSoup(open(fileS, 'r'))
        chitra = imgSoup.findAll('img')
        #Display the source img

        for each in chitra:
            print "LINK"
            print each['src']
            link = each['src']

            #Get the filename-after the last /
            name = link[link.rfind('/')+1:len(link)]
            namelist.append(name)
            urllibX.urlretrieve(link, mangaName+'/'+listChap[index]+'/'+name)
    '''
Example #3
0
#import re, sys, urllib, os
import re, sys, urllibX, os
import shutil

# modified urllib (user-agent string change)

fi = open(sys.argv[1]).read()

matches = re.search('img src="([^"]+)"', fi).group()

a = matches[9:-1]

b = urllibX.urlretrieve(a)

try:
    os.rename(b[0], sys.argv[3] + sys.argv[2] + ".jpg")
except:
    shutil.move(b[0], sys.argv[3] + sys.argv[2] + ".jpg")
    print "STAGE 3"
    for chapter in lC:
        temp = Checkbutton(root2, text=chapter, variable=choice[chapter])
        text.window_create("end", window=temp)
        text.insert("end", "\n") # in order to force one checkbox per line

    button = Button(root2, text='Download Chapter(s)',command= lambda:chapVal(mangaName, lC, choice))
    button.pack()

    #root2.mainloop()
    print "TEME!!!!!!!  ", val

#Make list of manga titles
if not os.path.isfile("mnrdl_list.html"):
    urllibX.urlretrieve("http://www.mangareader.net/alphabetical",\
                       "mnrdl_list.html")

myDict = {}

if not os.path.isfile("dbase.txt"):
    soup = bs4.BeautifulSoup(open('mnrdl_list.html'))
    f1 = open('dbase.txt', 'w+')
    mname = soup.findAll('a')
    for node in mname:
        a = ''.join(node.findAll(text=True))
        b = None
        if node.attrs.has_key('href'):
            b = node['href']
        myDict[a] = b
    pickle.dump(myDict, f1)
    f1.close()