Functions

There are several general function available in the framework.
A short overview below:

 

Fetch an Url

  1. ba.FetchUrl(url, cacheTime, xhr, params)

A function to get a http request, so you can fetch the html content of a specific website. It has the option to cache the results to release the load on internet servers. If the variable cachetime is set it will automatically loads the page from the cache instead of the internet as long as the cache is not expired yet. It is using a GET request on default.

Note that the caching of a page speeds up the loading time, but also is adding information to the database and extending the disk usage. For boxee 0.9 users this is no problem but the boxee box has a limited amount of space available. So please use the cache function appropriate.

 

Passing variables:

Variable Type Description Needed
url string The path to the website Yes
cacheTime integer Time period to keep the http data in cache (in seconds) No
xhr Boolean [True,False] Send the request as ajax xhr No
params string Use POST request with params (var=test&var2=test2) No

 

Examples:

  1. # GET request
  2. path = "http://www.google.com"
  3. data = ba.FetchUrl(path)
  4.  
  5. # GET request with params
  6. path = "http://www.google.com?search=boxee&var=delta"
  7. data = ba.FetchUrl(path)
  8.  
  9. # GET request cached for 60 minutes
  10. path = "http://www.google.com"
  11. data = ba.FetchUrl(path, 3600)
  12.  
  13. # XHR ajax call not cached
  14. path = "http://www.google.com"
  15. data = ba.FetchUrl(path, 0, True)
  16.  
  17. # POST Request not cached
  18. path = "http://www.google.com"
  19. params = "search=boxee&var=delta"
  20. data = ba.FetchUrl(path, 0, False, params)
  21.  
  22. # POST Request cached for 5 minutes
  23. path = "http://www.google.com"
  24. params = "search=boxee&var=delta"
  25. data = ba.FetchUrl(path, 300, False, params)

 

Set User Agent

  1. ba.UserAgent(var):

A function to set the user agent of the http requests

 

Passing variables:

Variable Type Description Needed
var string User agent string Yes

 

BeautifulSoup

  1. BeautifulSoup(data):

A very usefull parser to parse xml or html data.
It transforms the string into variables that can be searched or called. For more information regarding BeautifulSoup please read the manual on crummy.com

 

Main variables:

Variable Type Description Needed
data string A string with html / xml data Yes

 

Examples:

  1. doc = [‘<html><head><title>Page title</title></head>’,
  2.        ‘<body><p id="firstpara" align="center">This is paragraph <b>one</b></p>’,
  3.        ‘<p id="secondpara" align="blah">This is paragraph <b>two</b></p></body>’,
  4.        ‘</html>’]
  5. soup = BeautifulSoup(.join(doc))
  6.  
  7. soup.head.title
  8. # <title>Page title</title>
  9.  
  10. soup.body.p.b.string
  11. # u’one’
  12.  
  13. soup.findAll([‘title’, ‘p’])
  14. # [<title>Page title</title>,
  15. #  <p id="firstpara" align="center">This is paragraph <b>one</b>.</p>,
  16. #  <p id="secondpara" align="blah">This is paragraph <b>two</b>.</p>]
  1. doc = [‘<html><head><title>Page title</title></head>’,
  2.        ‘<body><p id="firstpara" align="center">This is paragraph <b>one</b></p>’,
  3.        ‘<p id="secondpara" align="blah">This is paragraph <b>two</b></p></body>’,
  4.        ‘</html>’]
  5. soup = BeautifulSoup(.join(doc))
  6.  
  7. for info in soup.findAll(‘p’):
  8. # create your boxee list at this point and extract data from the p tag
  9. # example info.b.contents[0] will result in ‘one’ and in the second list in ‘two’

  • *

    You may use these HTML tags: <a> <abbr> <acronym> <b> <blockquote> <cite> <code> <del> <em> <i> <q> <strike> <strong>

  • Comment Feed for this Post
Go to Top