mirror of
https://github.com/Rushilwiz/tj2023.git
synced 2025-04-20 12:00:17 -04:00
commit
55beede1b5
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,6 +2,9 @@ led / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
secrets.py
|
||||||
|
static_files
|
||||||
|
.idea/
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|
|
@ -11,8 +11,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
from my_secrets.secrets import *
|
||||||
from my_secrets import secrets
|
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
@ -21,9 +20,6 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
|
||||||
SECRET_KEY = secrets.SECRET_KEY
|
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
|
@ -34,6 +30,7 @@ ALLOWED_HOSTS = []
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'pages',
|
'pages',
|
||||||
|
'notes',
|
||||||
|
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
|
@ -61,7 +58,7 @@ ROOT_URLCONF = 'config.urls'
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [BASE_DIR / 'templates', BASE_DIR / 'notion_updater/templates'],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
|
@ -125,4 +122,7 @@ USE_TZ = True
|
||||||
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
# https://docs.djangoproject.com/en/3.1/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/static/'
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
|
||||||
|
import os
|
||||||
|
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
|
||||||
|
STATICFILES_DIRS = [BASE_DIR / "static"]
|
|
@ -16,10 +16,8 @@ Including another URLconf
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.conf.urls.static import static
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('notes/', include('notes.urls')),
|
||||||
path('', include('pages.urls'))
|
path('', include('pages.urls'))
|
||||||
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
]
|
||||||
|
|
|
@ -8,4 +8,6 @@
|
||||||
SECRET_KEYS = [
|
SECRET_KEYS = [
|
||||||
# start with your Django secret key like this:
|
# start with your Django secret key like this:
|
||||||
"SECRET_KEY",
|
"SECRET_KEY",
|
||||||
|
"NOTION_URL",
|
||||||
|
"NOTION_COOKIE",
|
||||||
]
|
]
|
||||||
|
|
11
my_secrets/secrets.py.sample.py
Normal file
11
my_secrets/secrets.py.sample.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Django
|
||||||
|
SECRET_KEY = "" # Add your django secret key
|
||||||
|
|
||||||
|
# Notion Client
|
||||||
|
NOTION_URL = "" # Add the notion url manually
|
||||||
|
NOTION_COOKIE = "" # Follow the steps listed below
|
||||||
|
|
||||||
|
# 1. Login to notion and navigate to the home page of your page. (Not in Guest or Incognito)
|
||||||
|
# 2. Open up developer tools by pressing Ctrl + Shift + i, and navigate to the application tab
|
||||||
|
# 3. Click on the cookie dropdown and click on the single cookie that is located there.
|
||||||
|
# 4. Copy the token_v2 info and paste it into NOTION_COOKIE
|
5
notes/admin.py
Normal file
5
notes/admin.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import NotionPage
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
admin.site.register(NotionPage)
|
5
notes/apps.py
Normal file
5
notes/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class NotesConfig(AppConfig):
|
||||||
|
name = 'notes'
|
19
notes/models.py
Normal file
19
notes/models.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
|
from notion.client import NotionClient
|
||||||
|
|
||||||
|
client = NotionClient(token_v2=settings.NOTION_COOKIE)
|
||||||
|
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
class NotionPage(models.Model):
|
||||||
|
url = models.URLField(max_length=300)
|
||||||
|
page = None
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(NotionPage, self).__init__(*args, **kwargs)
|
||||||
|
if self.url:
|
||||||
|
self.page = client.get_block(self.url)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.page and self.page.title)
|
4
notes/static/notes/css/base.css
Normal file
4
notes/static/notes/css/base.css
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
.content {
|
||||||
|
padding: 15px;
|
||||||
|
margin: 10px;
|
||||||
|
}
|
30
notes/static/notes/css/meeting.css
Normal file
30
notes/static/notes/css/meeting.css
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Lemonada&display=swap');
|
||||||
|
h2 {
|
||||||
|
font-size: 40px;
|
||||||
|
margin-top: 10px;
|
||||||
|
text-align: center;
|
||||||
|
font-family: 'Lemonada', cursive;
|
||||||
|
}
|
||||||
|
.BulletedListBlock {
|
||||||
|
}
|
||||||
|
.TodoBlock {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.SubheaderBlock {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0px;
|
||||||
|
margin: 0px;
|
||||||
|
font-size: 30px;
|
||||||
|
margin-top: 5px;
|
||||||
|
font-family: 'Lemonada', cursive;
|
||||||
|
}
|
||||||
|
.SubsubheaderBlock {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0px;
|
||||||
|
margin: 0px;
|
||||||
|
font-size: 30px;
|
||||||
|
margin-top: 5px;
|
||||||
|
font-family: 'Lemonada', cursive;
|
||||||
|
}
|
||||||
|
.TextBlock {
|
||||||
|
}
|
18
notes/templates/notes/base.html
Normal file
18
notes/templates/notes/base.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>TJ 2023 - {% block title %}{% endblock title %}</title>
|
||||||
|
<link rel="stylesheet" href="{% static 'css/base.css' %}">
|
||||||
|
{% block css %}{% endblock css %}
|
||||||
|
{% block js %}{% endblock js %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="content">
|
||||||
|
{% block body %}
|
||||||
|
|
||||||
|
{% endblock body %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
8
notes/templates/notes/meeting.html
Normal file
8
notes/templates/notes/meeting.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{% extends 'notion/base.html' %}
|
||||||
|
{% load static %}
|
||||||
|
{% block css %}
|
||||||
|
<link rel="stylesheet" href="{% static 'css/meeting.css' %}">
|
||||||
|
{% endblock css %}
|
||||||
|
{% block body %}
|
||||||
|
{{ html|safe }}
|
||||||
|
{% endblock body %}
|
13
notes/templates/notes/test.html
Normal file
13
notes/templates/notes/test.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Test</title>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="notes">
|
||||||
|
{{ html|safe }}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
3
notes/tests.py
Normal file
3
notes/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
7
notes/urls.py
Normal file
7
notes/urls.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from django.urls import path
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.test),
|
||||||
|
path('meeting/<str:meeting_id>/', views.show_meeting, name='show_meetings'),
|
||||||
|
]
|
81
notes/views.py
Normal file
81
notes/views.py
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
from .models import NotionPage
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
def test(request):
|
||||||
|
html = ''
|
||||||
|
|
||||||
|
page = NotionPage.objects.get(url=settings.NOTION_URL).page
|
||||||
|
|
||||||
|
meeting_block = None
|
||||||
|
for block in page.children:
|
||||||
|
if block.id == '383b2866-a0ae-4f4e-b246-4131117721c0':
|
||||||
|
meeting_block = block.collection
|
||||||
|
break
|
||||||
|
|
||||||
|
for meeting in meeting_block.get_rows():
|
||||||
|
html += f'<h4><a href="/notes/meeting/{meeting.id}">{meeting.title}</a></h4>'
|
||||||
|
|
||||||
|
html += '<hr>'
|
||||||
|
return render(request, 'notes/test.html', {'html': html})
|
||||||
|
|
||||||
|
|
||||||
|
def has_children(block):
|
||||||
|
try:
|
||||||
|
block.children
|
||||||
|
return True
|
||||||
|
except AttributeError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def pprint(dicti):
|
||||||
|
print('{')
|
||||||
|
for k in dicti.keys():
|
||||||
|
print(f'\t{k.title} : {dicti[k]}')
|
||||||
|
print('}')
|
||||||
|
|
||||||
|
|
||||||
|
def getHtml(html_dict, meeting_dict, node):
|
||||||
|
string = html_dict[node]
|
||||||
|
temp = ''
|
||||||
|
for child in meeting_dict.get(node, {}):
|
||||||
|
temp += getHtml(html_dict, meeting_dict, child)
|
||||||
|
return string.format(temp)
|
||||||
|
|
||||||
|
|
||||||
|
def show_meeting(request, meeting_id):
|
||||||
|
|
||||||
|
page = NotionPage.objects.get(url=settings.NOTION_URL).page
|
||||||
|
|
||||||
|
meeting = None
|
||||||
|
for block in page.children:
|
||||||
|
if block.id == '383b2866-a0ae-4f4e-b246-4131117721c0':
|
||||||
|
for row in block.collection.get_rows():
|
||||||
|
if row.id == meeting_id:
|
||||||
|
meeting = row
|
||||||
|
break
|
||||||
|
|
||||||
|
meeting_dict = dict()
|
||||||
|
html_dict = {meeting: '<h2>' + meeting.title.strip() + '</h2><ul>{}</ul>'}
|
||||||
|
|
||||||
|
q = [meeting]
|
||||||
|
|
||||||
|
while q and has_children(temp := q.pop(0)):
|
||||||
|
for children in temp.children:
|
||||||
|
|
||||||
|
if children.parent in meeting_dict.keys():
|
||||||
|
meeting_dict[children.parent].append(children)
|
||||||
|
else:
|
||||||
|
meeting_dict[children.parent] = [children]
|
||||||
|
|
||||||
|
q.append(children)
|
||||||
|
|
||||||
|
block_type = str(type(children)).replace('<class', '').replace('>', '').replace('notion.block.', '').replace("'", "").strip()
|
||||||
|
html_dict[children] = "<li class='" + block_type + "'>" + children.title.strip() + "<ul>{}</ul></li>"
|
||||||
|
|
||||||
|
html = getHtml(html_dict, meeting_dict, meeting)
|
||||||
|
print(html)
|
||||||
|
|
||||||
|
return render(request, "notes/meeting.html", {'html': html})
|
|
@ -1,8 +1,23 @@
|
||||||
asgiref==3.2.10
|
asgiref==3.2.10
|
||||||
|
beautifulsoup4==4.9.3
|
||||||
|
bs4==0.0.1
|
||||||
|
cached-property==1.5.2
|
||||||
|
certifi==2020.6.20
|
||||||
|
chardet==3.0.4
|
||||||
|
commonmark==0.9.1
|
||||||
|
dictdiffer==0.8.1
|
||||||
Django==3.1.2
|
Django==3.1.2
|
||||||
django-extensions==3.0.9
|
django-extensions==3.0.9
|
||||||
django-secrets==1.0.2
|
django-secrets==1.0.2
|
||||||
future==0.18.2
|
future==0.18.2
|
||||||
|
idna==2.10
|
||||||
|
notion==0.0.25
|
||||||
|
python-slugify==4.0.1
|
||||||
pytz==2020.1
|
pytz==2020.1
|
||||||
|
requests==2.24.0
|
||||||
six==1.15.0
|
six==1.15.0
|
||||||
|
soupsieve==2.0.1
|
||||||
sqlparse==0.4.1
|
sqlparse==0.4.1
|
||||||
|
text-unidecode==1.3
|
||||||
|
tzlocal==2.1
|
||||||
|
urllib3==1.25.11
|
||||||
|
|
Loading…
Reference in New Issue
Block a user