Move graphql_to_page -> Page._from_graphql
This commit is contained in:
@@ -746,7 +746,7 @@ class Client(object):
|
|||||||
GraphQL(query=GraphQL.SEARCH_PAGE, params={"search": name, "limit": limit})
|
GraphQL(query=GraphQL.SEARCH_PAGE, params={"search": name, "limit": limit})
|
||||||
)
|
)
|
||||||
|
|
||||||
return [graphql_to_page(node) for node in j[name]["pages"]["nodes"]]
|
return [Page._from_graphql(node) for node in j[name]["pages"]["nodes"]]
|
||||||
|
|
||||||
def searchForGroups(self, name, limit=10):
|
def searchForGroups(self, name, limit=10):
|
||||||
"""
|
"""
|
||||||
@@ -790,7 +790,7 @@ class Client(object):
|
|||||||
# MessageThread => Group thread
|
# MessageThread => Group thread
|
||||||
rtn.append(Group._from_graphql(node))
|
rtn.append(Group._from_graphql(node))
|
||||||
elif node["__typename"] == "Page":
|
elif node["__typename"] == "Page":
|
||||||
rtn.append(graphql_to_page(node))
|
rtn.append(Page._from_graphql(node))
|
||||||
elif node["__typename"] == "Group":
|
elif node["__typename"] == "Group":
|
||||||
# We don't handle Facebook "Groups"
|
# We don't handle Facebook "Groups"
|
||||||
pass
|
pass
|
||||||
@@ -1058,7 +1058,7 @@ class Client(object):
|
|||||||
if entry["type"] == ThreadType.USER:
|
if entry["type"] == ThreadType.USER:
|
||||||
rtn[_id] = User._from_graphql(entry)
|
rtn[_id] = User._from_graphql(entry)
|
||||||
else:
|
else:
|
||||||
rtn[_id] = graphql_to_page(entry)
|
rtn[_id] = Page._from_graphql(entry)
|
||||||
else:
|
else:
|
||||||
raise FBchatException(
|
raise FBchatException(
|
||||||
"{} had an unknown thread type: {}".format(thread_ids[i], entry)
|
"{} had an unknown thread type: {}".format(thread_ids[i], entry)
|
||||||
|
@@ -159,27 +159,6 @@ def graphql_to_thread(thread):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def graphql_to_page(page):
|
|
||||||
if page.get("profile_picture") is None:
|
|
||||||
page["profile_picture"] = {}
|
|
||||||
if page.get("city") is None:
|
|
||||||
page["city"] = {}
|
|
||||||
plan = None
|
|
||||||
if page.get("event_reminders") and page["event_reminders"].get("nodes"):
|
|
||||||
plan = Plan._from_graphql(page["event_reminders"]["nodes"][0])
|
|
||||||
|
|
||||||
return Page(
|
|
||||||
page["id"],
|
|
||||||
url=page.get("url"),
|
|
||||||
city=page.get("city").get("name"),
|
|
||||||
category=page.get("category_type"),
|
|
||||||
photo=page["profile_picture"].get("uri"),
|
|
||||||
name=page.get("name"),
|
|
||||||
message_count=page.get("messages_count"),
|
|
||||||
plan=plan,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def graphql_queries_to_json(*queries):
|
def graphql_queries_to_json(*queries):
|
||||||
"""
|
"""
|
||||||
Queries should be a list of GraphQL objects
|
Queries should be a list of GraphQL objects
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
from . import _plan
|
||||||
from ._thread import ThreadType, Thread
|
from ._thread import ThreadType, Thread
|
||||||
|
|
||||||
|
|
||||||
@@ -36,3 +37,24 @@ class Page(Thread):
|
|||||||
self.likes = likes
|
self.likes = likes
|
||||||
self.sub_title = sub_title
|
self.sub_title = sub_title
|
||||||
self.category = category
|
self.category = category
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _from_graphql(cls, data):
|
||||||
|
if data.get("profile_picture") is None:
|
||||||
|
data["profile_picture"] = {}
|
||||||
|
if data.get("city") is None:
|
||||||
|
data["city"] = {}
|
||||||
|
plan = None
|
||||||
|
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
||||||
|
plan = _plan.Plan._from_graphql(data["event_reminders"]["nodes"][0])
|
||||||
|
|
||||||
|
return cls(
|
||||||
|
data["id"],
|
||||||
|
url=data.get("url"),
|
||||||
|
city=data.get("city").get("name"),
|
||||||
|
category=data.get("category_type"),
|
||||||
|
photo=data["profile_picture"].get("uri"),
|
||||||
|
name=data.get("name"),
|
||||||
|
message_count=data.get("messages_count"),
|
||||||
|
plan=plan,
|
||||||
|
)
|
||||||
|
@@ -14,7 +14,6 @@ from ._graphql import (
|
|||||||
graphql_to_quick_reply,
|
graphql_to_quick_reply,
|
||||||
graphql_to_message,
|
graphql_to_message,
|
||||||
graphql_to_thread,
|
graphql_to_thread,
|
||||||
graphql_to_page,
|
|
||||||
graphql_queries_to_json,
|
graphql_queries_to_json,
|
||||||
graphql_response_to_json,
|
graphql_response_to_json,
|
||||||
GraphQL,
|
GraphQL,
|
||||||
|
Reference in New Issue
Block a user