def handleDistribHtmlPage(self, htmlPage): euro7startRx = QRegExp("data-grid-id=\"(\\d*)\"") indexGrille = "" posi = 0 while posi != -1 and indexGrille != self._gridList[self._indexGrille][0]: print "posi = %d" % posi print "indexGrille = %s" % indexGrille print "self._indexGrille = %s" % self._gridList[self._indexGrille][0] posi= euro7startRx.indexIn(htmlPage, posi+1) indexGrille = euro7startRx.cap(1) euro7TeamRx = QRegExp("<label for=\"[^\"]*\">([^<]*)<\/label>") self._grid = Grille() self._grid.setReturnRate(0.75) self._grid.setFirstRankRate(0.55) self._grid.setScndRankRate(0.45) jackpot = int(self._gridList[self._index][2]) self._grid.setJackpot(jackpot) self._grid.setNbPlayers(jackpot) index_l = 0 total = 0 #size_l = 5 i=0 #try: if True: posi= euro7TeamRx.indexIn(htmlPage, posi) print "posi = %d" % posi while posi != -1 and i < self._gridSize: i += 1 team1 = euro7TeamRx.cap(1) print "team1 = %s" % team1 posi= euro7TeamRx.indexIn(htmlPage, posi+1) posi= euro7TeamRx.indexIn(htmlPage, posi+1) team2 = euro7TeamRx.cap(1) print "indice %i" % i print "team2 = %s" % team2 match = Match(team1 + " vs " + team2) match.setTeam1(team1) match.setTeam2(team2) p1 = 0.33 pN = 0.33 p2 = 0.33 total = p1 + pN +p2 r1 = p1/total*100 r2 = p2/total*100 rN = pN/total*100 match.setRepartition(p1/total, pN/total, p2/total) self._grid.addGame(match) print "game added : %d" % i posi= euro7TeamRx.indexIn(htmlPage, posi+1) #except: #msg = QMessageBox() #msg.setText("Loading page error") #msg.exec_() #self.__workbook1.save(self.__outPutFileName) return
def handleHtmlPage(self, htmlPage): tup = () self._gridList = [] wina7rx = QRegExp("\{\"pool_id\":700(\\d+).*\"pool_end\":(\\d+).*\"guaranteed_amount\":(\\d+).*\}") posi = wina7rx.indexIn(str(htmlPage)) ngrille = wina7rx.cap(1) print "ngrille=%s" % ngrille #self.gridList.append(wina7rx.cap(1)) date = wina7rx.cap(2) print "date=%s" % date jackpot = wina7rx.cap(3) print "jackpot=%s" % jackpot tup = (ngrille, date, jackpot) self._gridList.append(tup) while posi != -1 : posi = wina7rx.indexIn(str(htmlPage), posi+1) ngrille = wina7rx.cap(1) print "ngrille=%s" % ngrille date = wina7rx.cap(2) print "date=%s" % date jackpot = wina7rx.cap(3) print "jackpot=%s" % jackpot tup = (ngrille, date, jackpot) self._gridList.append(tup) print self._gridList
def handleHtmlPage(self, htmlPage): tup = () self._gridList = [] loto15rx = QRegExp("<option selected=\"selected\" value=\"(\\d+)\">") loto15DateRx = QRegExp("\\d*\\s*du\\s*(\\d*\/\\d*\/\\d*)<\/option>") posi_encours = loto15rx.indexIn(str(htmlPage)) ngrille = loto15rx.cap(1) print "ngrille=%s" % ngrille posi = loto15DateRx.indexIn(str(htmlPage), posi_encours) date = loto15DateRx.cap(1) print "Date=%s" % date dmy = string.split(date, "/") print "dmy :%s" % str(dmy) qdatetime = QDateTime() qdatetime.setDate(QDate(int("20"+dmy[2]), int(dmy[1]), int(dmy[0]))) qdatetime = qdatetime.addDays(1).addSecs(-1) # next day epochDate = qdatetime.toMSecsSinceEpoch()/1000 print "epochDate=%d" % epochDate tup = (ngrille, epochDate, 0) self._gridList.append(tup) loto15rx = QRegExp("<option value=\"(\\d+)\">") posi = 0 posi = loto15rx.indexIn(str(htmlPage), posi+1) while posi != -1 :#and posi < posi_encours: ngrille = loto15rx.cap(1) print "ngrille=%s" % ngrille posi = loto15DateRx.indexIn(str(htmlPage), posi) date = loto15DateRx.cap(1) print "Date=%s" % date dmy = string.split(date, "/") qdatetime = QDateTime() qdatetime.setDate(QDate(int("20"+dmy[2]), int(dmy[1]), int(dmy[0]))) qdatetime = qdatetime.addDays(1).addSecs(-1) # next day epochDate = qdatetime.toMSecsSinceEpoch()/1000 print "epochDate=%d" % epochDate tup = (ngrille, epochDate, 0) self._gridList.append(tup) posi = loto15rx.indexIn(str(htmlPage), posi+1)
def highlightBlock(self, text): """ Highlight a block of text """ if self.enabled is False: return text = unicode(text) original_text = text prev_data = self.currentBlock().previous().userData() if prev_data is not None: self._lexer._saved_state_stack = prev_data.syntax_stack elif hasattr(self._lexer, '_saved_state_stack'): del self._lexer._saved_state_stack # Lex the text using Pygments index = 0 for token, text in self._lexer.get_tokens(text): length = len(text) self.setFormat(index, length, self._get_format(token)) index += length if hasattr(self._lexer, '_saved_state_stack'): data = PygmentsBlockUserData( syntax_stack=self._lexer._saved_state_stack) self.currentBlock().setUserData(data) # Clean up for the next go-round. del self._lexer._saved_state_stack #Spaces expression = QRegExp('\s+') index = expression.indexIn(original_text, 0) while index >= 0: index = expression.pos(0) length = len(expression.cap(0)) self.setFormat(index, length, self._get_format(Whitespace)) index = expression.indexIn(original_text, index + length) self.hilighlightingBlock.emit(original_text, self)
class MacroHighlighter(QSyntaxHighlighter): def __init__(self,textboxdoc,valid_list_of_commands): QSyntaxHighlighter.__init__(self,textboxdoc) self.valid_syntax="|".join([command.regexp_str for command in valid_list_of_commands]) self.my_expression = QRegExp(self.valid_syntax) #define a blue font format for valid commands self.valid = QTextCharFormat() self.valid.setForeground(Qt.black) #define a bold red font format for invalid commands self.invalid = QTextCharFormat() self.invalid.setFontWeight(QFont.Bold) self.invalid.setForeground(Qt.red) #define a blue font format for valid parameters self.valid_value=QTextCharFormat() self.valid_value.setFontWeight(QFont.Bold) #self.valid_value.setForeground(QColor.fromRgb(255,85,0)) self.valid_value.setForeground(Qt.blue) def highlightBlock(self, text): #this function is automatically called when some text is changed #in the texbox. 'text' is the line of text where the change occured #check if the line of text contains a valid command match = self.my_expression.exactMatch(text) if match: #valid command found: highlight the command in blue self.setFormat(0, len(text), self.valid) #highlight the parameters in orange #loop on all the parameters that can be captured for i in range(self.my_expression.captureCount()): #if a parameter was captured, it's position in the text will be >=0 and its capture contains some value 'xxx' #otherwise its position is -1 and its capture contains an empty string '' if self.my_expression.pos(i+1)!=-1: self.setFormat(self.my_expression.pos(i+1), len(self.my_expression.cap(i+1)), self.valid_value) else: #no valid command found: highlight in red self.setFormat(0, len(text), self.invalid)
def handleDistribHtmlPage(self, htmlPage): print "handleDistribHtmlPage" jackpot = int(self._gridList[self._index][2]) / 0.70 self._grid.setJackpot(jackpot) self._grid.setNbPlayers(jackpot) htmlStrPage = filter(onlyascii, str(htmlPage)) teamString = "<td class=\"center matchs_av\">((\\(?\\)?\\d*\\w*\\.?'?-?\\s*)*)<\/td>" enfOfGridString = "<div class=\"repart_legende\">" loto15Teamrx = QRegExp(teamString) endOfGridRx = QRegExp(enfOfGridString) posiEndOfGrid= endOfGridRx.indexIn(htmlStrPage, 0) repString = ">(\\d*,*\\d*)\\s*\%<" loto15Reprx = QRegExp(repString) index_l = 0 total = 0 posi = 0 i = 0 #try: if True : posi= loto15Teamrx.indexIn(htmlStrPage, posi+1) print "posi = %d" % posi while posi != -1: i+=1 print "indice %i" % i team1 = loto15Teamrx.cap(1) posi= loto15Teamrx.indexIn(htmlStrPage, posi+1) print "posi2 = %d" % posi print "posi2 = %d" % posi print "team1 = %s" % team1 team2 = loto15Teamrx.cap(1) posiMax= loto15Teamrx.indexIn(htmlStrPage, posi+1) if posiMax < 0: posiMax = posiEndOfGrid print "posi3 = %d" % posi print "team2 = %s" % team2 match = Match(team1 + " vs " + team2) match.setTeam1(team1) match.setTeam2(team2) posiInter= loto15Reprx.indexIn(htmlStrPage, posi+1) print "posiInter = %d" % posiInter print "posiMax = %d" % posiMax if (posiInter > 0) and (posiInter <= posiMax) : posi = posiInter print "posi4 = %d" % posi p1 = float(loto15Reprx.cap(1).replace(",",".")) posi= loto15Reprx.indexIn(htmlStrPage, posi+1) print "posi5 = %d" % posi pN = float(loto15Reprx.cap(1).replace(",",".")) posi= loto15Reprx.indexIn(htmlStrPage, posi+1) print "posi6 = %d" % posi p2 = float(loto15Reprx.cap(1).replace(",",".")) total = float(p1+pN+p2) r1 = p1/total*100 r2 = p2/total*100 rN = pN/total*100 match.setRepartition(p1/total, pN/total, p2/total) self._grid.addGame(match) print "game added : %d" % i posi= loto15Teamrx.indexIn(htmlStrPage, posi+1) print "posi1 = %d" % posi print "%d grilles" % i self._gridSize = i #except: #msg = QMessageBox() #msg.setText("Loading page error") #msg.exec_() #self.__workbook1.save(self.__outPutFileName) return
def handleHtmlPage(self, htmlPage): tup = () self._gridList = [] htmlAscii = filter(onlyascii, str(htmlPage)) #print "html = %s" % htmlAscii mini5NumGrillerx = QRegExp("<div class=\"grid grid-3\" data-grid-id=\"(\\d+)\" data-grid-type=\"3\">") mini5DateRx = QRegExp("<span\\s*class=\"date\">[\\s\\n\\r]*(\\w+)\\s*(\\d+)\\s*(\\w+)\\s*(\\d+)\\s*.{0,6}\\s*(\\d+):(\\d+)\\s*</span>") #mini5DateRx = QRegExp("<span\\s*class=\"date\">[\\s\\n\\r]*(\\w+)\\s*(\\d+)\\s*(\\w+)\\s*(\\d+)\\s*.+\\s*(\\d+):(\\d+)\\s*</span>") mini5JackpotRx = QRegExp("<p class=\"montant-jackpot\">Jackpot\\s*garanti\\s*<span>\\s*(\\d+)") posi = mini5NumGrillerx.indexIn(str(htmlAscii)) ngrille = mini5NumGrillerx.cap(1) print "ngrille=%s" % ngrille posi = mini5DateRx.indexIn(str(htmlAscii), posi+1) jour = mini5DateRx.cap(1) numJour = mini5DateRx.cap(2) mois = mini5DateRx.cap(3) annee = mini5DateRx.cap(4) heure = mini5DateRx.cap(5) minute = mini5DateRx.cap(6) mois = filter(onlyascii, mois) print "jour=%s" % jour print "mois=%s" % mois print "annee=%s" % annee date = CombinoCalendar(int(numJour), mois, int(annee), int(heure), int(minute)) epochDate = date.epochDate()/1000 print "date=%s" % (jour + str(numJour) + mois + str(annee)) print "epochDate=%d" % epochDate #self.gridList.append(mini5rx.cap(1)) posi = mini5JackpotRx.indexIn(str(htmlAscii), posi+1) jackpot = mini5JackpotRx.cap(1) print "jackpot=%s" % jackpot tup = (ngrille, epochDate, jackpot) self._gridList.append(tup) posi = mini5NumGrillerx.indexIn(str(htmlAscii), posi+1) while posi != -1 : ngrille = mini5NumGrillerx.cap(1) print "ngrille=%s" % ngrille posi = mini5DateRx.indexIn(str(htmlAscii), posi+1) jour = mini5DateRx.cap(1) numJour = mini5DateRx.cap(2) mois = mini5DateRx.cap(3) annee = mini5DateRx.cap(4) mois = filter(onlyascii, mois) heure = mini5DateRx.cap(5) minute = mini5DateRx.cap(6) print "date=%s" % (jour + str(numJour) + mois + str(annee)) date = CombinoCalendar(int(numJour), mois, int(annee), int(heure), int(minute)) epochDate = date.epochDate()/1000 print "epochDate=%d" % epochDate posi = mini5JackpotRx.indexIn(str(htmlAscii), posi+1) jackpot = mini5JackpotRx.cap(1) print "jackpot=%s" % jackpot tup = (ngrille, epochDate, jackpot) self._gridList.append(tup) posi = mini5NumGrillerx.indexIn(str(htmlAscii), posi+1) print self._gridList
def handleOddsHtmlPage(self, htmlPage, source=BETEXPLORER_SOURCE): print "handleOddsHtmlPage source = %d" % source epochDate = self._gridList[self._index][1] date = QDateTime() date.setMSecsSinceEpoch(int(epochDate) * 1000) deprecated = QDateTime.currentDateTime() > date.addDays(+1) strHtml = str(htmlPage) if source == BETEXPLORER_SOURCE: oddsRx = QRegExp( "<a href=.*data-odd-max=\"(\\d*\.\\d*)\".*data-odd-max=\"(\\d*\.\\d*)\".*data-odd-max=\"(\\d*\.\\d*)\".*>") elif source == ZULUBET_SOURCE: oddsRx = QRegExp( "<td\\s*class=\"aver_odds_full\"\\s*align=\"center\">(\\d*\.\\d*)</td><td\\s*class=\"aver_odds_full\"\\s*align=\"center\">(\\d*\.\\d*)</td><td\\s*class=\"aver_odds_full\"\\s*align=\"center\">(\\d*\.\\d*)</td>") for match in self._grid.matches(): if not match.cotesDisponibles(): if source == BETEXPLORER_SOURCE and not deprecated: team1Rx = QRegExp( "><span>(\\w*[\\'\\.-]?\\s*)*(%s)(\\w*[\\'\\.-]?\\s*)*</span>\\s*-\\s*<span>\\s*((\\w*[\\'\\.-]?\\s*)*)</span><" % match.team1()) team1Rx.setCaseSensitivity(QtCore.Qt.CaseInsensitive) team2Rx = QRegExp( "><span>\\s*(\\w*[\\'\\.-]?\\s*)*</span>\\s*-\\s*<span>(\\w*[\\'\\.-]?\\s*)*(%s)(\\w*[\\'\\.-]?\\s*)*</span><" % match.team2()) team2Rx.setCaseSensitivity(QtCore.Qt.CaseInsensitive) elif source == ZULUBET_SOURCE: team1Rx = QRegExp( #"<img\\s*src=\"http://www\.zulubet\.com/flags/flag-\\w*\.png\"\\s*class=\"flags\\s*flag-\\w*\"\\s*title=\"(\\w*\\'?\\s*-?)*,(\\w*\\'?\\s*-?)*\"\\s*width=\"\\d*\"\\s*height=\"\\d*\">\\s*(%s)\\s*-\\s*(\\w*\\'?\\s*-?)*<\img>" % match.team1()) "width=\"\\d*\"\\s*height=\"\\d*\">\\s*(%s)\\s*-\\s*(\\w*[\\'\\.-]?\\s*)*</td>" % match.team1()) team1Rx.setCaseSensitivity(QtCore.Qt.CaseInsensitive) team2Rx = QRegExp( "width=\"\\d*\"\\s*height=\"\\d*\">(\\w*[\\'\\.-]?\\s*)*-\\s*(%s)\\s*</td>" % match.team2()) team2Rx.setCaseSensitivity(QtCore.Qt.CaseInsensitive) else: team1Rx = QRegExp("---deprecated---") team2Rx = QRegExp("---deprecated---") # team2Rx = QRegExp(match.team2()) teamXRx = team1Rx posi = teamXRx.indexIn(strHtml) posi2 = team2Rx.indexIn(strHtml) #if posi < 0: #print "-1-%s- not found" % match.team1() #teamXRx = team2Rx #posi = teamXRx.indexIn(strHtml) #if (posi >= 0) and (posi2 >= 0): if (posi >= 0) and (posi2 == posi): print "-%s- found" % ''.join((match.team1(), " vs " + match.team2())) else: # try in an other way print "-%s- not found, try another way" % ''.join((match.team1(), " vs " + match.team2())) # split team names team1list = match.team1().split(" ") team2list = match.team2().split(" ") # find the longest maxLen = 0 miniTeam1 = "" for elt1 in team1list: if len(elt1) > maxLen: maxLen = len(elt1) miniTeam1 = filter(onlyascii, elt1) maxLen = 0 miniTeam2 = "" for elt2 in team2list: if len(elt2) > maxLen: maxLen = len(elt2) miniTeam2 = filter(onlyascii, elt2) print "Try with {0} vs {1}".format(miniTeam1, miniTeam2) if source == BETEXPLORER_SOURCE and not deprecated: teamRx = QRegExp( "><span>\\s*(\\w*\\'?\\s*-?)*{0}(\\w*\\'?\\s*-?)*</span>\\s*-\\s*<span>(\\w*\\'?\\s*-?)*{1}(\\w*\\'?\\s*-?)*</span><".format( miniTeam1, miniTeam2)) elif source == ZULUBET_SOURCE: #teamRx = QRegExp( #"<img\\s*src=\"http://www\.zulubet\.com/flags/flag-\\w*\.png\"\\s*class=\"flags\\s*flag-\\w*\"\\s*title=\"(\\w*\\'?\\s*-?)*,(\\w*\\'?\\s*-?)*\"\\s*width=\"\\d*\"\\s*height=\"\\d*\">(\\w*\\'?\\s*-?)*{0}(\\w*\\'?\\s*-?)*-(\\w*\\'?\\s*-?)*{1}(\\w*\\'?\\s*-?)*<\img>".format( #miniTeam1, miniTeam2)) teamRx = QRegExp("\">(\\w*\\'?\\s*-?)*{0}(\\w*\\'?\\s*-?)*-(\\w*\\'?\\s*-?)*{1}(\\w*\\'?\\s*-?)*</td>".format(miniTeam1, miniTeam2)) else: teamRx = QRegExp("---deprecated---") print "---GRID DEPRECATED---" teamRx.setCaseSensitivity(QtCore.Qt.CaseInsensitive) posi = teamRx.indexIn(strHtml) if posi >= 0: print "found : {0} vs {1}".format(miniTeam1, miniTeam2) else: print "still not found :'(" # print "Odds handling KO %s not found" % str(match) if posi >= 0: print "posi = %d" % posi posi = oddsRx.indexIn(strHtml, posi) oddStr1 = oddsRx.cap(1) oddStr2 = oddsRx.cap(2) oddStr3 = oddsRx.cap(3) print "read odds1 = %s" % oddStr1 try: match.setCotes(float(oddsRx.cap(1)), float(oddsRx.cap(2)), float(oddsRx.cap(3))) team1 = filter(onlyascii, match.team1()) team2 = filter(onlyascii, match.team2()) print "Odds handling OK : %s" % team1 + " vs " + team2 print "Odds handling OK : " match.setCotesDisponibles(True) except: team1 = filter(onlyascii, match.team1()) team2 = filter(onlyascii, match.team2()) print "Odds handling OK : cant read odds for %s" % team1 + " vs " + team2 return