5.0 release

This commit is contained in:
2019-04-05 14:26:19 +02:00
parent aade66eef8
commit 0209d1a5b1
4 changed files with 123 additions and 117 deletions
+84 -84
View File
@@ -1,101 +1,101 @@
using HtmlAgilityPack; //using HtmlAgilityPack;
using PocketSharp.Models; //using PocketSharp.Models;
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.Linq; //using System.Linq;
using System.Threading; //using System.Threading;
using System.Threading.Tasks; //using System.Threading.Tasks;
using System.Web; //using System.Web;
namespace PocketSharp //namespace PocketSharp
{ //{
/// <summary> // /// <summary>
/// PocketClient // /// PocketClient
/// </summary> // /// </summary>
public partial class PocketClient // public partial class PocketClient
{ // {
/// <summary> // /// <summary>
/// Term to use for trending articles in the Explore() method // /// Term to use for trending articles in the Explore() method
/// </summary> // /// </summary>
const string EXPLORE_TRENDING = "trending"; // const string EXPLORE_TRENDING = "trending";
/// <summary> // /// <summary>
/// Term to use for must-read articles in the Explore() method // /// Term to use for must-read articles in the Explore() method
/// </summary> // /// </summary>
const string EXPLORE_MUST_READS = "must-reads"; // const string EXPLORE_MUST_READS = "must-reads";
/// <summary> // /// <summary>
/// Explore Pocket and find interesting articles by a certain topic // /// Explore Pocket and find interesting articles by a certain topic
/// </summary> // /// </summary>
/// <param name="topic">Term or topic to get articles for</param> // /// <param name="topic">Term or topic to get articles for</param>
/// <param name="cancellationToken"></param> // /// <param name="cancellationToken"></param>
/// <returns></returns> // /// <returns></returns>
async Task<IEnumerable<PocketExploreItem>> Explore(string topic, CancellationToken cancellationToken = default(CancellationToken)) // async Task<IEnumerable<PocketExploreItem>> Explore(string topic, CancellationToken cancellationToken = default(CancellationToken))
{ // {
List<PocketExploreItem> items = new List<PocketExploreItem>(); // List<PocketExploreItem> items = new List<PocketExploreItem>();
string html = await RequestAsString("https://getpocket.com/explore/" + HttpUtility.UrlEncode(topic) , cancellationToken); // string html = await RequestAsString("https://getpocket.com/explore/" + HttpUtility.UrlEncode(topic), cancellationToken);
var document = new HtmlDocument(); // var document = new HtmlDocument();
document.LoadHtml(html); // document.LoadHtml(html);
IEnumerable<HtmlNode> nodes = document.DocumentNode.SelectNodesByClass("media_item"); // IEnumerable<HtmlNode> nodes = document.DocumentNode.SelectNodesByClass("media_item");
if (nodes == null || !nodes.Any()) // if (nodes == null || !nodes.Any())
{ // {
return items; // return items;
} // }
for (int i = 0; i < nodes.Count(); i++) // for (int i = 0; i < nodes.Count(); i++)
{ // {
HtmlNode node = nodes.ElementAt(i); // HtmlNode node = nodes.ElementAt(i);
PocketExploreItem item = new PocketExploreItem(); // PocketExploreItem item = new PocketExploreItem();
item.ID = node.Id; // item.ID = node.Id;
HtmlNode title = node.SelectNodeByClass("title")?.FirstChild; // HtmlNode title = node.SelectNodeByClass("title")?.FirstChild;
if (title == null) // if (title == null)
{ // {
continue; // continue;
} // }
// get uri // // get uri
string uri = title.GetAttributeValue("data-saveurl", null); // string uri = title.GetAttributeValue("data-saveurl", null);
item.Uri = new Uri(uri); // item.Uri = new Uri(uri);
// get image // // get image
string imageUri = node.SelectNodeByClass("item_image")?.GetAttributeValue("data-thumburl", null); // string imageUri = node.SelectNodeByClass("item_image")?.GetAttributeValue("data-thumburl", null);
if (!String.IsNullOrEmpty(imageUri)) // if (!String.IsNullOrEmpty(imageUri))
{ // {
PocketImage image = new PocketImage(); // PocketImage image = new PocketImage();
image.Uri = new Uri(imageUri); // image.Uri = new Uri(imageUri);
image.ID = "0"; // image.ID = "0";
image.ItemID = item.ID; // image.ItemID = item.ID;
item.Images = new List<PocketImage>() { image }; // item.Images = new List<PocketImage>() { image };
} // }
// get basic infos // // get basic infos
item.Title = title.InnerText; // item.Title = title.InnerText;
item.Excerpt = node.SelectNodeByClass("excerpt")?.InnerText; // item.Excerpt = node.SelectNodeByClass("excerpt")?.InnerText;
item.IsTrending = node.SelectNodeByClass("flag-trending") != null; // item.IsTrending = node.SelectNodeByClass("flag-trending") != null;
// save count // // save count
string saveCountStr = node.SelectNodeByClass("save_count")?.InnerText?.Split(' ')?.FirstOrDefault(); // string saveCountStr = node.SelectNodeByClass("save_count")?.InnerText?.Split(' ')?.FirstOrDefault();
int saveCount = 0; // int saveCount = 0;
Int32.TryParse(saveCountStr, out saveCount); // Int32.TryParse(saveCountStr, out saveCount);
item.SaveCount = saveCount; // item.SaveCount = saveCount;
// add published date // // add published date
DateTime publishedDate = DateTime.Now; // DateTime publishedDate = DateTime.Now;
if (DateTime.TryParse(node.SelectNodeByClass("read_time")?.InnerText, out publishedDate)) // if (DateTime.TryParse(node.SelectNodeByClass("read_time")?.InnerText, out publishedDate))
{ // {
item.PublishedTime = publishedDate; // item.PublishedTime = publishedDate;
} // }
items.Add(item); // items.Add(item);
} // }
return items; // return items;
} // }
} // }
} //}
+13 -3
View File
@@ -1,12 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>5.0.0</Version>
<Authors>Tobias Klika</Authors>
<Company>brothers</Company>
<RepositoryUrl>https://github.com/ceee/PocketSharp</RepositoryUrl>
<Copyright>Copyright by brothers, 2019</Copyright>
<PackageTags>PocketAPI Pocket API PocketSharp Tobias Klika cee Scott Lovegrove scottisafool NReadability SgmlReader Reader Article SDK Pockem</PackageTags>
<Description>PocketSharp is a .NET Standard library that integrates the Pocket API v3.</Description>
<PackageReleaseNotes><![CDATA[
For full release notes see https://github.com/ceee/PocketSharp/blob/master/CHANGELOG.md
]]></PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>
+7 -11
View File
@@ -1,4 +1,4 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<package > <package >
<metadata> <metadata>
<id>$id$</id> <id>$id$</id>
@@ -6,18 +6,14 @@
<title>$title$</title> <title>$title$</title>
<authors>$author$</authors> <authors>$author$</authors>
<owners>$author$</owners> <owners>$author$</owners>
<licenseUrl>https://raw.github.com/ceee/PocketSharp/master/LICENSE-MIT</licenseUrl> <license type="expression">MIT</license>
<projectUrl>https://github.com/ceee/PocketSharp</projectUrl> <projectUrl>https://github.com/ceee/PocketSharp</projectUrl>
<iconUrl>https://raw.github.com/ceee/PocketSharp/master/Assets/pocketsharp.png</iconUrl> <iconUrl>https://raw.github.com/ceee/PocketSharp/master/Assets/pocketsharp.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance> <requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>PocketSharp is a .NET Standard library that integrates the Pocket API v3.</description> <description>$description$</description>
<language>en-US</language> <language>en-US</language>
<releaseNotes> <releaseNotes>$releaseNotes$</releaseNotes>
<![CDATA[ <copyright>$copyright$</copyright>
For full release notes see https://github.com/ceee/PocketSharp/blob/master/CHANGELOG.md <tags>$tags$</tags>
]]>
</releaseNotes>
<copyright>Copyright by brothers, 2018</copyright>
<tags>PocketAPI Pocket API PocketSharp Tobias Klika cee Scott Lovegrove scottisafool NReadability SgmlReader Reader Article SDK Pockem</tags>
</metadata> </metadata>
</package> </package>
+19 -19
View File
@@ -1,22 +1,22 @@
using HtmlAgilityPack; //using HtmlAgilityPack;
using System; //using System;
using System.Collections.Generic; //using System.Collections.Generic;
using System.Linq; //using System.Linq;
using System.Text; //using System.Text;
namespace PocketSharp //namespace PocketSharp
{ //{
internal static class HtmlNodeExtensions // internal static class HtmlNodeExtensions
{ // {
public static IEnumerable<HtmlNode> SelectNodesByClass(this HtmlNode node, string className) // public static IEnumerable<HtmlNode> SelectNodesByClass(this HtmlNode node, string className)
{ // {
return node.Descendants().Where(x => x.HasClass(className)); // return node.Descendants().Where(x => x.HasClass(className));
} // }
public static HtmlNode SelectNodeByClass(this HtmlNode node, string className) // public static HtmlNode SelectNodeByClass(this HtmlNode node, string className)
{ // {
return node.Descendants().FirstOrDefault(x => x.HasClass(className)); // return node.Descendants().FirstOrDefault(x => x.HasClass(className));
} // }
} // }
} //}