Advertisement
Azelphur

Untitled

Jul 6th, 2011
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1.     def getData(self):
  2.         """ Get pending calendar events """
  3.  
  4.         def pendingPageLoaded(self, result):
  5.             # Time to break out the HTML parser
  6.             soup = BeautifulSoup(result)
  7.             soupupcoming = soup.findAll('li', 'event-category')
  8.             soupevents = soupupcoming[0].findAll('li', "event-summary")
  9.        
  10.             events = []
  11.  
  12.             for soupevent in soupevents:
  13.                 event = {}
  14.            
  15.                 # Get the event id
  16.                 event["event-id"] = soupevent['data-id']
  17.  
  18.                 # Get the event title
  19.                 event["title"] = BeautifulStoneSoup(soupevent.findAll('h4', 'subheader name')[0].text, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  20.  
  21.                 # Get the event description
  22.                 event["description"] = BeautifulStoneSoup(soupevent.findAll('p', 'description')[0].text, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  23.  
  24.                 # Get the date of the event
  25.                 event["date"] = soupevent.findAll('span', 'datetime')[0].text
  26.  
  27.                 # Are we invited?
  28.                 if soupevent.findAll('span', 'status invited'):
  29.                     event["invited"] = True
  30.                 else:
  31.                     event["invited"] = False
  32.  
  33.                 events.append(event)
  34.             return events # This needs to make it's way back to whatever called getData somehow
  35.  
  36.        
  37.         # Grab the calendar page
  38.         d = client.getPage("https://eu.battle.net/wow/en/vault/character/event", cookies=self.cookies)
  39.  
  40.         d.addCallback(self.pendingPageLoaded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement