colonelpanic8 / okcupyd

A Library that enables programmatic interaction with okcupid.com, using okcupid.com's private okcupid JSON API and html scraping when necessary.
MIT License
110 stars 18 forks source link

fetching looking_for.ages sometimes fails #59

Open dubiousjim opened 9 years ago

dubiousjim commented 9 years ago

Changing line 34 of looking_for.py from:

_ages_re = re.compile(u'Ages ([0-9]{1,3})\u2013([0-9]{1,3})')

to:

_ages_re = re.compile(u' *Ages ([0-9]{1,3})\u2013([0-9]{1,3})')

seems to fix it.

dubiousjim commented 9 years ago

I think OKCupid changed their html recently. This issue only showed up with a few profiles (out of 1000s).

dubiousjim commented 9 years ago

Also, I just now came across a profile where p.looking_for.raw_fields['ages'] was ' Age 41 '. This can be accommodated by adding:

_ages_re2 = re.compile(u' *Age ([0-9]{1,3})')

near the top of looking_for.py, and editing the definition of ages later in that file like this:

  def ages(self):
      """The age range that the user is interested in."""
      match = self._ages_re.match(self.raw_fields.get('ages'))
    + if not match:
    +     match = self._ages_re2.match(self.raw_fields.get('ages'))
    +     return self.Ages(int(match.group(1)),int(match.group(1)))
      return self.Ages(int(match.group(1)), int(match.group(2)))
colonelpanic8 commented 9 years ago

Cool, nice finds. Do you have an example profile that this happens with

Do you want to make a pull request? I'm happy to fix things I guess if not, but it would be greatly appreciated.

dubiousjim commented 9 years ago

Ehh, I don't want to publish my own copy of the repository just for a few tiny patches. I can email you patches if you prefer.