public static List<OddsInfoModel> Scrap(int spieltag)
        {
            string domainUrl = WettfreundeConfigInfo.Current.BaseURL;
            string betOddsUrl = domainUrl + WettfreundeConfigInfo.Current.OddsLink;

            CookieContainer cookies = new CookieContainer();

            var oddResponseStr = PostRequest("", betOddsUrl, "", cookies);

            var oddScraper = new WettfreundeOddsBuLiScraper();

            return oddScraper.GetOdds(oddResponseStr, spieltag.ToString());

        }
示例#2
0
        public ActionResult Index(int?Spieltag)
        {
            var spieltagInfo = OpenDBHelper.GetSpieltagInfo(_matchDataRepository);

            int currentSpieltag = (Spieltag.HasValue == true) ?
                                  Spieltag.Value :
                                  spieltagInfo.TippSpieltag;

            // build dropdown list data
            {
                var count             = SportsdataConfigInfo.Current.EndSpieltag - SportsdataConfigInfo.Current.StartSpieltag + 1;
                var ddlSpieltageRange = (from e in Enumerable.Range(SportsdataConfigInfo.Current.StartSpieltag, count)
                                         select new SelectListItem()
                {
                    Value = e.ToString(), Text = "Spieltag " + e.ToString(), Selected = (e == currentSpieltag)
                });

                ViewBag.Spieltag = ddlSpieltageRange;
            }

            var model = new SpieltagModel();

            model.Spieltag = currentSpieltag;

            if ((currentSpieltag == 34 || currentSpieltag == 0) && spieltagInfo.IsCompleted)
            {
                model.IsTippSpielFinished = true;
                return(View(model));
            }

            List <OddsInfoModel> oddsList = null;

            try
            {
                oddsList = WettfreundeScraper.Scrap(currentSpieltag);
            }
            catch (Exception ex)
            {
                _log.Error("Error while scrab odds: " + ex.Message);
                string fixFilename = String.Format("Odds_{0}_{1}_{2}", SportsdataConfigInfo.Current.LeagueShortcut, SportsdataConfigInfo.Current.LeagueSaison, currentSpieltag);
                _log.Info("Try fix: " + fixFilename);

                ResourceManager rm         = new ResourceManager(typeof(Resources));
                var             fixContent = rm.GetObject(fixFilename) as string;

                var oddScraper = new WettfreundeOddsBuLiScraper();

                oddsList = oddScraper.GetOdds(fixContent, currentSpieltag.ToString());
            }

            var matches = _matchDataRepository.GetMatchesByGroup(currentSpieltag);

            foreach (var m in matches)
            {
                var modelAllInfo = new MatchInfoModel()
                {
                    MatchId       = m.MatchId,
                    AwayTeam      = m.AwayTeam,
                    AwayTeamIcon  = m.AwayTeamIcon,
                    AwayTeamScore = m.AwayTeamScore,
                    HomeTeam      = m.HomeTeam,
                    HomeTeamIcon  = m.HomeTeamIcon,
                    HomeTeamScore = m.HomeTeamScore,
                    IsFinished    = m.IsFinished,
                    KickoffTime   = m.KickoffTime
                };

                model.IsSpieltagFinished = (model.IsSpieltagFinished && modelAllInfo.IsFinished);

                // mixin odds quotes into match data
                {
                    MixinOddsQuotes(oddsList, modelAllInfo);
                }

                using (var ctxt = new TippSpielContext())
                {
                    var myTippObject = (from t in ctxt.TippMatchList
                                        where t.MatchId == modelAllInfo.MatchId &&
                                        t.User == User.Identity.Name
                                        select t)
                                       .FirstOrDefault();

                    if (myTippObject != null)
                    {
                        modelAllInfo.MyOdds   = myTippObject.MyOdds;
                        modelAllInfo.MyTip    = myTippObject.MyTip;
                        modelAllInfo.MyAmount = myTippObject.MyAmount;
                    }
                }


                model.Matchdata.Add(modelAllInfo);
            }

            {
                _log.DebugFormat("Tipp data stats: remote hits={0}, cache hits={1}", MatchDBStats.GetRemoteHits(), MatchDBStats.GetCacheHits());
            }

            return(View(model));
        }