Skip to content

Instantly share code, notes, and snippets.

@MickaelCruzDB
Created January 10, 2020 09:03
Show Gist options
  • Save MickaelCruzDB/2c52c99d3096d775e2ceae3040ce4a55 to your computer and use it in GitHub Desktop.
Save MickaelCruzDB/2c52c99d3096d775e2ceae3040ce4a55 to your computer and use it in GitHub Desktop.
import App
import Fluent
import FluentSQLiteDriver
import Vapor
import APNS
import Leaf
import CoreLocation
struct GlobalVariables {
static var phoneTokens = [String]()
static var sunrise: Date!
static var sunset: Date!
}
// Called before your application initializes.
func configure(_ app: Application) throws {
// Serves files from `Public/` directory
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
// Configure SQLite database
app.databases.use(.sqlite(file: "db.sqlite"), as: .sqlite)
// Configure migrations
app.migrations.add(CreateTodo())
app.apns.configuration = try .init(
keyIdentifier: "4X4FCB5YZ6",
teamIdentifier: "KPMJVZAU5Z",
signer: .init(filePath: "/Users/mika/Documents/Development/Personal/HomeHub/Certificates/HomeHub.p8"),
topic: "fr.digitalblend.HomeHubClient",
environment: .sandbox
)
GlobalVariables.phoneTokens.append("2e794c40023acbce8801fa1132ab5dd1ff9b9d8de9ab145c9c499c301111a9a7")
let solar = Solar(coordinate: CLLocationCoordinate2D(latitude: 43.5286301, longitude: 1.2266326))
GlobalVariables.sunrise = solar?.sunrise
GlobalVariables.sunset = solar?.sunset
Jobs.add(interval: .seconds(5)) {
let now = Date()
let currentTime = DateFormatter()
currentTime.timeStyle = .short
currentTime.locale = Locale(identifier: "FR-fr")
if currentTime.string(from: now) == currentTime.string(from: GlobalVariables.sunrise!) {
print("yes")
}
else {
print("no")
}
}
app.views.use(.leaf)
try routes(app)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment