Skip to content

Commit

Permalink
Update for WWDC23
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewspear committed Jun 10, 2023
1 parent 1a0d1a1 commit a9a8581
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 55 deletions.
94 changes: 54 additions & 40 deletions Sessions.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import UIKit
import PlaygroundSupport
import UIKit

let file = "contents.json"
let url = URL(string: "https://api2021.wwdc.io/contents.json")!
let eventID = "wwdc2022"
let outputFile = "WWDC22"
let eventID = "wwdc2023"
let outputFile = "WWDC23"

print("Hello")

Expand All @@ -16,16 +16,17 @@ var contents: [Video]
let semaphore = DispatchSemaphore(value: 0)

if useWeb {
let session = URLSession(configuration: .default)
let task = session.dataTask(with: URLRequest(url: url)) { data, response, error in
guard let data = data else { return }
jsonData = data.decode(JSONData.self)
semaphore.signal()
}
task.resume()
} else {
jsonData = Bundle.main.decode(JSONData.self, from: file)
let session = URLSession(configuration: .default)
let task = session.dataTask(with: URLRequest(url: url)) { data, _, _ in
guard let data = data else { return }
jsonData = data.decode(JSONData.self)
// print(jsonData!)
semaphore.signal()
}
task.resume()
} else {
jsonData = Bundle.main.decode(JSONData.self, from: file)
semaphore.signal()
}

semaphore.wait()
Expand All @@ -42,50 +43,63 @@ printFormatter.dateFormat = "dd"
let dayOfWeekFormatter = DateFormatter()
dayOfWeekFormatter.dateFormat = "E"


func dateToDayOfTheWeek(for date: String) -> String {
let start = dateFormatter.date(from: date)!
if let start = dateFormatter.date(from: date) {
return dayOfWeekFormatter.string(from: start)
} else {
return ""
}
}

func dateToDay(for date: String) -> String {
let start = dateFormatter.date(from: date)!
if let start = dateFormatter.date(from: date) {
return printFormatter.string(from: start)
} else {
return ""
}
}

for item in contents {
if item.eventId == eventID,
item.type != "Lab by Appointment" {

outputString += "\(item.id); "
outputString += "\(item.title); "

let day = dateToDay(for: item.startTime)
outputString += "\(day); "

let dayOfTheWeek = dateToDayOfTheWeek(for: item.startTime)
outputString += "\(dayOfTheWeek); "

if let media = item.media {
outputString += "\(media.duration / 60); "
} else {
outputString += "; "
}

outputString += "\(item.webPermalink); "

outputString += " ; ; ;\n"
if item.eventId == eventID,
item.type == "Video"
// !item.title.contains("Q&A:")
{
outputString += "\(item.id); "
outputString += "\(item.title); "

if let startTime = item.originalPublishingDate {
print(startTime)
let day = dateToDay(for: startTime)
let dayOfTheWeek = dateToDayOfTheWeek(for: startTime)
outputString += "\(day); \(dayOfTheWeek); "
} else {
outputString += "; ; "
}

// if let startTime = item.startTime {
// outputString += "\(startTime); "
// }

if let media = item.media {
outputString += "\(media.duration / 60); "
} else {
outputString += "; "
}

outputString += "\(item.webPermalink); "

outputString += " ; ; ;\n"
}
}

let outputFolder = PlaygroundSupport.playgroundSharedDataDirectory
let outputURL = outputFolder.appendingPathComponent("\(outputFile).csv")

do {
try FileManager.default.createDirectory(at: outputFolder, withIntermediateDirectories: true, attributes: nil)
try outputString.write(toFile: outputURL.path, atomically: false, encoding: .utf8)
} catch let error {
print(error.localizedDescription)
try FileManager.default.createDirectory(at: outputFolder, withIntermediateDirectories: true, attributes: nil)
try outputString.write(toFile: outputURL.path, atomically: false, encoding: .utf8)
} catch {
print(error.localizedDescription)
}

print("Open \(outputFile).csv via:")
Expand Down
32 changes: 17 additions & 15 deletions Sessions.playground/Sources/Models.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import Foundation

public struct JSONData: Decodable {
public let contents: [Video]
public let contents: [Video]
}

public struct Video: Decodable {
public let id: String
public let staticContentId: Int
public let eventContentId: Int
public let eventId: String
public let webPermalink: String
public let description: String
public let title: String
public let topicIds: [Int]
public let type: String
public let trackId: Int
public let startTime: String
public let endTime: String
public let media: Media?
public let id: String
public let staticContentId: Int
public let eventContentId: Int
public let eventId: String
public let webPermalink: String
public let description: String
public let title: String
public let topicIds: [Int]
public let type: String
public let trackId: Int
public let startTime: String?
public let originalPublishingDate: String?
// public let endTime: String = ""
public let media: Media?
}

public struct Media: Decodable {
public let duration: Int
public let duration: Int
}

0 comments on commit a9a8581

Please sign in to comment.