Skip to content

Commit

Permalink
Auto convert based on computer's location, instead of Windows Region
Browse files Browse the repository at this point in the history
  • Loading branch information
SakaDream committed May 7, 2017
1 parent 7e4f725 commit 66230cc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
4 changes: 0 additions & 4 deletions Currency/Currency.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="plugin.json" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\icon.png" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
36 changes: 19 additions & 17 deletions Currency/CurrencyPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public List<Result> Query(Query query)
return new List<Result>();
}
}
catch(Exception)
catch(Exception e)
{
//return Debug(query.RawQuery + ". Inside catch: " + e.Message);
return new List<Result>();
Expand All @@ -111,21 +111,6 @@ private decimal GetRate(string fromCurrency, string toCurrency)
}
}

//private string APIDebug(string fromCurrency, string toCurrency)
//{
// string query = fromCurrency + "_" + toCurrency;
// var url = $"http://free.currencyconverterapi.com/api/v3/convert?q={query}&compact=ultra";
// var request = (HttpWebRequest)WebRequest.Create(url);
// request.Method = "GET";
// var respone = (HttpWebResponse)request.GetResponse();
// using (new StreamReader(respone.GetResponseStream()))
// {
// var responeString = new StreamReader(respone.GetResponseStream()).ReadToEnd();
// var json = JObject.Parse(responeString);
// return url + ", " + json[query];
// }
//}

public List<Result> GetResult(SearchParams sp)
{
var results = new List<Result>();
Expand All @@ -147,10 +132,26 @@ public List<Result> GetResult(SearchParams sp)
IcoPath = "Images/icon.png"
});
}
// Debug: Add {APIDebug(sp.FromCurrency, sp.ToCurrency)} to Result.Title
//Debug: Add {APIDebug(sp.FromCurrency, sp.ToCurrency)} to Result.Title
return results;
}

#region Debug
//private string APIDebug(string fromCurrency, string toCurrency)
//{
// string query = fromCurrency + "_" + toCurrency;
// var url = $"http://free.currencyconverterapi.com/api/v3/convert?q={query}&compact=ultra";
// var request = (HttpWebRequest)WebRequest.Create(url);
// request.Method = "GET";
// var respone = (HttpWebResponse)request.GetResponse();
// using (new StreamReader(respone.GetResponseStream()))
// {
// var responeString = new StreamReader(respone.GetResponseStream()).ReadToEnd();
// var json = JObject.Parse(responeString);
// return url + ", " + json[query];
// }
//}

//public List<Result> Debug(SearchParams sp)
//{
// var results = new List<Result>();
Expand Down Expand Up @@ -203,5 +204,6 @@ public List<Result> GetResult(SearchParams sp)

// return results;
//}
#endregion
}
}
37 changes: 30 additions & 7 deletions Currency/Models/SearchParams.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;

namespace Currency.Models
{
Expand All @@ -18,7 +16,7 @@ public SearchParams(decimal Amount, string FromCurrency)
{
this.Amount = Amount;
this.FromCurrency = FromCurrency;
this.ToCurrency = RegionInfo.CurrentRegion.ISOCurrencySymbol;
this.ToCurrency = GetCurrencyCode();
}
public SearchParams(decimal Amount, string FromCurrency, string ToCurrency)
{
Expand All @@ -36,7 +34,32 @@ public SearchParams(string FromCurrency)
{
this.Amount = 1;
this.FromCurrency = FromCurrency;
this.ToCurrency = RegionInfo.CurrentRegion.ISOCurrencySymbol;
this.ToCurrency = GetCurrencyCode();
}

private string GetCurrencyCode()
{
var CountryCode = "";

var url = $"http://ip-api.com/json";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
var respone = (HttpWebResponse)request.GetResponse();
using (new StreamReader(respone.GetResponseStream()))
{
var responeString = new StreamReader(respone.GetResponseStream()).ReadToEnd();
var json = JObject.Parse(responeString);
CountryCode = json["countryCode"].ToString();
}
try
{
RegionInfo ri = new RegionInfo(CountryCode);
return ri.ISOCurrencySymbol;
}
catch
{
return RegionInfo.CurrentRegion.ISOCurrencySymbol;
}
}
}
}
File renamed without changes
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
An easy-to-use Currency Converter for Wox. Currency API by [http://www.currencyconverterapi.com/](http://www.currencyconverterapi.com/)

# Features
Auto convert based on Windows localization
**New in v1.0.1!** Auto convert based on computer's location (Public IP)

![](https://puu.sh/vHeML.png)
![](https://puu.sh/vIhpB.png)

Get Foreign exchange rate

![](https://puu.sh/vHeLZ.png)
![](https://puu.sh/vIhqe.png)

Convert using native speak or Google Search style

![](https://puu.sh/vHeMt.png)

![Convert using Google Search style](https://puu.sh/vHeME.png)
![](https://puu.sh/vHeME.png)

# About Wox
- Homepage: [http://www.getwox.com/](http://www.getwox.com/)
- Doc: [http://doc.getwox.com/en/](http://doc.getwox.com/en/)

# Changelog
v1.0.0 (05/06/2017 07:19 GMT) : First Release
- v1.0.0 (05/06/2017 07:19 GMT) : First Release
- v1.0.1 (06/06/2017 07:50 GMT) : Auto convert based on computer's location, instead of Windows Region
2 changes: 1 addition & 1 deletion Currency/plugin.json → plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name":"Currency",
"Description":"An easy-to-use Currency Converter for Wox",
"Author":"SakaDream",
"Version":"1.0.0",
"Version":"1.0.1",
"Language":"csharp",
"Website":"https://github.com/SakaDream/wox-currency-converter",
"IcoPath": "Images\\icon.png",
Expand Down

0 comments on commit 66230cc

Please sign in to comment.