cleanup, update ongoing events continuously
This commit is contained in:
parent
7d123e9452
commit
b9bdd9594e
|
@ -13,6 +13,9 @@
|
|||
ViewData["Title"] = Request.Query["c"];
|
||||
var wc = new WebClient();
|
||||
var conference = c3stream.Conferences.First(c => c.Acronym == Request.Query["c"]);
|
||||
if (conference.Ongoing) {
|
||||
c3stream.UpdateConference(conference);
|
||||
}
|
||||
wc.Dispose();
|
||||
}
|
||||
|
||||
|
@ -35,8 +38,7 @@
|
|||
var isWatched = state == "watched";
|
||||
var isMarked = state == "marked";
|
||||
var file = $"{talk.Slug}.mp4";
|
||||
var tagV = c3stream.Conferences.First(c => c.Acronym == Request.Query["c"]).TagVersion;
|
||||
var eventName = tagV == 0 ? conference.Acronym : talk.Tags[0].Replace("-", "-<br/>");
|
||||
var eventName = talk.Tags.Count > 1 ? conference.Acronym : talk.Tags[0].Replace("-", "-<br/>");
|
||||
var category = talk.Tags.Count switch {
|
||||
0 => "<no category>",
|
||||
1 => talk.Tags[0],
|
||||
|
|
|
@ -39,9 +39,8 @@ namespace c3stream.Pages {
|
|||
}
|
||||
|
||||
public static void WriteUserData() {
|
||||
lock (c3stream.Lock) {
|
||||
lock (c3stream.Lock)
|
||||
System.IO.File.WriteAllText(c3stream.DbPath, JsonConvert.SerializeObject(UserData));
|
||||
}
|
||||
}
|
||||
|
||||
public class UserStatus {
|
||||
|
|
|
@ -34,8 +34,7 @@
|
|||
var file = $"{talk.Slug}.mp4";
|
||||
var conference = c3stream.GetConferenceByEventGuid(talk.Guid);
|
||||
|
||||
var tagV = c3stream.Conferences.First(c => c.Acronym == Request.Query["c"]).TagVersion;
|
||||
var eventName = tagV == 0 ? conference.Acronym : talk.Tags[0].Replace("-", "-<br/>");
|
||||
var eventName = talk.Tags.Count > 1 ? conference.Acronym : talk.Tags[0].Replace("-", "-<br/>");
|
||||
|
||||
var category = talk.Tags.Count switch {
|
||||
0 => "<no category>",
|
||||
|
|
55
c3stream.cs
55
c3stream.cs
|
@ -18,10 +18,10 @@ namespace c3stream {
|
|||
public static string DbPath = Path.Combine(DataPath, DbFile);
|
||||
|
||||
public static List<ConferenceObject> Conferences = new List<ConferenceObject> {
|
||||
new ConferenceObject("36c3", 2, true),
|
||||
new ConferenceObject("36c3", true),
|
||||
new ConferenceObject("camp2019"),
|
||||
new ConferenceObject("35c3", 1),
|
||||
new ConferenceObject("34c3", 1),
|
||||
new ConferenceObject("35c3"),
|
||||
new ConferenceObject("34c3"),
|
||||
new ConferenceObject("33c3"),
|
||||
new ConferenceObject("32c3"),
|
||||
new ConferenceObject("31c3"),
|
||||
|
@ -34,22 +34,8 @@ namespace c3stream {
|
|||
if (!File.Exists(DbPath))
|
||||
ConferenceModel.WriteUserData();
|
||||
|
||||
using var wc = new WebClient();
|
||||
|
||||
foreach (var conference in Conferences) {
|
||||
var jsonpath = Path.Combine(DataPath, conference.Acronym + "_index.json");
|
||||
var json = "";
|
||||
if (conference.Ongoing || !File.Exists(jsonpath)) {
|
||||
json = wc.DownloadString($"https://api.media.ccc.de/public/conferences/{conference.Acronym}");
|
||||
File.WriteAllText(jsonpath, json);
|
||||
}
|
||||
else {
|
||||
json = File.ReadAllText(jsonpath);
|
||||
}
|
||||
|
||||
var parsed = Conference.FromJson(json);
|
||||
conference.Talks.AddRange(parsed.Events);
|
||||
}
|
||||
foreach (var conference in Conferences)
|
||||
UpdateConference(conference);
|
||||
|
||||
if (args.Length != 0) {
|
||||
if (Conferences.All(p => p.Acronym != args[0]))
|
||||
|
@ -63,6 +49,29 @@ namespace c3stream {
|
|||
}
|
||||
}
|
||||
|
||||
public static void UpdateConference(ConferenceObject conference) {
|
||||
using var wc = new WebClient();
|
||||
|
||||
var jsonpath = Path.Combine(DataPath, conference.Acronym + "_index.json");
|
||||
var json = "";
|
||||
if (!File.Exists(jsonpath)) {
|
||||
json = wc.DownloadString($"https://api.media.ccc.de/public/conferences/{conference.Acronym}");
|
||||
File.WriteAllText(jsonpath, json);
|
||||
}
|
||||
else if (conference.Ongoing) {
|
||||
json = wc.DownloadString($"https://api.media.ccc.de/public/conferences/{conference.Acronym}");
|
||||
}
|
||||
else {
|
||||
json = File.ReadAllText(jsonpath);
|
||||
}
|
||||
|
||||
var parsed = Conference.FromJson(json);
|
||||
lock (Lock) {
|
||||
conference.Talks.Clear();
|
||||
conference.Talks.AddRange(parsed.Events);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateCookie(HttpRequest resquest, HttpResponse response, string redirectUri) {
|
||||
//if new bookmark is in uri
|
||||
if (resquest.Query.ContainsKey("bookmark") && resquest.Cookies["bookmark"] != resquest.Query["bookmark"]) {
|
||||
|
@ -95,13 +104,11 @@ namespace c3stream {
|
|||
public class ConferenceObject {
|
||||
public string Acronym;
|
||||
public bool Ongoing;
|
||||
public int TagVersion;
|
||||
public List<Event> Talks = new List<Event>();
|
||||
|
||||
public ConferenceObject(string acronym, int tagVersion = 0, bool ongoing = false) {
|
||||
Acronym = acronym;
|
||||
TagVersion = tagVersion;
|
||||
Ongoing = ongoing;
|
||||
public ConferenceObject(string acronym, bool ongoing = false) {
|
||||
Acronym = acronym;
|
||||
Ongoing = ongoing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue