Advertisement
xcodinas

Untitled

Mar 29th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. def jornada_float(jornada):
  2. try:
  3. int(jornada)
  4. return True
  5. except ValueError:
  6. return False
  7.  
  8.  
  9. def get_jornada(jornada, equipo=None):
  10. matchInfoRegexp = "(\d{1,2}) (.*), (\d{4}) \xb7 ((\d{1,2}:\d{1,2}) (am|pm))(.*?)"
  11. web = urllib.request.urlopen('http://antoniovela.es/ligafcmv/756-2/?league_id=4&match_day_4=' + str(jornada)).read()
  12. soup = BeautifulSoup(web, "html.parser")
  13. matchTable = soup.find('table', {'class':['leaguemanager', 'matchtable']});
  14.  
  15. text = "🔫"
  16. text += "<b>Torneo FCMV - Jornada " + str(jornada) + "</b>"
  17. text += "🔫"
  18. text += "\n\n"
  19.  
  20. if(matchTable):
  21. teamFound = (equipo is None);
  22. matches = matchTable.findAll('td', {'class': 'match'})
  23.  
  24. for match in matches:
  25. matchTime = ""
  26. matchDate = ""
  27.  
  28. matchInfo = match.find('br').previousSibling
  29. matchTeams = match.find('strong');
  30. matchScore = match.parent.find('td', {'class':'score'});
  31. regMatch = re.search(matchInfoRegexp, matchInfo)
  32.  
  33. if(regMatch):
  34. matchTime = regMatch.group(4).rjust(8, '0');
  35. matchDate = regMatch.group(1) + " " + regMatch.group(2) + " " + regMatch.group(3);
  36. if(matchInfo and matchTeams and matchScore):
  37. if((equipo is None) or (matchTeams.text.lower().find(equipo.lower()) > -1)):
  38. text += "🗓" + " "
  39. text += matchTime.strip()
  40. text += " - "
  41. text += matchDate.strip()
  42. text += "\n"
  43. text += "âš”" + " "
  44. text += "<i>" + matchTeams.text.strip() + "</i>"
  45. text += "\n"
  46. text += "âš–" + " "
  47. text += "<b>" + matchScore.text.strip() + "</b>"
  48. text += "\n\n"
  49.  
  50. teamFound = True;
  51.  
  52. if(teamFound == False):
  53. text += "Equipo no encontrado";
  54. text += "\n";
  55. else:
  56. text += "Jornada no encontrada";
  57. text += "\n";
  58.  
  59. text += "\n" + 'Mas en <a href="http://www.ligafcmv.tk/">LIGAFCMV</a>'
  60. return(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement