def update_bill(self, bill): """ Check if a bill exists in datastore, and update its stats. """ this_bill = Bill.get_by_key_name(bill['title']) logging.info(bill['title']) if this_bill is None: this_bill = self.create_bill(bill) is_new_bill = True else: is_new_bill = False this_bill.rank = bill['rank'] import urllib self.request_args = {'bill_id': bill['id']} self.formatted_args = urllib.urlencode(self.request_args) from google.appengine.api import urlfetch fetch_page = urlfetch.fetch( url = OPENCONGRESS_INFO_URL + self.formatted_args, method = urlfetch.GET) from utils.BeautifulSoup import BeautifulSoup document = BeautifulSoup(fetch_page.content) property_count = 0 this_bill.introduction_date = str(document.findAll('li')[property_count]).split('</strong> ')[1].split('</li>')[0] this_bill.status = str(document.findAll('li')[property_count + 1]).split('</strong> ')[1].split('</li>')[0] if this_bill.status == "This Bill Has Become Law": property_count = -1 # no next step else: this_bill.next_step = str(document.findAll('li')[property_count + 2]).split('</strong> ')[1].split('</li>')[0] this_bill.latest_action = str(document.findAll('li')[property_count + 3]).split('</strong> ')[1].split('</li>')[0] if len( this_bill.latest_action ) > 68: this_bill.latest_action = " ".join(this_bill.latest_action.split(' ')[:9]) + "..." this_bill.sponsor = str(document.findAll('li')[property_count + 4]).split('</strong> ')[1].split('</li>')[0].decode('utf-8') this_bill.sponsor_name = this_bill.sponsor.split("[")[0] self.save.append(this_bill) if is_new_bill: self.send_email_updates(this_bill) return
def get(self): """ Renders an frame with a webpage used to create quizzes. For this app, the frame contains the text of pending Congressional legislation. """ import urllib bill_name = urllib.unquote( self.request.path.split('/bill/')[1] ) self.this_bill = Bill.get_by_key_name(bill_name) if self.this_bill is None: logging.error('bill %s not found', bill_name) return self.redirect('/bill_not_found') from models import ProficiencyTopic template_values = {'url': self.get_bill_url(), 'subject_key': APP_NAME, 'topic_name': self.this_bill.title, } path = tpl_path(TEMPLATE_PATH + 'iframe.html') self.response.out.write(template.render(path, template_values)) return