Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 29th, 2012, 01:22 PM
Sparkon Sparkon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 15 Sparkon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 24 m 14 sec
Reputation Power: 0
Torrent Downloader Scripts

Hello guys in these 2-3 days i have been working on a torrent downloader scripts that allows me to download the best torrents from different websites ( i just got two for now ) with one click!.
The script actually works, but not very elegant, i hope you guys can give me some tips on how to improve the code mainly with the regex part. The rar zip contains three files, two of the are simply "configuration" files used to store hexcharts and website regex. Do you think i should use another way to store this kind of information?

Here is the anti-virus scan
Anti-Virus Scan from VirusTotal

here is the download from mediafire
Download

Reply With Quote
  #2  
Old July 29th, 2012, 09:12 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,376 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 12 h 21 m 42 sec
Reputation Power: 383
Looks good to me, leaving a few ideas. This post is so complicated to write that if I had other thoughts they are lost.

html suggestions:
Take this regular expression. As I recall, double quotes about a string that doesn't contain spaces is optional.
h33t_torrent['seed_re'] = '<span style="color:[a-z]*">[0-9]*'
Your regular expression works for the websites you've found, and writing the more general re is perhaps painful and certainly harder to comprehend.

refactoring suggestions:

You could learn more about lists. I haven't tested any of these replacements---I'll bet they're mostly correct and all conceptually correct.
Code:
    # index stride
    self.leeches = self.seeds[1::2] # make leeches from the odd index entries of seeds
    self.seeds = self.seeds[::2]    # retain even entries

    # in place of

    i = 0
    self.leeches = list()
    for s in self.seeds :
        if i == 0 :
            i += 1
            continue
        elif i == 1 :
            self.leeches.append(s)
            self.seeds.remove(s)
            i == 0

Code:
    # extend method
    self.all_downloads.extend(self.downloads)

    # in place of

    for d in self.downloads : self.all_downloads.append(d)

Code:
    # list indexing for assignment
    self.all_links[1:1+len(self.all_names)] = self.all_names

    # in place of

    id = 1
    for name in self.all_names :
        self.all_links[id] = name
        id += 1

reduce duplicate code
Code:
    # reduce duplicate code
    # move the lower method call so you do it just once.
    action = raw_input(' T >>> ')  .  lower()  # stick the lower here
    if action == 'q' or action == 'quit':

    # in place of

    action = raw_input(' T >>> ')
    if action.lower() == 'q' or action.lower() == 'quit':

Code:
    # reduce duplicate code
    # use the string index method
    # if website['seed_re'] is a string

    re_count = website['seed_re'].index('[')

    # in place of

    seed_re = ''
    re_count = 0
    while website['seed_re'][re_count] != '[' :
        seed_re += website['seed_re'][re_count]
        re_count += 1

list comprehension
Code:
    # consider list comprehensions.  Actually, everytime I've
    # timed a list comprehension versus a for loop the for loop
    # such as you have has always performed better.

    self.leeches = [leech[len(leech_re)] for leech in self.leeches]

    # in place of

    for i in range(len(self.leeches)):
        self.leeches[i] = self.leeches[i][len(leech_re):]


__________________
[code]Code tags[/code] are essential for python code!

Last edited by b49P23TIvg : July 29th, 2012 at 09:14 PM.

Reply With Quote
  #3  
Old July 30th, 2012, 07:55 PM
Sparkon Sparkon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 15 Sparkon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 24 m 14 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Looks good to me, leaving a few ideas. This post is so complicated to write that if I had other thoughts they are lost.

html suggestions:
Take this regular expression. As I recall, double quotes about a string that doesn't contain spaces is optional.
h33t_torrent['seed_re'] = '<span style="color:[a-z]*">[0-9]*'
Your regular expression works for the websites you've found, and writing the more general re is perhaps painful and certainly harder to comprehend.

refactoring suggestions:

You could learn more about lists. I haven't tested any of these replacements---I'll bet they're mostly correct and all conceptually correct.
Code:
    # index stride
    self.leeches = self.seeds[1::2] # make leeches from the odd index entries of seeds
    self.seeds = self.seeds[::2]    # retain even entries

    # in place of

    i = 0
    self.leeches = list()
    for s in self.seeds :
        if i == 0 :
            i += 1
            continue
        elif i == 1 :
            self.leeches.append(s)
            self.seeds.remove(s)
            i == 0

Code:
    # extend method
    self.all_downloads.extend(self.downloads)

    # in place of

    for d in self.downloads : self.all_downloads.append(d)

Code:
    # list indexing for assignment
    self.all_links[1:1+len(self.all_names)] = self.all_names

    # in place of

    id = 1
    for name in self.all_names :
        self.all_links[id] = name
        id += 1

reduce duplicate code
Code:
    # reduce duplicate code
    # move the lower method call so you do it just once.
    action = raw_input(' T >>> ')  .  lower()  # stick the lower here
    if action == 'q' or action == 'quit':

    # in place of

    action = raw_input(' T >>> ')
    if action.lower() == 'q' or action.lower() == 'quit':

Code:
    # reduce duplicate code
    # use the string index method
    # if website['seed_re'] is a string

    re_count = website['seed_re'].index('[')

    # in place of

    seed_re = ''
    re_count = 0
    while website['seed_re'][re_count] != '[' :
        seed_re += website['seed_re'][re_count]
        re_count += 1

list comprehension
Code:
    # consider list comprehensions.  Actually, everytime I've
    # timed a list comprehension versus a for loop the for loop
    # such as you have has always performed better.

    self.leeches = [leech[len(leech_re)] for leech in self.leeches]

    # in place of

    for i in range(len(self.leeches)):
        self.leeches[i] = self.leeches[i][len(leech_re):]



Thanks for reading my program and writing this! about the HTML regex is true... the regex are ofcourse site specific, but to add another site you can simply analyze the page with firebug and add more links.

this one is so ridiculos thanks for the tip :
Code:
    i = 0
    self.leeches = list()
    for s in self.seeds :
        if i == 0 :
            i += 1
            continue
        elif i == 1 :
            self.leeches.append(s)
            self.seeds.remove(s)
            i == 0

i don't know where to start i didn't even know the .index() method that definetly is faster than my for loop
But if you say that the list comprehension is slower i think i'll stick with the 'for loop', because the search is already slow so i'm not gonna slow it down more!.
Thanks a lot for the time, i'm gonna fix the thing you pointed, they are really helpful. But what do you think about the rest of the program?

Reply With Quote
  #4  
Old July 30th, 2012, 08:13 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,376 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 12 h 21 m 42 sec
Reputation Power: 383
Quote:
Originally Posted by b49P23TIvg
Looks good to me


The things you want to "fix" aren't "broken". I'm merely aware of python shorthand.

Reply With Quote
  #5  
Old July 30th, 2012, 09:01 PM
Sparkon Sparkon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 15 Sparkon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 24 m 14 sec
Reputation Power: 0
Ok :P

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Torrent Downloader Scripts

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap