-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add issue #125 Crawl posts from search results under "Recent" sort
- Until now the search crawler downloaded the posts with the default order ("most popular"). There was no possibility to download them with the other sort order "recent". - Now the url field also accepts search urls with the ending "/recent". Because of some quirks (same property changing between object and array) in Tumblr's json responses the Json.NET framework has been introduced.
- Loading branch information
Showing
9 changed files
with
1,706 additions
and
99 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/TumblThree/TumblThree.Applications/Converter/PropertyCopier.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace TumblThree.Applications.Converter | ||
{ | ||
public static class PropertyCopier<TSrc, TDst> where TSrc : class | ||
where TDst : class | ||
{ | ||
public static void Copy(TSrc src, TDst dst) | ||
{ | ||
var srcProperties = src.GetType().GetProperties(); | ||
var dstProperties = dst.GetType().GetProperties(); | ||
|
||
foreach (var srcProperty in srcProperties) | ||
{ | ||
foreach (var dstProperty in dstProperties) | ||
{ | ||
if (srcProperty.Name == dstProperty.Name && srcProperty.PropertyType == dstProperty.PropertyType) | ||
{ | ||
dstProperty.SetValue(dst, srcProperty.GetValue(src)); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/TumblThree/TumblThree.Applications/Converter/SingleOrArrayConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace TumblThree.Applications.Converter | ||
{ | ||
public class SingleOrArrayConverter<T> : JsonConverter | ||
{ | ||
public override bool CanConvert(Type objectType) | ||
{ | ||
return (objectType == typeof(List<T>)); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
JToken token = JToken.Load(reader); | ||
if (token.Type == JTokenType.Array) | ||
{ | ||
return token.ToObject<List<T>>(); | ||
} | ||
return new List<T> { token.ToObject<T>() }; | ||
} | ||
|
||
public override bool CanWrite | ||
{ | ||
get { return false; } | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.