ability to save spotlight data for current date

This commit is contained in:
2015-05-05 01:22:58 +02:00
parent 53437cdc8c
commit 97ec658db8
5 changed files with 63 additions and 4 deletions
+2 -1
View File
@@ -183,4 +183,5 @@ Development/*.js
# Project # Project
# ========================= # =========================
src/OnePeek.sln.ide/* src/OnePeek.sln.ide/*
src/OnePeek.Console/ src/OnePeek.Console/
AppData/
+51 -1
View File
@@ -1,14 +1,19 @@
using Nancy; using Nancy;
using Newtonsoft.Json;
using OnePeek.Api; using OnePeek.Api;
using OnePeek.Entities; using OnePeek.Entities;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO; using System.IO;
using System.Reflection;
using System.Threading;
namespace OnePeek.WebConsole.Modules namespace OnePeek.WebConsole.Modules
{ {
public class ApiModule : NancyModule public class ApiModule : NancyModule
{ {
public ApiModule() : base("api/") public ApiModule(IRootPathProvider rootProvider) : base("api/")
{ {
OnePeekApi api = new OnePeekApi(); OnePeekApi api = new OnePeekApi();
@@ -19,6 +24,51 @@ namespace OnePeek.WebConsole.Modules
}; };
Post["/spotlight", true] = async (ctx, token) =>
{
IEnumerable<StoreSpotlightIdResults> apps1 = await api.GetSpotlightIdsForAllCultures(StoreSpotlightType.Apps, StoreType.WindowsPhone8, default(CancellationToken));
IEnumerable<StoreSpotlightIdResults> games1 = await api.GetSpotlightIdsForAllCultures(StoreSpotlightType.Games, StoreType.WindowsPhone8, default(CancellationToken));
Dictionary<string, string> apps = new Dictionary<string, string>();
Dictionary<string, string> games = new Dictionary<string, string>();
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) => Get["/reviews/{id}", true] = async (ctx, token) =>
{ {
AppReviews reviews = await api.GetReviews(ctx.id, StoreType.WindowsPhone8, StoreCultureType.EN_US, StoreReviewSorting.Latest); AppReviews reviews = await api.GetReviews(ctx.id, StoreType.WindowsPhone8, StoreCultureType.EN_US, StoreReviewSorting.Latest);
@@ -49,6 +49,10 @@
<Reference Include="Nancy.ViewEngines.Razor"> <Reference Include="Nancy.ViewEngines.Razor">
<HintPath>..\packages\Nancy.Viewengines.Razor.1.1\lib\net40\Nancy.ViewEngines.Razor.dll</HintPath> <HintPath>..\packages\Nancy.Viewengines.Razor.1.1\lib\net40\Nancy.ViewEngines.Razor.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.7.0.1-beta3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.DynamicData" /> <Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" /> <Reference Include="System.Web.Entity" />
+5 -2
View File
@@ -37,8 +37,11 @@
<br /><br /> <br /><br />
<div class="large-12 columns"> <div class="large-12 columns">
<h3>SPOTLIGHT SUMMARY</h3> <form action="/api/spotlight" method="post">
<a href="/spotlight" class="button">load</a> <h3>SPOTLIGHT SUMMARY</h3>
<a href="/spotlight" class="button">load</a>&nbsp;
<input type="submit" value="save" class="button" />
</form>
</div> </div>
<div style="clear:both;"></div> <div style="clear:both;"></div>
+1
View File
@@ -4,4 +4,5 @@
<package id="Nancy" version="1.1" targetFramework="net45" /> <package id="Nancy" version="1.1" targetFramework="net45" />
<package id="Nancy.Hosting.Aspnet" version="1.1" targetFramework="net45" /> <package id="Nancy.Hosting.Aspnet" version="1.1" targetFramework="net45" />
<package id="Nancy.Viewengines.Razor" version="1.1" targetFramework="net451" /> <package id="Nancy.Viewengines.Razor" version="1.1" targetFramework="net451" />
<package id="Newtonsoft.Json" version="7.0.1-beta3" targetFramework="net451" />
</packages> </packages>