
July 30th, 2012, 07:55 PM
|
|
Registered User
|
|
Join Date: Mar 2012
Posts: 15
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?
|