mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Add Google suggestions for web searches
Fix issues with push results
This commit is contained in:
42
Wox.Plugin.System/SuggestionSources/Google.cs
Normal file
42
Wox.Plugin.System/SuggestionSources/Google.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Wox.Infrastructure;
|
||||
using YAMP.Numerics;
|
||||
|
||||
namespace Wox.Plugin.System.SuggestionSources
|
||||
{
|
||||
public class Google : AbstractSuggestionSource
|
||||
{
|
||||
public override List<string> GetSuggestions(string query)
|
||||
{
|
||||
var response =
|
||||
HttpRequest.CreateGetHttpResponse("https://www.google.com/complete/search?output=chrome&q=" + Uri.EscapeUriString(query), null,
|
||||
null, null);
|
||||
var stream = response.GetResponseStream();
|
||||
|
||||
if (stream != null)
|
||||
{
|
||||
var body = new StreamReader(stream).ReadToEnd();
|
||||
var json = JsonConvert.DeserializeObject(body) as JContainer;
|
||||
if (json != null)
|
||||
{
|
||||
var results = json[1] as JContainer;
|
||||
if (results != null)
|
||||
{
|
||||
var j = results.OfType<JValue>().Select(o => o.Value);
|
||||
return results.OfType<JValue>().Select(o => o.Value).OfType<string>().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Wox.Plugin.System/SuggestionSources/ISuggestionSource.cs
Normal file
18
Wox.Plugin.System/SuggestionSources/ISuggestionSource.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Plugin.System.SuggestionSources
|
||||
{
|
||||
public interface ISuggestionSource
|
||||
{
|
||||
List<string> GetSuggestions(string query);
|
||||
}
|
||||
|
||||
public abstract class AbstractSuggestionSource : ISuggestionSource
|
||||
{
|
||||
public abstract List<string> GetSuggestions(string query);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user