public async Task <int> Run() { using (var db = LiteDbFactory.New()) { var configCollection = db.GetCollection <Config>(); var config = configCollection.FindAll().SingleOrDefault() ?? new Config(); options.ApplyToConfig(config); if (!config.LeagueId.HasValue) { Console.Error.WriteLine("Error: League ID is not set"); return(1); } Console.WriteLine("Searching for players..."); var client = new YahooClient(config); var players = await client.SearchPlayers(config.LeagueId.Value, playerNameOrId); players.WriteTable(); } return(0); }
public async Task <int> Run() { using (var db = LiteDbFactory.New()) { var configCollection = db.GetCollection <Config>(); var config = configCollection.FindAll().SingleOrDefault() ?? new Config(); options.ApplyToConfig(config); if (string.IsNullOrWhiteSpace(config.ClientId)) { Console.Error.WriteLine("Error: Client ID is not set"); } if (string.IsNullOrWhiteSpace(config.ClientSecret)) { Console.Error.WriteLine("Error: Client secret is not set"); } if (string.IsNullOrWhiteSpace(config.RefreshToken)) { Console.Error.WriteLine("Error: Refresh token is not set"); } if (!config.LeagueId.HasValue) { Console.Error.WriteLine("Error: League ID is not set"); } if (!config.TeamId.HasValue) { Console.Error.WriteLine("Error: Team ID is not set"); } Console.WriteLine("Verifying connection to Yahoo!..."); var client = new YahooClient(config); await client.GetGameId(); Console.WriteLine("Successfully connected to Yahoo!"); var league = await client.GetLeague(config.LeagueId.GetValueOrDefault()); Console.WriteLine($"Successfully found league {league.Name} (#{config.LeagueId})"); var team = await client.GetTeam(config.LeagueId.GetValueOrDefault(), config.TeamId.GetValueOrDefault()); if (team.IsOwnedByCurrentLogin) { Console.WriteLine($"Successfully found team {team.Name} (#{config.TeamId})"); } else { Console.Error.WriteLine($"Error: Team {team.Name} (#{config.TeamId}) is not owned by current user"); } } return(0); }
public async Task <int> Run() { using (var db = LiteDbFactory.New()) { var configCollection = db.GetCollection <Config>(); var config = configCollection.FindAll().SingleOrDefault() ?? new Config(); options.ApplyToConfig(config); if (!config.LeagueId.HasValue) { Console.Error.WriteLine("Error: League ID is not set"); return(1); } if (!config.TeamId.HasValue) { Console.Error.WriteLine("Error: Team ID is not set"); return(1); } var client = new YahooClient(config); var addPlayers = await client.SearchPlayers(config.LeagueId.Value, addNameOrId); var dropPlayers = await client.SearchPlayers(config.LeagueId.Value, dropNameOrId); if (VerifySinglePlayer(addPlayers, "add") && VerifySinglePlayer(dropPlayers, "drop")) { var claimsCollection = db.GetCollection <Claim>(); var existingClaims = claimsCollection.FindAll(); var claim = new Claim { Add = new Player(addPlayers.Single()), Drop = new Player(dropPlayers.Single()), Priority = existingClaims .OrderByDescending(ec => ec.Priority) .Select(ec => ec.Priority) .FirstOrDefault() + 1 }; claimsCollection.Insert(claim); Console.WriteLine("Claim successfully added"); claimsCollection.FindAll().ToArray().WriteTable(); return(0); } else { return(1); } } }
internal YahooContact(YahooBuddy contact, YahooClient client) { this.contact = contact; this.client = client; }
public async Task <IActionResult> Post([FromBody] YahooRequest request) { if (request.Type == "process") { foreach (string code in request.Codes) { var raw = _context.YahooFinanceRawSet.FirstOrDefault(y => y.Code == code && y.Status == FinanceProcessEnum.Loaded); JObject obj = JObject.Parse(raw.Data); System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); IList <CommonLib.Objects.FinanceAnnual> _reports = obj["timeSeries"]["timestamp"] .Select(s => new CommonLib.Objects.FinanceAnnual() { Id = Guid.NewGuid(), Code = code, CreateDate = DateTime.Now, Data = "", Year = dateTime.AddSeconds((int)s).Year }) .OrderByDescending(r => r.Year) .ToList(); for (int i = 0; i < _reports.Count; i++) { JObject report = new JObject(); report["financialsTemplate"] = obj["financialsTemplate"]; report["incomeStatement"] = obj["incomeStatementHistory"]["incomeStatementHistory"][i]; report["balanceSheet"] = obj["balanceSheetHistory"]["balanceSheetStatements"][i]; report["cashflowStatement"] = obj["cashflowStatementHistory"]["cashflowStatements"][i]; _reports[i].Data = report.ToString(); } foreach (var rep in _reports) { if (_context.FinanceAnnualSet.Count(f => f.Code == rep.Code && f.Year == rep.Year) == 0) { _context.FinanceAnnualSet.Add(rep); } } raw.Status = FinanceProcessEnum.Processed; _context.SaveChanges(); } } if (request.Type == "financial") { var apiClient = new CommonLib.WebApiClient(); YahooClient yahooClient = new YahooClient(apiClient); apiClient.addHeader("x-rapidapi-host", "apidojo-yahoo-finance-v1.p.rapidapi.com"); apiClient.addHeader("x-rapidapi-key", "d8c3e2c892msh13cac0704b75eb0p115a47jsn5be47ce5097d"); foreach (string code in request.Codes) { string resp = await yahooClient.GetFinancial(code); JObject obj = JObject.Parse(resp); int max_timestamp = obj["timeSeries"]["timestamp"].Select(s => (int)s).Max(); System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); var raw = _context.YahooFinanceRawSet.FirstOrDefault(y => y.Code == code && y.Status == FinanceProcessEnum.Init); raw.Data = resp; raw.LoadDate = DateTime.Now; raw.Status = FinanceProcessEnum.Loaded; raw.LastFinance = dateTime.AddSeconds(max_timestamp); _context.SaveChanges(); } } if (request.Type == "init") { foreach (string code in request.Codes) { _context.YahooFinanceRawSet.Add(new CommonLib.Objects.YahooFinanceRaw() { Id = Guid.NewGuid(), Status = FinanceProcessEnum.Init, Code = code, }); } _context.SaveChanges(); } return(Ok()); }
/// <summary> /// Initializes a new instance of the login form with a specified OAuth client. /// </summary> /// <param name="client">Instance of the OAuth client.</param> /// <param name="autoLogout">Disables saving and restoring authorization cookies in WebBrowser. Default: false.</param> /// <param name="loadUserInfo">Indicates the need to make a request for recive the user profile or not. Default: false.</param> /// <param name="responseType">Allows to set the type of response that is expected from the server. Default: <see cref="ResponseType.Token"/>.</param> public YahooLogin(YahooClient client, bool autoLogout = false, bool loadUserInfo = false, string responseType = "token") : base(client, autoLogout, loadUserInfo, responseType) { this.Width = 815; this.Height = 642; this.Icon = Properties.Resources.yahoo; }
public async Task <int> Run() { using (var db = LiteDbFactory.New()) { var configCollection = db.GetCollection <Config>(); var config = configCollection.FindAll().SingleOrDefault() ?? new Config(); options.ApplyToConfig(config); if (!config.LeagueId.HasValue) { Console.Error.WriteLine("Error: League ID is not set"); return(1); } if (!config.TeamId.HasValue) { Console.Error.WriteLine("Error: Team ID is not set"); return(1); } var client = new YahooClient(config); var claimCollection = db.GetCollection <Claim>(); var claims = claimCollection.FindAll().OrderBy(c => c.Priority).ToList(); string claimsText(int claimCount) => claimCount.ToString("G") + (claimCount == 1 ? " claim" : " claims"); WriteMessage($"Attempting to process {claimsText(claims.Count)}..."); while (claims.Any()) { foreach (var claim in claims) { // Check if the added player is a free agent var potentialAddedPlayers = await client.SearchPlayersByName( config.LeagueId.Value, claim.Add.FullName, PlayerStatus.FreeAgent); var addedPlayer = potentialAddedPlayers .SingleOrDefault(p => p.PlayerId == claim.Add.PlayerId); if (addedPlayer != null) { WriteMessage($"{claim.Add.Description} is a free-agent. Submitting claim..."); try { await client.SubmitClaim( config.LeagueId.Value, config.TeamId.Value, claim.Add.PlayerId, claim.Drop.PlayerId); WriteMessage($"{claim.Add.Description} successfully added! {claim.Drop.Description} dropped"); } catch (ClientException ce) { WriteMessage($"Error: {claim.Add.Description} could not be added, dropping {claim.Drop.Description}", Console.Error); WriteMessage($"Error: {ce.Message}", Console.Error); } // Whether the claim succeeded or failed, delete it claimCollection.Delete(claim.Id); } else { WriteMessage($"{claim.Add.Description} is not (yet) a free-agent", verbose: true); } } // Reload the claims collection, to pick up new claims and eliminate deleted ones claims = claimCollection.FindAll().OrderBy(c => c.Priority).ToList(); // If outstanding claims remain, try again after a delay if (claims.Any()) { WriteMessage($"{claimsText(claims.Count)} still pending. Sleeping for {wait:G} seconds...", verbose: true); await Task.Delay(wait * 1000); WriteMessage($"Attempting to process {claimsText(claims.Count)}...", verbose: true); } } WriteMessage("All pending claims were processed (or failed). Exiting..."); } return(0); }