forked from joaoestevanbarbosa/Data-science
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
903c380
commit ed773a8
Showing
10 changed files
with
697 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from hashlib import new | ||
from notion.client import NotionClient | ||
from notion.block import ColumnBlock, TodoBlock | ||
from rich import inspect | ||
|
||
client = NotionClient(token_v2="02a65af9ae61ae50bc17f3333d251e2580d9fd1293bdc68990a474372a458a56b63b1b2868f47e5b21e947ddc093634ce8442de2390f14bcdc54bbaa0d6d2921fad82538d01c9d78c9931f6daea5") | ||
page = client.get_block("https://www.notion.so/1063a61b0a4548959373f995b008d13e?v=6fba291866984949abf7c2c6e2e85ae1") | ||
|
||
inspect(page, methods=True) | ||
# print(page) | ||
content = page.get() | ||
print(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from notion.client import NotionClient | ||
|
||
client = NotionClient(token_v2="02a65af9ae61ae50bc17f3333d251e2580d9fd1293bdc68990a474372a458a56b63b1b2868f47e5b21e947ddc093634ce8442de2390f14bcdc54bbaa0d6d2921fad82538d01c9d78c9931f6daea5") | ||
|
||
page = client.get_block("https://www.notion.so/1063a61b0a4548959373f995b008d13e?v=6fba291866984949abf7c2c6e2e85ae1") | ||
print("Page title is", page.title) | ||
|
||
page.title = "My connections" | ||
print("New page title is", page.title) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from notion.client import NotionClient | ||
|
||
client = NotionClient(token_v2="02a65af9ae61ae50bc17f3333d251e2580d9fd1293bdc68990a474372a458a56b63b1b2868f47e5b21e947ddc093634ce8442de2390f14bcdc54bbaa0d6d2921fad82538d01c9d78c9931f6daea5") | ||
page = client.get_block("https://www.notion.so/1063a61b0a4548959373f995b008d13e?v=6fba291866984949abf7c2c6e2e85ae1") | ||
|
||
for child in page.children: | ||
print(child.title) | ||
|
||
print("Parent of {} is {}".format(page.id, page.parent.id)) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from eventsourcing.domain import Aggregate, event | ||
from loguru import logger | ||
|
||
class Person(Aggregate): | ||
@event('Created') | ||
def __init__(self): | ||
self.life = [] | ||
|
||
@event("LifeHappened") | ||
def deal_with_life(self, some_event): | ||
self.life.append(some_event) | ||
|
||
@logger.catch | ||
def main(): | ||
ben = Person() | ||
assert ben.life == [] | ||
|
||
ben.deal_with_life('school') | ||
assert ben.life == ['school'] | ||
assert len(ben.collect_events()) == 2 | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from eventsourcing.domain import Aggregate, event | ||
from loguru import logger | ||
|
||
class Person(Aggregate): | ||
@event('Created') | ||
def __init__(self): | ||
self.life = [] | ||
|
||
@event("LifeHappened") | ||
def deal_with_life(self, some_event): | ||
self.life.append(some_event) | ||
|
||
@event("Grow") | ||
def learn_from_life(self, some_event): | ||
self.life.append(some_event) | ||
|
||
@logger.catch | ||
def main(): | ||
ben = Person() | ||
assert ben.life == [] | ||
|
||
ben.deal_with_life('school') | ||
ben.deal_with_life('friend') | ||
ben.learn_from_life('leave_home') | ||
|
||
assert ben.life == ['school', 'friend', 'leave_home'] | ||
events = ben.collect_events() | ||
assert len(events) == 4 | ||
assert type(events[0]).__qualname__ == 'Person.Created' | ||
assert type(events[1]).__qualname__ == 'Person.LifeHappened' | ||
assert type(events[2]).__qualname__ == 'Person.LifeHappened' | ||
assert type(events[3]).__qualname__ == 'Person.Grow' | ||
|
||
|
||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from eventsourcing.application import Application | ||
from eventsourcing.domain import Aggregate, event | ||
from eventsourcing.system import NotificationLogReader | ||
from rich import print | ||
|
||
class Person(Aggregate): | ||
@event('Created') | ||
def __init__(self): | ||
self.life = [] | ||
|
||
@event("LifeHappened") | ||
def deal_with_life(self, some_event): | ||
self.life.append(some_event) | ||
|
||
class Record(Application): | ||
def create_person(self): | ||
person = Person() | ||
self.save(person) | ||
return person.id | ||
|
||
def deal_with_life(self, person_id, some_event): | ||
person = self.repository.get(person_id) | ||
person.deal_with_life(some_event) | ||
self.save(person) | ||
|
||
def view_life(self, person_id): | ||
person = self.repository.get(person_id) | ||
return person.life | ||
|
||
def notification_to_table(record): | ||
return [record.id, record.version, record.created_on, record.modified_on, record.history] | ||
|
||
def main(): | ||
record = Record() | ||
ben = record.create_person() | ||
record.deal_with_life(ben, 'school') | ||
record.deal_with_life(ben, 'friend') | ||
assert record.view_life(ben) == ['school', 'friend'] | ||
|
||
alex = record.create_person() | ||
assert alex != ben | ||
record.deal_with_life(alex, 'girl') | ||
assert record.view_life(alex) == ['girl'] | ||
|
||
# Create event notification | ||
reader = NotificationLogReader(record.log) | ||
notifications = list(reader.read(start=1)) | ||
assert len(notifications) == 5 | ||
print(notifications) | ||
for notification in notifications: | ||
print(notification_to_table(notification)) | ||
|
||
|
||
main() | ||
|
13 changes: 13 additions & 0 deletions
13
python/eventsourcing_examples/non_eventsourcing_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class World(): | ||
def __init__(self): | ||
self.history = [] | ||
|
||
def add_to_history(self, something): | ||
self.history.append(something) | ||
|
||
|
||
world = World() | ||
assert world.history == [] | ||
|
||
world.add_to_history('something') | ||
assert world.history == ['something'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[[], ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6deefa06", | ||
"metadata": {}, | ||
"source": [ | ||
"Question: " | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.1" | ||
}, | ||
"toc": { | ||
"base_numbering": 1, | ||
"nav_menu": {}, | ||
"number_sections": true, | ||
"sideBar": true, | ||
"skip_h1_title": false, | ||
"title_cell": "Table of Contents", | ||
"title_sidebar": "Contents", | ||
"toc_cell": false, | ||
"toc_position": {}, | ||
"toc_section_display": true, | ||
"toc_window_display": false | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |