Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalex committed Feb 5, 2021
1 parent d24d2c8 commit 3533c01
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 38 deletions.
6 changes: 2 additions & 4 deletions notion/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,7 @@ def get_backlinks(self):
"""
Returns a list of blocks that referencing the current PageBlock. Note that only PageBlocks support backlinks.
"""
data = self._client.post(
"getBacklinksForBlock",
{"blockId": self.id},
).json()
data = self._client.post("getBacklinksForBlock", {"blockId": self.id}).json()
backlinks = []
for block in data.get("backlinks") or []:
mention = block.get("mentioned_from")
Expand All @@ -560,6 +557,7 @@ def get_backlinks(self):
backlinks.append(self._client.get_block(block_id))
return backlinks


class BulletedListBlock(BasicBlock):

_type = "bulleted_list"
Expand Down
16 changes: 12 additions & 4 deletions notion/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ def create_session(client_specified_retry=None):
backoff_factor=0.3,
status_forcelist=(502, 503, 504),
# CAUTION: adding 'POST' to this list which is not technically idempotent
method_whitelist=("POST", "HEAD", "TRACE", "GET", "PUT", "OPTIONS", "DELETE"),
method_whitelist=(
"POST",
"HEAD",
"TRACE",
"GET",
"PUT",
"OPTIONS",
"DELETE",
),
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("https://", adapter)
Expand Down Expand Up @@ -91,10 +99,10 @@ def start_monitoring(self):

def _set_token(self, email=None, password=None):
if not email:
email = input(f'Enter Your Notion Email\n')
email = input("Enter your Notion email address:\n")
if not password:
password = getpass(f'Enter Your Notion Password\n')
self.post("loginWithEmail", {"email":email,"password":password}).json()
password = getpass("Enter your Notion password:\n")
self.post("loginWithEmail", {"email": email, "password": password}).json()

def _update_user_info(self):
records = self.post("loadUserContent", {}).json()["recordMap"]
Expand Down
49 changes: 35 additions & 14 deletions notion/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from .markdown import markdown_to_notion, notion_to_markdown
from .operations import build_operation
from .records import Record
from .utils import add_signed_prefix_as_needed, extract_id, remove_signed_prefix_as_needed, slugify
from .utils import (
add_signed_prefix_as_needed,
extract_id,
remove_signed_prefix_as_needed,
slugify,
)


class NotionDate(object):
Expand Down Expand Up @@ -97,8 +102,18 @@ def to_notion(self):


class NotionSelect(object):
valid_colors = ["default", "gray", "brown", "orange", "yellow",
"green", "blue", "purple", "pink", "red"]
valid_colors = [
"default",
"gray",
"brown",
"orange",
"yellow",
"green",
"blue",
"purple",
"pink",
"red",
]
id = None
color = "default"
value = None
Expand All @@ -116,11 +131,7 @@ def set_color(self, color):
return color

def to_dict(self):
return {
"id": self.id,
"value": self.value,
"color": self.color
}
return {"id": self.id, "value": self.value, "color": self.color}


class Collection(Record):
Expand Down Expand Up @@ -320,7 +331,9 @@ def _normalize_query_data(data, collection, recursing=False):
if not recursing:
data = deepcopy(data)
if isinstance(data, list):
return [_normalize_query_data(item, collection, recursing=True) for item in data]
return [
_normalize_query_data(item, collection, recursing=True) for item in data
]
elif isinstance(data, dict):
# convert slugs to property ids
if "property" in data:
Expand Down Expand Up @@ -348,7 +361,9 @@ def __init__(
calendar_by="",
group_by="",
):
assert not (aggregate and aggregations), "Use only one of `aggregate` or `aggregations` (old vs new format)"
assert not (
aggregate and aggregations
), "Use only one of `aggregate` or `aggregations` (old vs new format)"
self.collection = collection
self.collection_view = collection_view
self.search = search
Expand Down Expand Up @@ -379,7 +394,7 @@ def execute(self):
calendar_by=self.calendar_by,
group_by=self.group_by,
),
self
self,
)


Expand Down Expand Up @@ -497,7 +512,9 @@ def _convert_notion_to_python(self, val, prop):
if prop["type"] in ["file"]:
val = (
[
add_signed_prefix_as_needed(item[1][0][1], client=self._client, id=self.id)
add_signed_prefix_as_needed(
item[1][0][1], client=self._client, id=self.id
)
for item in val
if item[0] != ","
]
Expand Down Expand Up @@ -542,7 +559,9 @@ def set_property(self, identifier, val):
if prop["type"] in ["select"] or prop["type"] in ["multi_select"]:
schema_update, prop = self.collection.check_schema_select_options(prop, val)
if schema_update:
self.collection.set("schema.{}.options".format(prop["id"]), prop["options"])
self.collection.set(
"schema.{}.options".format(prop["id"]), prop["options"]
)

path, val = self._convert_python_to_notion(val, prop, identifier=identifier)

Expand Down Expand Up @@ -686,7 +705,9 @@ def __init__(self, collection, result, query):
self._client = collection._client
self._block_ids = self._get_block_ids(result)
self.aggregates = result.get("aggregationResults", [])
self.aggregate_ids = [agg.get("id") for agg in (query.aggregate or query.aggregations)]
self.aggregate_ids = [
agg.get("id") for agg in (query.aggregate or query.aggregations)
]
self.query = query

def _get_block_ids(self, result):
Expand Down
7 changes: 6 additions & 1 deletion notion/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
def enable_debugging():
set_log_level(logging.DEBUG)


def set_log_level(level):
logger.setLevel(level)
handler.setLevel(level)
Expand All @@ -35,4 +36,8 @@ def set_log_level(level):
elif NOTIONPY_LOG_LEVEL == "error":
set_log_level(logging.ERROR)
else:
raise Exception("Invalid value for environment variable NOTIONPY_LOG_LEVEL: {}".format(NOTIONPY_LOG_LEVEL))
raise Exception(
"Invalid value for environment variable NOTIONPY_LOG_LEVEL: {}".format(
NOTIONPY_LOG_LEVEL
)
)
36 changes: 22 additions & 14 deletions notion/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def run_live_smoke_test(token_v2, parent_page_url_or_id):
col1kid = col1.children.add_new(
TextBlock, title="Some formatting: *italic*, **bold**, ***both***!"
)
assert col1kid.title.replace("_", "*") == "Some formatting: *italic*, **bold**, ***both***!"
assert (
col1kid.title.replace("_", "*")
== "Some formatting: *italic*, **bold**, ***both***!"
)
assert col1kid.title_plaintext == "Some formatting: italic, bold, both!"
col2.children.add_new(TodoBlock, title="I should be unchecked")
col2.children.add_new(TodoBlock, title="I should be checked", checked=True)
Expand Down Expand Up @@ -112,7 +115,7 @@ def run_live_smoke_test(token_v2, parent_page_url_or_id):
start = datetime.strptime("2020-01-01 09:30", "%Y-%m-%d %H:%M")
end = datetime.strptime("2020-01-05 20:45", "%Y-%m-%d %H:%M")
timezone = "America/Los_Angeles"
reminder= {'unit': 'minute', 'value': 30}
reminder = {"unit": "minute", "value": 30}
row1.some_date = NotionDate(start, end=end, timezone=timezone, reminder=reminder)

# add another row
Expand All @@ -134,7 +137,10 @@ def run_live_smoke_test(token_v2, parent_page_url_or_id):

# check that existing options "A" haven't been affected
for prop in ["=d{|", "=d{q"]:
assert cvb.collection.get("schema.{}.options.0.id".format(prop)) == get_collection_schema()[prop]["options"][0]["id"]
assert (
cvb.collection.get("schema.{}.options.0.id".format(prop))
== get_collection_schema()[prop]["options"][0]["id"]
)

# Run a filtered/sorted query using the view's default parameters
result = view.default_query().execute()
Expand Down Expand Up @@ -163,17 +169,19 @@ def run_live_smoke_test(token_v2, parent_page_url_or_id):

# Run a "filtered" query
filter_params = {
"filters": [{
"filter": {
"value": {
"type": "exact",
"value": {"table": "notion_user", "id": client.current_user.id}
"filters": [
{
"filter": {
"value": {
"type": "exact",
"value": {"table": "notion_user", "id": client.current_user.id},
},
"operator": "person_does_not_contain",
},
"operator": "person_does_not_contain"
},
"property": "person"
}],
"operator": "and"
"property": "person",
}
],
"operator": "and",
}
result = view.build_query(filter=filter_params).execute()
assert row1 in result
Expand Down Expand Up @@ -267,7 +275,7 @@ def get_collection_schema():
"LL[(": {"name": "Person", "type": "person"},
"4Jv$": {"name": "Estimated value", "type": "number"},
"OBcJ": {"name": "Where to?", "type": "url"},
"TwR:": {"name": "Some Date", "type": "date"},
"TwR:": {"name": "Some Date", "type": "date"},
"dV$q": {"name": "Files", "type": "file"},
"title": {"name": "Name", "type": "title"},
}
4 changes: 3 additions & 1 deletion notion/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ def call_query_collection(
group_by="",
):

assert not (aggregate and aggregations), "Use only one of `aggregate` or `aggregations` (old vs new format)"
assert not (
aggregate and aggregations
), "Use only one of `aggregate` or `aggregations` (old vs new format)"

# convert singletons into lists if needed
if isinstance(aggregate, dict):
Expand Down

0 comments on commit 3533c01

Please sign in to comment.