Skip to content

Instantly share code, notes, and snippets.

@BlakeStevenson
Last active December 1, 2019 17:06
Show Gist options
  • Save BlakeStevenson/f82659246fded8bc29ce9c4f1f5382ae to your computer and use it in GitHub Desktop.
Save BlakeStevenson/f82659246fded8bc29ce9c4f1f5382ae to your computer and use it in GitHub Desktop.
Notion Database to Calendar
<?php
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="cal.ics"');
date_default_timezone_set('America/Chicago');
require_once './vendor/autoload.php';
// calendar name
$vCalendar = new \Eluceo\iCal\Component\Calendar('Tennis Tournaments');
// get database entries from python script
$events = json_decode(shell_exec("python3 notion.py"), true);
foreach($events as $event) {
if($event['endDate'] === "None") {
$event['endDate'] =$event['startDate'];
}
if($event['confirmationID'] == "") {
$event['confirmationID'] = "None";
}
if($event['type'] === "Verified UTR") {
$tournamentID = "";
$confirmationID = ""; } else {
$tournamentID = "\n Tournament ID: " . $event['tournamentID'] . "\n";
$confirmationID = "Confirmation ID: " . $event['confirmationID'] . "\n";
}
$vEvent = new \Eluceo\iCal\Component\Event();
$vEvent
->setDtStart(new \DateTime($event['startDate']))
->setDtEnd(new \DateTime($event['endDate']))
->setNoTime(true)
->setSummary($event['name'])
->setLocation($event['location'])
->setDescription(" Type: {$event['type']} \n URL: {$event['url']} \n Price: {$event['price']} \n Organizer: {$event['organizer']} $tournamentID $confirmationID");
$vCalendar->addComponent($vEvent);
unset($vEvent);
}
echo $vCalendar->render();
https://i.ibb.co/JvYhbV4/6520-E98-A-FA3-A-455-D-8275-3-EA801-C7-B9-CE.png
https://i.ibb.co/LzVF2jd/FD5-B9-D2-F-C22-D-4419-B76-B-7-E353-A0-DDF04.png
https://i.ibb.co/4mMBzrq/D4998679-88-E2-4670-A8-F2-D17-BF73-E2-E07.png
https://i.ibb.co/cQjqfDw/C442-D598-1-E72-4239-8093-DE9-D89770-C51.png
from notion.client import NotionClient
import json
# Obtain the `token_v2` value by inspecting your browser cookies on a logged-in session on Notion.so
client = NotionClient(token_v2="you can't have it")
cv = client.get_collection_view("https://www.notion.so/32d5cb7a9b114ffba03f518085f0833c?v=b98caaf68e35433380e2e6bcd6a6ba77")
output = {}
rows = cv.default_query().execute();
for i in range(len(rows)):
output[i] = {
'name': rows[i].name,
'type': rows[i].tags[0],
'tournamentID': str(rows[i].tournament_id),
'confirmationID': str(rows[i].confirmation_id),
'url': rows[i].link,
'price': "$" + str(rows[i].price),
'organizer': rows[i].organizer,
'location': rows[i].location,
'drawsPosted': str(rows[i].draws_posted),
'entriesClose': str(rows[i].entries_close),
'startDate': str(rows[i].date.start),
'endDate': str(rows[i].date.end)
}
print(json.dumps(output))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment