mirror of
https://github.com/g3rv4/GetMoarFediverse.git
synced 2024-11-21 23:23:09 +01:00
Use Mastodon's API to fetch hashtagged statuses (#39)
This commit is contained in:
parent
6fd7804d6c
commit
d9faf231a0
@ -7,7 +7,7 @@ internal partial class JsonContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(TagResponse))]
|
||||
[JsonSerializable(typeof(Status[]))]
|
||||
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
|
||||
internal partial class CamelCaseJsonContext : JsonSerializerContext
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ await Parallel.ForEachAsync(sitesTags, new ParallelOptions{MaxDegreeOfParallelis
|
||||
var (site, tag) = st;
|
||||
Console.WriteLine($"Fetching tag #{tag} from {site}");
|
||||
|
||||
var url = $"https://{site}/tags/{tag}.json";
|
||||
var url = $"https://{site}/api/v1/timelines/tag/{tag}?limit=40";
|
||||
if (sitesRobotFile.TryGetValue(site, out var robotsFile))
|
||||
{
|
||||
var allowed = robotsFile.IsAllowedAccess(new Uri(url), "GetMoarFediverse");
|
||||
@ -114,23 +114,18 @@ await Parallel.ForEachAsync(sitesTags, new ParallelOptions{MaxDegreeOfParallelis
|
||||
}
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var data = JsonSerializer.Deserialize(json, CamelCaseJsonContext.Default.TagResponse);
|
||||
|
||||
var data = JsonSerializer.Deserialize(json, CamelCaseJsonContext.Default.StatusArray);
|
||||
if (data == null)
|
||||
{
|
||||
Console.WriteLine($"Error deserializing the response when pulling #{tag} posts from {site}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.OrderedItems == null)
|
||||
{
|
||||
Console.WriteLine($"Got null on OrderedItems when pulling #{tag} posts from {site}");
|
||||
return;
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
foreach (var statusLink in data.OrderedItems.Where(i => !imported.Contains(i)))
|
||||
foreach (var statusLink in data.Where(i => !imported.Contains(i.Uri)))
|
||||
{
|
||||
statusesToLoadBag.Add(statusLink);
|
||||
statusesToLoadBag.Add(statusLink.Uri);
|
||||
count++;
|
||||
}
|
||||
|
||||
@ -168,12 +163,12 @@ if (importedList.Count > 5000)
|
||||
|
||||
File.WriteAllLines(importedPath, importedList);
|
||||
|
||||
public class TagResponse
|
||||
public class Status
|
||||
{
|
||||
public string[]? OrderedItems { get; }
|
||||
public string Uri { get; }
|
||||
|
||||
public TagResponse(string[] orderedItems)
|
||||
public Status(string uri)
|
||||
{
|
||||
OrderedItems = orderedItems;
|
||||
Uri = uri;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user