示例#1
0
def user_profile_parse(u_id, u_name = ""):
  
  try:
    ba_connect = BACn()
    burl = ba_connect.user_profile(u_id, u_name)
    lx_doc = fromstring(burl.read())
  except Exception as e:
    return User(u_id, None, None, None, None), e
  
  if not u_name:
    u_name = lx_doc.xpath('//*[@class="username"]')[0].text
  
  title = lx_doc.xpath('//*[@class="userTitle"]')[0].text
  
  loc = lx_doc.xpath('//a[contains(@href,"misc/location-info?")]')
  u_loc = loc[0].text if loc else "Unknown"
  
  blurb = lx_doc.xpath('//*[@class="userBlurb"]/text()')
  if any(s for s in blurb if 'Male' in s):
    sex = "Male"
  elif any(s for s in blurb if 'Female' in s):
    sex = "Female"
  else:
    sex = "Unspecified"
    
  return User(u_id, u_name, title, u_loc, sex), None
示例#2
0
def user_profile_parse(u_id, u_name=""):

    try:
        ba_connect = BACn()
        burl = ba_connect.user_profile(u_id, u_name)
        lx_doc = fromstring(burl.read())
    except Exception as e:
        return User(u_id, None, None, None, None), e

    if not u_name:
        u_name = lx_doc.xpath('//*[@class="username"]')[0].text

    title = lx_doc.xpath('//*[@class="userTitle"]')[0].text

    loc = lx_doc.xpath('//a[contains(@href,"misc/location-info?")]')
    u_loc = loc[0].text if loc else "Unknown"

    blurb = lx_doc.xpath('//*[@class="userBlurb"]/text()')
    if any(s for s in blurb if 'Male' in s):
        sex = "Male"
    elif any(s for s in blurb if 'Female' in s):
        sex = "Female"
    else:
        sex = "Unspecified"

    return User(u_id, u_name, title, u_loc, sex), None
示例#3
0
def beer_meta_parse(brewer_id, beer_id):
    def int_or_def(nstr, nerr):
        return int(nstr) if nstr.isdigit() else nerr

    BeerMeta = namedtuple(
        'BeerMeta',
        'brewer_id, beer_id, name, style_num, style, abv, ibu, date_added, ba_score, bros_score, notes'
    )

    try:
        ba_connect = BACn()
        burl = ba_connect.beer_meta(brewer_id, beer_id)
        lx_doc = fromstring(burl.read())
        burl.close()
    except:
        return BeerMeta(brewer_id, beer_id, *(9 * [None]))

    main = lx_doc.xpath('//div[@class="mainContent"]')[0]
    name = main.xpath('//div[@class="titleBar"]')[0][0].text.strip()
    metatab = main.xpath('//div[@id="baContent"]')[0].xpath('child::table')[0]
    ba_scr = int_or_def(
        metatab.xpath('//span[@class="BAscore_big"]')[0].text, -1)
    bro_scr = int_or_def(
        metatab.xpath('//span[@class="BAscore_big"]')[1].text, -1)
    style_link = metatab.xpath('//a[contains(@href, "/beer/style")]')[0]
    style_num = int_or_def(style_link.xpath('@href')[0].split('/')[3], -1)
    style = style_link.xpath('b')[0].text

    qual_dat = style_link.xpath('..//text()')

    rec_notes = False
    notes = []
    abv, ibu, date_add = 0, 0, 0
    for t in qual_dat:
        if '|' in t and 'Style' not in t:
            ti = re.findall(r'\d+', t)
            abv = ".".join(ti) + '%'
        elif 'IBU' in t:
            ti = re.findall(r'\d+', t)
            ibu = int_or_def(ti[0], -1)
        elif 'added' in t:
            date_add = t.split("on")[1].replace(')', '').strip()
        elif 'Notes' in t:
            rec_notes = True
        elif rec_notes and t.strip() != '\n':
            notes.append(t.strip())

    notes = ' '.join(notes)

    return BeerMeta(brewer_id, beer_id, name, style_num, style, abv, ibu,
                    date_add, ba_scr, bro_scr, notes)
示例#4
0
def beer_meta_parse(brewer_id, beer_id):
  def int_or_def(nstr, nerr):
    return int(nstr) if nstr.isdigit() else nerr
    
  BeerMeta = namedtuple('BeerMeta',
    'brewer_id, beer_id, name, style_num, style, abv, ibu, date_added, ba_score, bros_score, notes')

  try:
    ba_connect = BACn()
    burl = ba_connect.beer_meta(brewer_id, beer_id)
    lx_doc = fromstring(burl.read())
    burl.close()
  except:
    return BeerMeta(brewer_id, beer_id, *(9*[None]))
    
  main = lx_doc.xpath('//div[@class="mainContent"]')[0]
  name = main.xpath('//div[@class="titleBar"]')[0][0].text.strip()
  metatab = main.xpath('//div[@id="baContent"]')[0].xpath('child::table')[0]
  ba_scr = int_or_def(metatab.xpath('//span[@class="BAscore_big"]')[0].text,-1)
  bro_scr = int_or_def(metatab.xpath('//span[@class="BAscore_big"]')[1].text,-1)
  style_link = metatab.xpath('//a[contains(@href, "/beer/style")]')[0]
  style_num = int_or_def(style_link.xpath('@href')[0].split('/')[3],-1)
  style = style_link.xpath('b')[0].text
  
  
  qual_dat = style_link.xpath('..//text()')
  
  rec_notes = False
  notes = []
  abv, ibu, date_add = 0, 0, 0
  for t in qual_dat:
    if '|' in t and 'Style' not in t:
      ti = re.findall(r'\d+', t)
      abv = ".".join(ti) + '%'
    elif 'IBU' in t:
      ti = re.findall(r'\d+', t)
      ibu = int_or_def(ti[0], -1)
    elif 'added' in t:
      date_add = t.split("on")[1].replace(')', '').strip()
    elif 'Notes' in t:
      rec_notes = True
    elif rec_notes and t.strip() != '\n':
      notes.append(t.strip())
        
  notes = ' '.join(notes)
  
  return BeerMeta(
    brewer_id, beer_id,
    name, style_num, style, abv, ibu,
    date_add, ba_scr, bro_scr, notes)
示例#5
0
def brewer_meta_parse(brewer_id):
  
  BrewerMeta = namedtuple('BrewerMeta', 'id, name, location')
  
  ba_connect = BACn()
  burl = ba_connect.brewer_meta(brewer_id)
  lx_doc = fromstring(burl.read())
  burl.close()

  name = lx_doc.xpath('//div[@class="titleBar"]')[0].xpath('h1/text()')[0]

  loc_inf = lx_doc.xpath('//a[contains(@href, "/place/directory")]')
  loc = ', '.join(l.text for l in loc_inf if l.xpath('@href')[0] != '/place/directory/')
  
  return BrewerMeta(brewer_id, name, loc)
示例#6
0
def brewer_meta_parse(brewer_id):

    BrewerMeta = namedtuple('BrewerMeta', 'id, name, location')

    ba_connect = BACn()
    burl = ba_connect.brewer_meta(brewer_id)
    lx_doc = fromstring(burl.read())
    burl.close()

    name = lx_doc.xpath('//div[@class="titleBar"]')[0].xpath('h1/text()')[0]

    loc_inf = lx_doc.xpath('//a[contains(@href, "/place/directory")]')
    loc = ', '.join(l.text for l in loc_inf
                    if l.xpath('@href')[0] != '/place/directory/')

    return BrewerMeta(brewer_id, name, loc)