From 97ec658db81d1ed7332a12cc455b630baadc9331 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Tue, 5 May 2015 01:22:58 +0200 Subject: [PATCH] ability to save spotlight data for current date --- .gitignore | 3 +- src/OnePeek.WebConsole/Modules/ApiModule.cs | 52 ++++++++++++++++++- .../OnePeek.WebConsole.csproj | 4 ++ src/OnePeek.WebConsole/Views/Index.cshtml | 7 ++- src/OnePeek.WebConsole/packages.config | 1 + 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4f77d1e..c7e610a 100644 --- a/.gitignore +++ b/.gitignore @@ -183,4 +183,5 @@ Development/*.js # Project # ========================= src/OnePeek.sln.ide/* -src/OnePeek.Console/ \ No newline at end of file +src/OnePeek.Console/ +AppData/ \ No newline at end of file diff --git a/src/OnePeek.WebConsole/Modules/ApiModule.cs b/src/OnePeek.WebConsole/Modules/ApiModule.cs index cf6cc65..f548471 100644 --- a/src/OnePeek.WebConsole/Modules/ApiModule.cs +++ b/src/OnePeek.WebConsole/Modules/ApiModule.cs @@ -1,14 +1,19 @@ using Nancy; +using Newtonsoft.Json; using OnePeek.Api; using OnePeek.Entities; +using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.IO; +using System.Reflection; +using System.Threading; namespace OnePeek.WebConsole.Modules { public class ApiModule : NancyModule { - public ApiModule() : base("api/") + public ApiModule(IRootPathProvider rootProvider) : base("api/") { OnePeekApi api = new OnePeekApi(); @@ -19,6 +24,51 @@ namespace OnePeek.WebConsole.Modules }; + Post["/spotlight", true] = async (ctx, token) => + { + IEnumerable apps1 = await api.GetSpotlightIdsForAllCultures(StoreSpotlightType.Apps, StoreType.WindowsPhone8, default(CancellationToken)); + IEnumerable games1 = await api.GetSpotlightIdsForAllCultures(StoreSpotlightType.Games, StoreType.WindowsPhone8, default(CancellationToken)); + + Dictionary apps = new Dictionary(); + Dictionary games = new Dictionary(); + + foreach (var result in apps1) + { + foreach (var id in result.Ids) + { + if (!apps.ContainsKey(id)) + { + apps.Add(id, result.StoreCultureType.ToString()); + } + else + { + apps[id] = apps[id] + "," + result.StoreCultureType.ToString(); + } + } + } + + foreach (var result in games1) + { + foreach (var id in result.Ids) + { + if (!games.ContainsKey(id)) + { + games.Add(id, result.StoreCultureType.ToString()); + } + else + { + games[id] = games[id] + "," + result.StoreCultureType.ToString(); + } + } + } + + File.WriteAllText(Path.Combine(rootProvider.GetRootPath(), "AppData", "apps-" + DateTime.Now.ToString("yyyy-MM-dd") + ".json"), JsonConvert.SerializeObject(apps)); + File.WriteAllText(Path.Combine(rootProvider.GetRootPath(), "AppData", "games-" + DateTime.Now.ToString("yyyy-MM-dd") + ".json"), JsonConvert.SerializeObject(games)); + + return Response.AsText("ok"); + }; + + Get["/reviews/{id}", true] = async (ctx, token) => { AppReviews reviews = await api.GetReviews(ctx.id, StoreType.WindowsPhone8, StoreCultureType.EN_US, StoreReviewSorting.Latest); diff --git a/src/OnePeek.WebConsole/OnePeek.WebConsole.csproj b/src/OnePeek.WebConsole/OnePeek.WebConsole.csproj index 8a697ce..e2f2982 100644 --- a/src/OnePeek.WebConsole/OnePeek.WebConsole.csproj +++ b/src/OnePeek.WebConsole/OnePeek.WebConsole.csproj @@ -49,6 +49,10 @@ ..\packages\Nancy.Viewengines.Razor.1.1\lib\net40\Nancy.ViewEngines.Razor.dll + + False + ..\packages\Newtonsoft.Json.7.0.1-beta3\lib\net45\Newtonsoft.Json.dll + diff --git a/src/OnePeek.WebConsole/Views/Index.cshtml b/src/OnePeek.WebConsole/Views/Index.cshtml index 13b164f..856a900 100644 --- a/src/OnePeek.WebConsole/Views/Index.cshtml +++ b/src/OnePeek.WebConsole/Views/Index.cshtml @@ -37,8 +37,11 @@

-

SPOTLIGHT SUMMARY

- load +
+

SPOTLIGHT SUMMARY

+ load  + +
diff --git a/src/OnePeek.WebConsole/packages.config b/src/OnePeek.WebConsole/packages.config index a2a4eca..b145453 100644 --- a/src/OnePeek.WebConsole/packages.config +++ b/src/OnePeek.WebConsole/packages.config @@ -4,4 +4,5 @@ + \ No newline at end of file