Created
June 28, 2019 23:19
-
-
Save Lucas7yoshi/07ed8532f0b66864e8fcfeea528d692e to your computer and use it in GitHub Desktop.
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
// <auto-generated /> | |
// | |
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: | |
// | |
// using QuickType; | |
// | |
// var bidWars = BidWars.FromJson(jsonString); | |
namespace QuickType | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Globalization; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Converters; | |
public partial class BidWars | |
{ | |
[JsonProperty("pk")] | |
public long Pk { get; set; } | |
[JsonProperty("model")] | |
public Model Model { get; set; } | |
[JsonProperty("fields")] | |
public Fields Fields { get; set; } | |
} | |
public partial class Fields | |
{ | |
[JsonProperty("rght")] | |
public long Rght { get; set; } | |
[JsonProperty("biddependency")] | |
public object Biddependency { get; set; } | |
[JsonProperty("speedrun__console")] | |
public string SpeedrunConsole { get; set; } | |
[JsonProperty("speedrun__endtime")] | |
public DateTimeOffset SpeedrunEndtime { get; set; } | |
[JsonProperty("speedrun__category")] | |
public string SpeedrunCategory { get; set; } | |
[JsonProperty("event__locked")] | |
public bool EventLocked { get; set; } | |
[JsonProperty("event__public")] | |
public Event EventPublic { get; set; } | |
[JsonProperty("lft")] | |
public long Lft { get; set; } | |
[JsonProperty("revealedtime")] | |
public DateTimeOffset Revealedtime { get; set; } | |
[JsonProperty("speedrun__deprecated_runners")] | |
public string SpeedrunDeprecatedRunners { get; set; } | |
[JsonProperty("total")] | |
public string Total { get; set; } | |
[JsonProperty("event")] | |
public long Event { get; set; } | |
[JsonProperty("speedrun__coop")] | |
public bool SpeedrunCoop { get; set; } | |
[JsonProperty("option_max_length")] | |
public long? OptionMaxLength { get; set; } | |
[JsonProperty("speedrun__tech_notes")] | |
public string SpeedrunTechNotes { get; set; } | |
[JsonProperty("goal")] | |
public string Goal { get; set; } | |
[JsonProperty("event__datetime")] | |
public DateTimeOffset EventDatetime { get; set; } | |
[JsonProperty("allowuseroptions")] | |
public bool Allowuseroptions { get; set; } | |
[JsonProperty("speedrun__description")] | |
public string SpeedrunDescription { get; set; } | |
[JsonProperty("event__name")] | |
public Event EventName { get; set; } | |
[JsonProperty("state")] | |
public State State { get; set; } | |
[JsonProperty("speedrun__display_name")] | |
public string SpeedrunDisplayName { get; set; } | |
[JsonProperty("event__minimumdonation")] | |
public string EventMinimumdonation { get; set; } | |
[JsonProperty("tree_id")] | |
public long TreeId { get; set; } | |
[JsonProperty("event__timezone")] | |
public EventTimezone EventTimezone { get; set; } | |
[JsonProperty("speedrun__starttime")] | |
public DateTimeOffset SpeedrunStarttime { get; set; } | |
[JsonProperty("public")] | |
public string Public { get; set; } | |
[JsonProperty("speedrun__order")] | |
public long SpeedrunOrder { get; set; } | |
[JsonProperty("speedrun__commentators")] | |
public string SpeedrunCommentators { get; set; } | |
[JsonProperty("description")] | |
public string Description { get; set; } | |
[JsonProperty("parent")] | |
public object Parent { get; set; } | |
[JsonProperty("speedrun__setup_time")] | |
public string SpeedrunSetupTime { get; set; } | |
[JsonProperty("event__paypalcurrency")] | |
public EventPaypalcurrency EventPaypalcurrency { get; set; } | |
[JsonProperty("event__use_one_step_screening")] | |
public bool EventUseOneStepScreening { get; set; } | |
[JsonProperty("event__auto_approve_threshold")] | |
public object EventAutoApproveThreshold { get; set; } | |
[JsonProperty("event__receivername")] | |
public EventReceivername EventReceivername { get; set; } | |
[JsonProperty("event__short")] | |
public EventShort EventShort { get; set; } | |
[JsonProperty("speedrun__run_time")] | |
public string SpeedrunRunTime { get; set; } | |
[JsonProperty("speedrun__public")] | |
public string SpeedrunPublic { get; set; } | |
[JsonProperty("count")] | |
public long Count { get; set; } | |
[JsonProperty("istarget")] | |
public bool Istarget { get; set; } | |
[JsonProperty("name")] | |
public string Name { get; set; } | |
[JsonProperty("level")] | |
public long Level { get; set; } | |
[JsonProperty("speedrun")] | |
public long Speedrun { get; set; } | |
[JsonProperty("event__targetamount")] | |
public string EventTargetamount { get; set; } | |
[JsonProperty("speedrun__name")] | |
public string SpeedrunName { get; set; } | |
[JsonProperty("speedrun__release_year")] | |
public long? SpeedrunReleaseYear { get; set; } | |
[JsonProperty("event__donationemailsender")] | |
public object EventDonationemailsender { get; set; } | |
[JsonProperty("event__prize_accept_deadline_delta")] | |
public long EventPrizeAcceptDeadlineDelta { get; set; } | |
[JsonProperty("shortdescription")] | |
public string Shortdescription { get; set; } | |
[JsonProperty("event__paypalemail")] | |
public EventPaypalemail EventPaypalemail { get; set; } | |
} | |
public enum Event { SummerGamesDoneQuick2019 }; | |
public enum EventPaypalcurrency { Usd }; | |
public enum EventPaypalemail { AndreuMaldonadoNewyorkMsfOrg }; | |
public enum EventReceivername { DoctorsWithoutBorders }; | |
public enum EventShort { Sgdq2019 }; | |
public enum EventTimezone { UsCentral }; | |
public enum State { Closed, Opened }; | |
public enum Model { TrackerBid }; | |
public partial class BidWars | |
{ | |
public static BidWars[] FromJson(string json) => JsonConvert.DeserializeObject<BidWars[]>(json, QuickType.Converter.Settings); | |
} | |
public static class Serialize | |
{ | |
public static string ToJson(this BidWars[] self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings); | |
} | |
internal static class Converter | |
{ | |
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings | |
{ | |
MetadataPropertyHandling = MetadataPropertyHandling.Ignore, | |
DateParseHandling = DateParseHandling.None, | |
Converters = | |
{ | |
EventConverter.Singleton, | |
EventPaypalcurrencyConverter.Singleton, | |
EventPaypalemailConverter.Singleton, | |
EventReceivernameConverter.Singleton, | |
EventShortConverter.Singleton, | |
EventTimezoneConverter.Singleton, | |
StateConverter.Singleton, | |
ModelConverter.Singleton, | |
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal } | |
}, | |
}; | |
} | |
internal class EventConverter : JsonConverter | |
{ | |
public override bool CanConvert(Type t) => t == typeof(Event) || t == typeof(Event?); | |
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
{ | |
if (reader.TokenType == JsonToken.Null) return null; | |
var value = serializer.Deserialize<string>(reader); | |
if (value == "Summer Games Done Quick 2019") | |
{ | |
return Event.SummerGamesDoneQuick2019; | |
} | |
throw new Exception("Cannot unmarshal type Event"); | |
} | |
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
{ | |
if (untypedValue == null) | |
{ | |
serializer.Serialize(writer, null); | |
return; | |
} | |
var value = (Event)untypedValue; | |
if (value == Event.SummerGamesDoneQuick2019) | |
{ | |
serializer.Serialize(writer, "Summer Games Done Quick 2019"); | |
return; | |
} | |
throw new Exception("Cannot marshal type Event"); | |
} | |
public static readonly EventConverter Singleton = new EventConverter(); | |
} | |
internal class EventPaypalcurrencyConverter : JsonConverter | |
{ | |
public override bool CanConvert(Type t) => t == typeof(EventPaypalcurrency) || t == typeof(EventPaypalcurrency?); | |
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
{ | |
if (reader.TokenType == JsonToken.Null) return null; | |
var value = serializer.Deserialize<string>(reader); | |
if (value == "USD") | |
{ | |
return EventPaypalcurrency.Usd; | |
} | |
throw new Exception("Cannot unmarshal type EventPaypalcurrency"); | |
} | |
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
{ | |
if (untypedValue == null) | |
{ | |
serializer.Serialize(writer, null); | |
return; | |
} | |
var value = (EventPaypalcurrency)untypedValue; | |
if (value == EventPaypalcurrency.Usd) | |
{ | |
serializer.Serialize(writer, "USD"); | |
return; | |
} | |
throw new Exception("Cannot marshal type EventPaypalcurrency"); | |
} | |
public static readonly EventPaypalcurrencyConverter Singleton = new EventPaypalcurrencyConverter(); | |
} | |
internal class EventPaypalemailConverter : JsonConverter | |
{ | |
public override bool CanConvert(Type t) => t == typeof(EventPaypalemail) || t == typeof(EventPaypalemail?); | |
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
{ | |
if (reader.TokenType == JsonToken.Null) return null; | |
var value = serializer.Deserialize<string>(reader); | |
if (value == "andreu.maldonado@newyork.msf.org") | |
{ | |
return EventPaypalemail.AndreuMaldonadoNewyorkMsfOrg; | |
} | |
throw new Exception("Cannot unmarshal type EventPaypalemail"); | |
} | |
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
{ | |
if (untypedValue == null) | |
{ | |
serializer.Serialize(writer, null); | |
return; | |
} | |
var value = (EventPaypalemail)untypedValue; | |
if (value == EventPaypalemail.AndreuMaldonadoNewyorkMsfOrg) | |
{ | |
serializer.Serialize(writer, "andreu.maldonado@newyork.msf.org"); | |
return; | |
} | |
throw new Exception("Cannot marshal type EventPaypalemail"); | |
} | |
public static readonly EventPaypalemailConverter Singleton = new EventPaypalemailConverter(); | |
} | |
internal class EventReceivernameConverter : JsonConverter | |
{ | |
public override bool CanConvert(Type t) => t == typeof(EventReceivername) || t == typeof(EventReceivername?); | |
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
{ | |
if (reader.TokenType == JsonToken.Null) return null; | |
var value = serializer.Deserialize<string>(reader); | |
if (value == "Doctors Without Borders") | |
{ | |
return EventReceivername.DoctorsWithoutBorders; | |
} | |
throw new Exception("Cannot unmarshal type EventReceivername"); | |
} | |
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
{ | |
if (untypedValue == null) | |
{ | |
serializer.Serialize(writer, null); | |
return; | |
} | |
var value = (EventReceivername)untypedValue; | |
if (value == EventReceivername.DoctorsWithoutBorders) | |
{ | |
serializer.Serialize(writer, "Doctors Without Borders"); | |
return; | |
} | |
throw new Exception("Cannot marshal type EventReceivername"); | |
} | |
public static readonly EventReceivernameConverter Singleton = new EventReceivernameConverter(); | |
} | |
internal class EventShortConverter : JsonConverter | |
{ | |
public override bool CanConvert(Type t) => t == typeof(EventShort) || t == typeof(EventShort?); | |
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
{ | |
if (reader.TokenType == JsonToken.Null) return null; | |
var value = serializer.Deserialize<string>(reader); | |
if (value == "sgdq2019") | |
{ | |
return EventShort.Sgdq2019; | |
} | |
throw new Exception("Cannot unmarshal type EventShort"); | |
} | |
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
{ | |
if (untypedValue == null) | |
{ | |
serializer.Serialize(writer, null); | |
return; | |
} | |
var value = (EventShort)untypedValue; | |
if (value == EventShort.Sgdq2019) | |
{ | |
serializer.Serialize(writer, "sgdq2019"); | |
return; | |
} | |
throw new Exception("Cannot marshal type EventShort"); | |
} | |
public static readonly EventShortConverter Singleton = new EventShortConverter(); | |
} | |
internal class EventTimezoneConverter : JsonConverter | |
{ | |
public override bool CanConvert(Type t) => t == typeof(EventTimezone) || t == typeof(EventTimezone?); | |
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
{ | |
if (reader.TokenType == JsonToken.Null) return null; | |
var value = serializer.Deserialize<string>(reader); | |
if (value == "US/Central") | |
{ | |
return EventTimezone.UsCentral; | |
} | |
throw new Exception("Cannot unmarshal type EventTimezone"); | |
} | |
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
{ | |
if (untypedValue == null) | |
{ | |
serializer.Serialize(writer, null); | |
return; | |
} | |
var value = (EventTimezone)untypedValue; | |
if (value == EventTimezone.UsCentral) | |
{ | |
serializer.Serialize(writer, "US/Central"); | |
return; | |
} | |
throw new Exception("Cannot marshal type EventTimezone"); | |
} | |
public static readonly EventTimezoneConverter Singleton = new EventTimezoneConverter(); | |
} | |
internal class StateConverter : JsonConverter | |
{ | |
public override bool CanConvert(Type t) => t == typeof(State) || t == typeof(State?); | |
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
{ | |
if (reader.TokenType == JsonToken.Null) return null; | |
var value = serializer.Deserialize<string>(reader); | |
switch (value) | |
{ | |
case "CLOSED": | |
return State.Closed; | |
case "OPENED": | |
return State.Opened; | |
} | |
throw new Exception("Cannot unmarshal type State"); | |
} | |
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
{ | |
if (untypedValue == null) | |
{ | |
serializer.Serialize(writer, null); | |
return; | |
} | |
var value = (State)untypedValue; | |
switch (value) | |
{ | |
case State.Closed: | |
serializer.Serialize(writer, "CLOSED"); | |
return; | |
case State.Opened: | |
serializer.Serialize(writer, "OPENED"); | |
return; | |
} | |
throw new Exception("Cannot marshal type State"); | |
} | |
public static readonly StateConverter Singleton = new StateConverter(); | |
} | |
internal class ModelConverter : JsonConverter | |
{ | |
public override bool CanConvert(Type t) => t == typeof(Model) || t == typeof(Model?); | |
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer) | |
{ | |
if (reader.TokenType == JsonToken.Null) return null; | |
var value = serializer.Deserialize<string>(reader); | |
if (value == "tracker.bid") | |
{ | |
return Model.TrackerBid; | |
} | |
throw new Exception("Cannot unmarshal type Model"); | |
} | |
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) | |
{ | |
if (untypedValue == null) | |
{ | |
serializer.Serialize(writer, null); | |
return; | |
} | |
var value = (Model)untypedValue; | |
if (value == Model.TrackerBid) | |
{ | |
serializer.Serialize(writer, "tracker.bid"); | |
return; | |
} | |
throw new Exception("Cannot marshal type Model"); | |
} | |
public static readonly ModelConverter Singleton = new ModelConverter(); | |
} | |
} |
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
using System; | |
using System.Linq; | |
using System.Net; | |
using System.Threading.Tasks; | |
using QuickType; | |
namespace XPathTracker | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
new Program().Run().GetAwaiter().GetResult(); | |
} | |
public async Task Run() | |
{ | |
var wc = new WebClient(); | |
while (true) | |
{ | |
var rawjson = wc.DownloadString("https://gamesdonequick.com/tracker/search/?type=bid&event=26"); | |
var bw = BidWars.FromJson(rawjson); | |
var entry = bw.First(x => x.Pk == 9022); | |
var current = int.Parse(entry.Fields.Total.Split('.')[0]); | |
var goal = int.Parse(entry.Fields.Goal.Split('.')[0]); | |
var percentage = current * 100 / goal; | |
Console.Clear(); | |
Console.WriteLine($"${current} / ${goal}\n{percentage}%"); | |
await Task.Delay(1000); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment