Question for t0mm0
#1
How do you use the add_directory with the total_items for the progress bar

Code:
for url,name in match:
            addon.add_directory({'mode' : 'GetMovieSource', 'url' : url , 'img' : '' }, name , total_items=len(match))

i get an error. is this the correct way.?
Reply
#2
k_zeon Wrote:How do you use the add_directory with the total_items for the progress bar

Code:
for url,name in match:
            addon.add_directory({'mode' : 'GetMovieSource', 'url' : url , 'img' : '' }, name , total_items=len(match))

i get an error. is this the correct way.?

can't really help without knowing what 'match' is and what the error is....
Reply
#3
t0mm0 Wrote:can't really help without knowing what 'match' is and what the error is....

Not to worry. got it sorted.

another question. How would you exit a for statement.

for name in match:

if x = 1 then exit for << this is what i would do in VB6

does match have a count ie match(x) that i can check for. still learning.
Reply
#4
k_zeon Wrote:Not to worry. got it sorted.

another question. How would you exit a for statement.

for name in match:

if x = 1 then exit for << this is what i would do in VB6

does match have a count ie match(x) that i can check for. still learning.

you still haven't said what 'match' is or what you are trying to do. can you post some code?

python is not (thankfully!) vb6 - you need to think of what it is you are trying to do and then do it in python rather than think of how to do it in vb6 and try and translate, you'll find you end up with neater code that way Wink
Reply
#5
t0mm0 Wrote:you still haven't said what 'match' is or what you are trying to do. can you post some code?

python is not (thankfully!) vb6 - you need to think of what it is you are trying to do and then do it in python rather than think of how to do it in vb6 and try and translate, you'll find you end up with neater code that way Wink

sorry , here is some code.


Code:
html = net.http_GET(url).content
        match=re.compile('<li class="searchList"><a href="(.+?)">(.+?)</a> <span>(.+?)</span>').findall(html)
        total = len(match)
        for url,name,sYear in match:

             if for example i only wanted the for to run 5 times only then exit for <<<<<<<

            addon.add_directory({'mode' : 'GetMovieSource', 'url' : url , 'img' : '' }, CleanHTML(name) + '  ' + sYear, total_items=total)
        addon.end_of_directory()
Reply
#6
k_zeon Wrote:sorry , here is some code.


Code:
html = net.http_GET(url).content
        match=re.compile('<li class="searchList"><a href="(.+?)">(.+?)</a> <span>(.+?)</span>').findall(html)
        total = len(match)
        for url,name,sYear in match:

             if for example i only wanted the for to run 5 times only then exit for <<<<<<<

            addon.add_directory({'mode' : 'GetMovieSource', 'url' : url , 'img' : '' }, CleanHTML(name) + '  ' + sYear, total_items=total)
        addon.end_of_directory()

ok, cool, so match is a list of tuples and you only want to iterate through the first 5 tuples in the list. python has a cool feature called slices (here is a really good clear explanation)

here is an example:
Code:
import re

html = '''<html>
       <li class="searchList"><a href="http://url1">name1</a> <span>1901</span>
       <li class="searchList"><a href="http://url2">name2</a> <span>1902</span>
       <li class="searchList"><a href="http://url3">name3</a> <span>1903</span>
       <li class="searchList"><a href="http://url4">name4</a> <span>1904</span>
       <li class="searchList"><a href="http://url5">name5</a> <span>1905</span>
       <li class="searchList"><a href="http://url6">name6</a> <span>1906</span>
       <li class="searchList"><a href="http://url7">name7</a> <span>1907</span>
       </html>
       '''
      
matches = re.findall('<li class="searchList"><a href="(.+?)">(.+?)</a> <span>(.+?)</span>', html)

for match in matches[:5]:
    print match # or do whatever else you want with it

if you run this you will see the following output:
Code:
('http://url1', 'name1', '1901')
('http://url2', 'name2', '1902')
('http://url3', 'name3', '1903')
('http://url4', 'name4', '1904')
('http://url5', 'name5', '1905')


the nice part is that even if nothing matches you will not get any errors (the code inside the for loop will just not be run at all)

also if less than five items are matched, the code in the for loop will only run on each match that does exist and not produce an error.

hope that helps!

t0mm0
Reply

Logout Mark Read Team Forum Stats Members Help
Question for t0mm00