public async Task GoogleAsyc([Remainder] string searchQuery) { //checks if the search fails the censor if (censor.CensorText(searchQuery)) { //if so it sends an embed explaining the why the request failed EmbedBuilder builder = new EmbedBuilder() { Author = new EmbedAuthorBuilder().WithName("Error"), Title = "Your request could not be completed", Description = Context.Message.Author.Mention + " Your request most likely contained profanity and therefore was not completed. Please refined your request so that it does not contain profanity. Your original request has been removed.", ThumbnailUrl = "https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678069-sign-error-512.png", Color = Color.DarkRed }; await ReplyAsync(embed : builder.Build()); //deletes orignal request await Context.Message.DeleteAsync(); } //if it passes the censor complete the search else { GoogleResults searchResults = await searchService.SearchAsync(searchQuery); //the following code is responsible for bulding the embed and sending it EmbedAuthorBuilder EAB = new EmbedAuthorBuilder() { Name = "Main Result:" }; EmbedBuilder embedBuilder = new EmbedBuilder() { Author = EAB, Title = searchResults.Items[0].Title, Url = searchResults.Items[0].Link, ThumbnailUrl = searchResults.Items[0].PageMap.CseThumbnail[0].Src, Color = new Color?(new Color(66, 133, 244)), Footer = new EmbedFooterBuilder().WithText("Search Requested").WithIconUrl("https://cdn4.iconfinder.com/data/icons/new-google-logo-2015/400/new-google-favicon-512.png") } .AddField("Result 2", "[" + searchResults.Items[1].Title + "](" + searchResults.Items[1].Link + ")", false) .AddField("Result 3", "[" + searchResults.Items[2].Title + "](" + searchResults.Items[2].Link + ")", false) .WithCurrentTimestamp(); await ReplyAsync(embed: embedBuilder.Build()); } }
// Generate Result Lists internal static async Task Generate(IWebDriver web, ProgressBar progressBar, string[] terms, int min, int max, SearchEngines searchEngine, bool clear) { if (clear) { File.Delete(BingFile); File.Delete(GoogleFile); BingResults.Clear(); GoogleResults.Clear(); } int termsCount = terms.Length; int count = 0; // ReSharper disable once PossibleMultipleEnumeration //foreach (var term in terms) for (int i = min; i < max; i++) { var term = terms[i]; //if (term != string.Empty) // UpdateProgress(); switch (searchEngine) { case SearchEngines.All: BingResults.Add(new Result(term, await GetBingResults(web, term))); GoogleResults.AddRange(await GetGoogleResults(web, term)); break; case SearchEngines.Bing: BingResults.Add(new Result(term, await GetBingResults(web, term))); break; case SearchEngines.Google: GoogleResults.AddRange(await GetGoogleResults(web, term)); break; } progressBar.Tick($"Step {count} of {termsCount}: {term}"); Persist(); ++count; } }
public bool TryLookup(double latitude, double longitude, out LocationInfo locationInfo) { var downloader = new Downloader { EnableCompression = true }; downloader.Headers["Accept"] = "application/json"; // Google enables compressed output only, if a valid User-Agent is sent! downloader.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"; GoogleResults results = downloader.Download <GoogleResults>(BuildUrl(latitude, longitude)); if (results == null || results.Results == null || results.Results.Count == 0) { locationInfo = null; return(false); } locationInfo = results.Results[0].ToLocation(); locationInfo.Latitude = latitude; locationInfo.Longitude = longitude; return(true); }
public MutualFundCalculator(String fundName, List <MutualFundView> transactions, Boolean isOpenFund, DateTime last12Start, InvestmentEntities entities) { FundName = fundName; if (ValueToday == null && isOpenFund) { var mutualFund = entities.MutualFunds.Single(mf => mf.MutualFundSymbol == fundName); if (mutualFund.IsGoogleTracked) { //http://ichart.yahoo.com/table.csv?s=FSDIX&a=2&b=1&c=2013&d=2&e=1&f=2014&g=d&ignore=.csv a=Month-1, b=day, c=year (d, e, f = m,d,y end date) String url = "http://finance.google.com/finance/info?client=ig&q=" + fundName; WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); String responseString = ""; using (Stream stream = response.GetResponseStream()) { using (StreamReader answer = new StreamReader(stream)) { responseString = answer.ReadToEnd(); } } ValueToday = JSONHelper.Deserialise <GoogleResults>(responseString); } else { GoogleResults r = new GoogleResults(); r.l = mutualFund.LastKnownValue.ToString(); ValueToday = r; } } Decimal todaysValue = !isOpenFund?transactions.OrderByDescending(t => t.TransactionDate).First().PricePerShare : Decimal.Parse(ValueToday.l); CurrentValue = todaysValue * transactions.Sum(i => i.NumberOfShares); Investments = transactions.Where(i => i.ReturnType == "Investment").Sum(i => i.Amount); Gains = transactions.Where(i => i.ReturnType != "Investment").Sum(i => i.Amount); FirstPurchase = transactions.OrderBy(i => i.TransactionDate).First().TransactionDate; Dictionary <DateTime, Double> allTransactions = new Dictionary <DateTime, double>(); foreach (MutualFundView fund in transactions) { if (fund.ReturnType == "Investment") { allTransactions.Add(fund.TransactionDate, Convert.ToDouble(fund.Amount)); if (fund.TransactionDate > last12Start) { TransactionsLast12.Add(fund.TransactionDate, Convert.ToDouble(fund.Amount)); } } } try { ROI = Convert.ToDecimal(Calculations.IRR.solveIRR(allTransactions, Convert.ToDouble(CurrentValue), 1, 1000, DateTime.Now)); if (allTransactions.Count == TransactionsLast12.Count) { ROILast12 = ROI; Last12Valid = true; } else { MutualFundPriceHistory historicalPrice = entities.MutualFundPriceHistories.SingleOrDefault(h => h.MutualFundSymbol == fundName && h.QuoteDate == last12Start); if (historicalPrice != null) { Decimal numberOfSharesYearAgo = transactions.Sum(i => i.NumberOfShares) - transactions.Where(i => i.TransactionDate > last12Start).Sum(i => i.NumberOfShares); TransactionsLast12.Add(last12Start, Convert.ToDouble(numberOfSharesYearAgo * historicalPrice.DayPrice)); ROILast12 = Convert.ToDecimal(Calculations.IRR.solveIRR(TransactionsLast12, Convert.ToDouble(CurrentValue), 1, 1000, DateTime.Now)); Last12Valid = true; } else { ROILast12 = 0; Last12Valid = false; } } } catch { //ROI = -1; //ROILast12 = -1; } }
public void BeforeEachTest() { googleHome = new GoogleHome(); googleResults = new GoogleResults(); seleniumPage = new SeleniumPage(); }