aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2021-11-29 17:10:43 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2021-11-29 17:10:43 +0300
commitd176a023f06d70cb577e64d1a917e77d677d2a2b (patch)
tree9fac9e0444baa16cb748d86abafbbb6c6b67909e
parent15995027bfbc535e4b9ffa159607caaffdecc478 (diff)
Add clean request private method
-rw-r--r--Assistant/SkuAssist.cs9
-rw-r--r--Functions.cs2
-rw-r--r--Rehau.Sku.Assist-AddIn-packed.xllbin0 -> 653312 bytes
-rw-r--r--Rehau.Sku.Assist.csproj2
4 files changed, 10 insertions, 3 deletions
diff --git a/Assistant/SkuAssist.cs b/Assistant/SkuAssist.cs
index 9d90394..dc36dc0 100644
--- a/Assistant/SkuAssist.cs
+++ b/Assistant/SkuAssist.cs
@@ -3,6 +3,7 @@ using AngleSharp.Dom;
using System.Linq;
using System.Net;
using System.Net.Http;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Rehau.Sku.Assist
@@ -11,7 +12,7 @@ namespace Rehau.Sku.Assist
{
public async static Task<string> GetContent(string request, HttpClient httpClient)
{
- string uri = "https://shop-rehau.ru/catalogsearch/result/?q=" + request;
+ string uri = "https://shop-rehau.ru/catalogsearch/result/?q=" + request._CleanRequest();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
return await httpClient.GetStringAsync(uri);
@@ -31,9 +32,13 @@ namespace Rehau.Sku.Assist
.All
.Where(e => e.ClassName == "product-item__desc-top")
.Select(e => new Product(e.Children[0].TextContent, e.Children[1].TextContent.Trim(new[] { '\n', ' ' })))
- // .Where(product => !product.Sku.Any(c => char.IsLetter(c)))
.FirstOrDefault();
}
+
+ private static string _CleanRequest(this string input)
+ {
+ return input.Replace("+", " plus ");
+ }
}
}
diff --git a/Functions.cs b/Functions.cs
index 9112822..6792195 100644
--- a/Functions.cs
+++ b/Functions.cs
@@ -15,7 +15,7 @@ namespace Rehau.Sku.Assist
Task<string> contentTask = Task.Run(() => SkuAssist.GetContent(request, httpClient));
Task<IDocument> documentTask = await contentTask.ContinueWith(content => SkuAssist.GetDocument(content));
IProduct product = await documentTask.ContinueWith(doc => SkuAssist.GetProductFromDocument(doc.Result));
- return product.ToString();
+ return product == null ? ExcelError.ExcelErrorNull.ToString() : product.ToString();
}
}
} \ No newline at end of file
diff --git a/Rehau.Sku.Assist-AddIn-packed.xll b/Rehau.Sku.Assist-AddIn-packed.xll
new file mode 100644
index 0000000..aea355f
--- /dev/null
+++ b/Rehau.Sku.Assist-AddIn-packed.xll
Binary files differ
diff --git a/Rehau.Sku.Assist.csproj b/Rehau.Sku.Assist.csproj
index 144c4f6..86fe220 100644
--- a/Rehau.Sku.Assist.csproj
+++ b/Rehau.Sku.Assist.csproj
@@ -36,6 +36,7 @@
<ItemGroup>
<Reference Include="AngleSharp, Version=0.16.1.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
<HintPath>packages\AngleSharp.0.16.1\lib\net472\AngleSharp.dll</HintPath>
+ <Private>True</Private>
</Reference>
<Reference Include="ExcelDna.Integration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f225e9659857edbe, processorArchitecture=MSIL">
<HintPath>packages\ExcelDna.Integration.1.5.0\lib\net452\ExcelDna.Integration.dll</HintPath>
@@ -43,6 +44,7 @@
</Reference>
<Reference Include="ExcelDna.Registration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f225e9659857edbe, processorArchitecture=MSIL">
<HintPath>packages\ExcelDna.Registration.1.5.0\lib\net452\ExcelDna.Registration.dll</HintPath>
+ <Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">