コード例 #1
0
ファイル: ImagesProvider.cs プロジェクト: nachog4/nLauncher
        public static List <Google.Apis.Customsearch.v1.Data.Result> googleSearch(string query)
        {
            const string apiKey         = "AIzaSyALPsRIcFB8dc9SbsaaA-f1gRNG3gZtxV4";
            const string searchEngineId = "015210785414118161171:eaqkejpiflg";

            var customSearchService = new Google.Apis.Customsearch.v1.CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer {
                ApiKey = apiKey
            });
            var listRequest = customSearchService.Cse.List();

            listRequest.Cx         = searchEngineId;
            listRequest.ImgSize    = Google.Apis.Customsearch.v1.CseResource.ListRequest.ImgSizeEnum.XXLARGE;
            listRequest.SearchType = Google.Apis.Customsearch.v1.CseResource.ListRequest.SearchTypeEnum.Image;
            listRequest.Safe       = Google.Apis.Customsearch.v1.CseResource.ListRequest.SafeEnum.Off;
            listRequest.Q          = query;

            List <Google.Apis.Customsearch.v1.Data.Result> paging = new List <Google.Apis.Customsearch.v1.Data.Result>();

            try
            {
                paging = listRequest.Execute().Items.ToList();
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(paging);
        }
コード例 #2
0
        public ActionResult Search(string query)
        {
            string apiKey = "AIzaSyBv-EM_Dq27eAAXSQLERCIBzJb_3I-CwE4";
            string cx     = "014866169754120585633:hgy0gg0o7g8";
            //query = "Augmrny";
            var svc = new Google.Apis.Customsearch.v1.CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer {
                ApiKey = apiKey
            });
            var listRequest = svc.Cse.List(query);

            listRequest.Cx = cx;
            var search  = listRequest.Execute();
            var results = search.Items;

            ViewBag.results = results;
            return(View());
        }
コード例 #3
0
        public GoogleResult GoogleSearch([FromBody] string searchText)
        {
            var apiKey = "AIzaSyAYEw4E8k2V4n2xhEAtl3gPJatZfQ0mbhM";
            var cx     = "004052071860325123994:6giwpag8kue";
            var query  = searchText;
            var svc    = new Google.Apis.Customsearch.v1.CustomsearchService(new BaseClientService.Initializer {
                ApiKey = apiKey
            });
            var listRequest = svc.Cse.List(query);

            listRequest.Cx = cx;
            var search = listRequest.Execute();

            var googleResult = new GoogleResult();

            googleResult.Counter = search.Items.Count;
            googleResult.Query   = query;
            return(googleResult);
        }
コード例 #4
0
        public Google.Apis.Customsearch.v1.Data.Search Search(string keywords)
        {
            List <string> _results = new List <string>();

            var svc = new Google.Apis.Customsearch.v1.CustomsearchService(new BaseClientService.Initializer
            {
                ApiKey = GetGoogleApiKey()
            });

            var listRequest = svc.Cse.List(keywords);

            listRequest.Cx = GetGoogleSearchEngine();
            //listRequest.ExactTerms = "stackoverflow";
            listRequest.Gl = "en"; //Default search by Vietnamese
            listRequest.Hl = "vi";

            var search = listRequest.Execute();

            return(search);
        }
コード例 #5
0
        public async Task <IEnumerable <SearchResult> > Search(string term)
        {
            var customsearchService = new Google.Apis.Customsearch.v1.CustomsearchService(new BaseClientService.Initializer
            {
                ApiKey = _googleConfiguration.Key
            });

            var listRequest = customsearchService.Cse.List(term);

            listRequest.Cx = _googleConfiguration.Cx;

            var search = await listRequest.ExecuteAsync();

            return(search.Items.Select(i => new SearchResult
            {
                Link = i.Link,
                Snippet = i.HtmlSnippet,
                Title = i.Title
            }));
        }
コード例 #6
0
        public async Task Find(CommandContext context, [Description("The term you want to search for.")] string term)
        {
            // let's trigger a typing indicator to let users know we're working
            await context.TriggerTypingAsync();

            // Use the default configuration for AngleSharp
            var config = Configuration.Default;

            // Create a new context for evaluating webpages with the given config
            var browseContext = BrowsingContext.New(config);

            string apiKey             = Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
            string customSearchEngine = Environment.GetEnvironmentVariable("SEARCH_ENGINE_KEY");
            var    svc = new Google.Apis.Customsearch.v1.CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer {
                ApiKey = apiKey
            });
            var listRequest = svc.Cse.List(term);

            listRequest.Cx = customSearchEngine;
            var searchItem = listRequest.Execute().Items; // get the first search result

            // wrap it into an embed
            var embed = new DiscordEmbedBuilder();

            embed.WithFooter($"Search results for {term}...");

            if (searchItem != null) // found a search result!
            {
                embed.WithTitle(searchItem[0].Title.Replace(" - World of Warcraft", ""));
                embed.WithDescription(searchItem[0].Snippet);
                embed.WithUrl(searchItem[0].Link);
            }
            else // not an item
            {
                DiscordEmoji searchEmoji = DiscordEmoji.FromName(context.Client, ":grimacing:");
                embed.WithTitle($"{searchEmoji} Couldn't find a page for this term, is it possible you misspelled it or it isn't from Classic WoW?");
            }

            // respond with content
            await context.RespondAsync(embed : embed);
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: khm2034/image-finder
        private void searchButton_Click(object sender, EventArgs e)
        {
            imageArr.Clear();
            imageArrIndex = 0;
            imageArrSize  = 0;
            if (!searchText.Equals(""))
            {
                var svc = new Google.Apis.Customsearch.v1.CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer {
                    ApiKey = key
                });
                Console.WriteLine(searchText);
                //var listRequest = svc.Cse.List(searchText);
                Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = svc.Cse.List(searchText);
                listRequest.Cx         = searchID;
                listRequest.SearchType = Google.Apis.Customsearch.v1.CseResource.ListRequest.SearchTypeEnum.Image;

                for (int i = 0; i < 5; i++)
                {
                    listRequest.Start = 1 + 10 * i;
                    Google.Apis.Customsearch.v1.Data.Search search = listRequest.Execute();
                    foreach (var result in search.Items)
                    {
                        imageArrIndex++;
                        imageArr.Add((Image)BitmapFromURL(result.Image.ThumbnailLink));

                        //if (!result.Pagemap.Equals(null) && result.Pagemap.ContainsKey("cse_thumbnail"))
                        //{
                        //    //Console.WriteLine(result.Pagemap["cse_thumbnail"][0]["src"]);
                        //    imageArrIndex++;
                        //    imageArr.Add((Image)BitmapFromURL(result.Pagemap["cse_thumbnail"][0]["src"].ToString()));
                        //}
                        //imageArr[imageArrIndex++] = result.Image.;
                        //pictureBox1.Image = result.Image.ThumbnailLink;
                    }
                }
                imageArrSize  = imageArrIndex;
                imageArrIndex = 0;

                pictureBox1.Image = imageArr[imageArrIndex];
            }
        }
コード例 #8
0
        public Google.Apis.Customsearch.v1.Data.Search SearchImage(string keywords)
        {
            List <string> _results = new List <string>();
            var           svc      = new Google.Apis.Customsearch.v1.CustomsearchService(new BaseClientService.Initializer
            {
                ApiKey = GetGoogleApiKey()
            });
            var listRequest = svc.Cse.List(keywords);

            listRequest.Cx = GetGoogleSearchEngine();

            string startDate = DateTime.UtcNow.AddDays(-3).ToString("yyyyMMdd");
            //string startDate = (DateTime.UtcNow.Year.ToString() + sMonth + sday);
            string endDate = DateTime.UtcNow.ToString("yyyyMMdd");

            listRequest.DateRestrict = startDate + ":" + endDate;
            listRequest.Start        = 1;
            var search = listRequest.Execute();//.Fetch();

            return(search);
        }
コード例 #9
0
        public Google.Apis.Customsearch.v1.Data.Search SearchImage(string keywords)
        {
            List <string> _results = new List <string>();
            var           svc      = new Google.Apis.Customsearch.v1.CustomsearchService(new BaseClientService.Initializer
            {
                ApiKey = GetGoogleApiKey()
            });
            //var listRequest = svc.Cse.List(keywords.Split(new string[] { "," },StringSplitOptions.None)[0]);
            var listRequest = svc.Cse.List(keywords);

            listRequest.Cx         = GetGoogleSearchEngine();
            listRequest.SearchType = Google.Apis.Customsearch.v1.CseResource.ListRequest.SearchTypeEnum.Image;
            listRequest.Gl         = "en"; //Default search by Vietnamese
            listRequest.Hl         = "vi";

            //string startDate = DateTime.UtcNow.AddDays(-3).ToString("yyyyMMdd");
            //string endDate = DateTime.UtcNow.ToString("yyyyMMdd");
            //listRequest.DateRestrict = startDate + ":" + endDate;
            //listRequest.Start = 1;
            var search = listRequest.Execute();//.Fetch();

            return(search);
        }
コード例 #10
0
ファイル: CallGoogle.cs プロジェクト: brunoslam/BotPepe
        public async Task <IList <Result> > GoogleIt(string consulta)
        {
            string apiKey = "AIzaSyAnIxLWO9OgoZaZZb9RnHMsJaqMv9LtWn4";
            string cx     = "011102882269195785315:fqiiyc32lh0";
            string query  = consulta;

            var svc = new Google.Apis.Customsearch.v1.CustomsearchService(new BaseClientService.Initializer {
                ApiKey = apiKey
            });
            var listRequest = svc.Cse.List(query);

            listRequest.Num         = 1;
            listRequest.PrettyPrint = true;

            listRequest.Cx = cx;
            var search = await listRequest.ExecuteAsync();

            foreach (var result in search.Items)
            {
                var asd = result.Title;
            }

            return(search.Items);
        }
コード例 #11
0
        [Description("Type the name of an existing item and it will show up with a link in chat.")] // this will be displayed to tell users what this command does when they invoke help
        public async Task Linkerator(CommandContext context, [Description("The item you want to link.")] string item)
        {
            // let's trigger a typing indicator to let users know we're working
            await context.TriggerTypingAsync();

            // Use the default configuration for AngleSharp
            var config = Configuration.Default;

            // Create a new context for evaluating webpages with the given config
            var browseContext = BrowsingContext.New(config);

            string apiKey             = Environment.GetEnvironmentVariable("GOOGLE_API_KEY");
            string customSearchEngine = Environment.GetEnvironmentVariable("SEARCH_ENGINE_KEY");
            var    svc = new Google.Apis.Customsearch.v1.CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer {
                ApiKey = apiKey
            });
            var listRequest = svc.Cse.List(item);

            listRequest.Cx  = customSearchEngine;
            listRequest.Num = 5; // get first 5 search results
            var searchItems = listRequest.Execute();

            // wrap it into an embed
            var embed = new DiscordEmbedBuilder();

            embed.WithFooter($"Search results for {item}...");

            bool itemFound  = false;
            var  searchItem = new Google.Apis.Customsearch.v1.Data.Result();

            if (searchItems.Items != null)
            {
                foreach (var currentItem in searchItems.Items)
                {
                    if (currentItem.Title.Contains("Item") && !itemFound)
                    {
                        itemFound  = true;
                        searchItem = currentItem;
                    }
                }
            }

            if (itemFound) // got a result, and it's an item!
            {
                embed.WithTitle(searchItem.Title.Replace(" - Item - World of Warcraft", ""));
                embed.WithDescription(searchItem.Snippet);
                embed.WithUrl(searchItem.Link);

                // Source to be parsed
                string response = await client.GetStringAsync(searchItem.Link);

                var document = await browseContext.OpenAsync(req => req.Content(response));

                // all <link> tags
                var links = document.QuerySelectorAll("link");
                foreach (var link in links)
                {
                    // looking for <link rel="image_src" href="item icon image">
                    if (link.HasAttribute("rel") && link.GetAttribute("rel").Contains("image_src") &&
                        link.HasAttribute("href"))
                    {
                        embed.WithThumbnailUrl(link.GetAttribute("href"));
                    }
                }
            }
            else // not an item
            {
                DiscordEmoji searchEmoji = DiscordEmoji.FromName(context.Client, ":grimacing:");
                embed.WithTitle($"{searchEmoji} Couldn't find a page for this item, is it possible you misspelled it or it isn't an item from Classic WoW?");
            }

            // respond with content
            await context.RespondAsync(embed : embed);
        }