graphql - Event to Plan
This commit is contained in:
committed by
GitHub
parent
aed75c7d1b
commit
49b213bb2d
@@ -148,30 +148,31 @@ def graphql_to_poll_option(a):
|
|||||||
rtn.votes_count = a.get('voters').get('count') if isinstance(a.get('voters'), dict) else a.get('total_count')
|
rtn.votes_count = a.get('voters').get('count') if isinstance(a.get('voters'), dict) else a.get('total_count')
|
||||||
return rtn
|
return rtn
|
||||||
|
|
||||||
def graphql_to_event(a):
|
def graphql_to_plan(a):
|
||||||
if a.get('event_members') is not None:
|
if a.get('event_members'):
|
||||||
rtn = Event(
|
rtn = Plan(
|
||||||
time=a.get('event_time'),
|
time=a.get('event_time'),
|
||||||
title=a.get('title'),
|
title=a.get('title'),
|
||||||
location=a.get('location_name')
|
location=a.get('location_name')
|
||||||
)
|
)
|
||||||
if a.get('location_id') != 0:
|
if a.get('location_id') != 0:
|
||||||
rtn.location_id = str(a.get('location_id'))
|
rtn.location_id = str(a.get('location_id'))
|
||||||
rtn.creator_id = a.get('creator_id')
|
rtn.uid = a.get('oid')
|
||||||
|
rtn.author_id = a.get('creator_id')
|
||||||
guests = a.get("event_members")
|
guests = a.get("event_members")
|
||||||
rtn.going = [uid for uid in guests if guests[uid] == "GOING"]
|
rtn.going = [uid for uid in guests if guests[uid] == "GOING"]
|
||||||
rtn.declined = [uid for uid in guests if guests[uid] == "DECLINED"]
|
rtn.declined = [uid for uid in guests if guests[uid] == "DECLINED"]
|
||||||
rtn.invited = [uid for uid in guests if guests[uid] == "INVITED"]
|
rtn.invited = [uid for uid in guests if guests[uid] == "INVITED"]
|
||||||
return rtn
|
return rtn
|
||||||
elif a.get('id') is None:
|
elif a.get('id') is None:
|
||||||
rtn = Event(
|
rtn = Plan(
|
||||||
time=a.get('event_time'),
|
time=a.get('event_time'),
|
||||||
title=a.get('event_title'),
|
title=a.get('event_title'),
|
||||||
location=a.get('event_location_name'),
|
location=a.get('event_location_name'),
|
||||||
location_id=a.get('event_location_id')
|
location_id=a.get('event_location_id')
|
||||||
)
|
)
|
||||||
rtn.uid = a.get('event_id')
|
rtn.uid = a.get('event_id')
|
||||||
rtn.creator_id = a.get('event_creator_id')
|
rtn.author_id = a.get('event_creator_id')
|
||||||
guests = ast.literal_eval(a.get('guest_state_list'))
|
guests = ast.literal_eval(a.get('guest_state_list'))
|
||||||
else:
|
else:
|
||||||
rtn = Event(
|
rtn = Event(
|
||||||
@@ -180,7 +181,7 @@ def graphql_to_event(a):
|
|||||||
location=a.get('location_name')
|
location=a.get('location_name')
|
||||||
)
|
)
|
||||||
rtn.uid = a.get('id')
|
rtn.uid = a.get('id')
|
||||||
rtn.creator_id = a.get('lightweight_event_creator').get('id')
|
rtn.author_id = a.get('lightweight_event_creator').get('id')
|
||||||
guests = a.get('event_reminder_members').get('edges')
|
guests = a.get('event_reminder_members').get('edges')
|
||||||
rtn.going = [m.get('node').get('id') for m in guests if m.get('guest_list_state') == "GOING"]
|
rtn.going = [m.get('node').get('id') for m in guests if m.get('guest_list_state') == "GOING"]
|
||||||
rtn.declined = [m.get('node').get('id') for m in guests if m.get('guest_list_state') == "DECLINED"]
|
rtn.declined = [m.get('node').get('id') for m in guests if m.get('guest_list_state') == "DECLINED"]
|
||||||
@@ -214,7 +215,7 @@ def graphql_to_user(user):
|
|||||||
if user.get('profile_picture') is None:
|
if user.get('profile_picture') is None:
|
||||||
user['profile_picture'] = {}
|
user['profile_picture'] = {}
|
||||||
c_info = get_customization_info(user)
|
c_info = get_customization_info(user)
|
||||||
event_reminders = [graphql_to_event(event) for event in user['event_reminders']['nodes']] if user.get('event_reminders') is not None else []
|
plan = graphql_to_plan(user['event_reminders']['nodes'][0]) if user.get('event_reminders') else []
|
||||||
return User(
|
return User(
|
||||||
user['id'],
|
user['id'],
|
||||||
url=user.get('url'),
|
url=user.get('url'),
|
||||||
@@ -230,7 +231,7 @@ def graphql_to_user(user):
|
|||||||
photo=user['profile_picture'].get('uri'),
|
photo=user['profile_picture'].get('uri'),
|
||||||
name=user.get('name'),
|
name=user.get('name'),
|
||||||
message_count=user.get('messages_count'),
|
message_count=user.get('messages_count'),
|
||||||
event_reminders=event_reminders
|
plan=plan,
|
||||||
)
|
)
|
||||||
|
|
||||||
def graphql_to_thread(thread):
|
def graphql_to_thread(thread):
|
||||||
@@ -252,7 +253,7 @@ def graphql_to_thread(thread):
|
|||||||
else:
|
else:
|
||||||
last_name = user.get('name').split(first_name, 1).pop().strip()
|
last_name = user.get('name').split(first_name, 1).pop().strip()
|
||||||
|
|
||||||
event_reminders = [graphql_to_event(event) for event in thread['event_reminders']['nodes']] if thread.get('event_reminders') is not None else []
|
plan = graphql_to_plan(thread['event_reminders']['nodes'][0]) if thread.get('event_reminders') else []
|
||||||
|
|
||||||
return User(
|
return User(
|
||||||
user['id'],
|
user['id'],
|
||||||
@@ -270,7 +271,7 @@ def graphql_to_thread(thread):
|
|||||||
photo=user['big_image_src'].get('uri'),
|
photo=user['big_image_src'].get('uri'),
|
||||||
message_count=thread.get('messages_count'),
|
message_count=thread.get('messages_count'),
|
||||||
last_message_timestamp=last_message_timestamp,
|
last_message_timestamp=last_message_timestamp,
|
||||||
event_reminders=event_reminders
|
plan=plan,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise FBchatException('Unknown thread type: {}, with data: {}'.format(thread.get('thread_type'), thread))
|
raise FBchatException('Unknown thread type: {}, with data: {}'.format(thread.get('thread_type'), thread))
|
||||||
@@ -282,7 +283,7 @@ def graphql_to_group(group):
|
|||||||
last_message_timestamp = None
|
last_message_timestamp = None
|
||||||
if 'last_message' in group:
|
if 'last_message' in group:
|
||||||
last_message_timestamp = group['last_message']['nodes'][0]['timestamp_precise']
|
last_message_timestamp = group['last_message']['nodes'][0]['timestamp_precise']
|
||||||
event_reminders = [graphql_to_event(event) for event in group['event_reminders']['nodes']] if group.get('event_reminders') is not None else []
|
plan = graphql_to_plan(group['event_reminders']['nodes'][0]) if group.get('event_reminders') else []
|
||||||
return Group(
|
return Group(
|
||||||
group['thread_key']['thread_fbid'],
|
group['thread_key']['thread_fbid'],
|
||||||
participants=set([node['messaging_actor']['id'] for node in group['all_participants']['nodes']]),
|
participants=set([node['messaging_actor']['id'] for node in group['all_participants']['nodes']]),
|
||||||
@@ -293,14 +294,14 @@ def graphql_to_group(group):
|
|||||||
name=group.get('name'),
|
name=group.get('name'),
|
||||||
message_count=group.get('messages_count'),
|
message_count=group.get('messages_count'),
|
||||||
last_message_timestamp=last_message_timestamp,
|
last_message_timestamp=last_message_timestamp,
|
||||||
event_reminders=event_reminders
|
plan=plan,
|
||||||
)
|
)
|
||||||
|
|
||||||
def graphql_to_room(room):
|
def graphql_to_room(room):
|
||||||
if room.get('image') is None:
|
if room.get('image') is None:
|
||||||
room['image'] = {}
|
room['image'] = {}
|
||||||
c_info = get_customization_info(room)
|
c_info = get_customization_info(room)
|
||||||
event_reminders = [graphql_to_event(event) for event in room['event_reminders']['nodes']] if room.get('event_reminders') is not None else []
|
plan = graphql_to_plan(room['event_reminders']['nodes'][0]) if room.get('event_reminders') else []
|
||||||
return Room(
|
return Room(
|
||||||
room['thread_key']['thread_fbid'],
|
room['thread_key']['thread_fbid'],
|
||||||
participants=set([node['messaging_actor']['id'] for node in room['all_participants']['nodes']]),
|
participants=set([node['messaging_actor']['id'] for node in room['all_participants']['nodes']]),
|
||||||
@@ -315,7 +316,7 @@ def graphql_to_room(room):
|
|||||||
approval_requests = set(node.get('id') for node in room['thread_queue_metadata'].get('approval_requests', {}).get('nodes')),
|
approval_requests = set(node.get('id') for node in room['thread_queue_metadata'].get('approval_requests', {}).get('nodes')),
|
||||||
join_link = room['joinable_mode'].get('link'),
|
join_link = room['joinable_mode'].get('link'),
|
||||||
privacy_mode = bool(room.get('privacy_mode')),
|
privacy_mode = bool(room.get('privacy_mode')),
|
||||||
event_reminders=event_reminders
|
plan=plan,
|
||||||
)
|
)
|
||||||
|
|
||||||
def graphql_to_page(page):
|
def graphql_to_page(page):
|
||||||
@@ -323,7 +324,7 @@ def graphql_to_page(page):
|
|||||||
page['profile_picture'] = {}
|
page['profile_picture'] = {}
|
||||||
if page.get('city') is None:
|
if page.get('city') is None:
|
||||||
page['city'] = {}
|
page['city'] = {}
|
||||||
event_reminders = [graphql_to_event(event) for event in page['event_reminders']['nodes']] if page.get('event_reminders') is not None else []
|
plan = graphql_to_plan(page['event_reminders']['nodes'][0]) if page.get('event_reminders') else []
|
||||||
return Page(
|
return Page(
|
||||||
page['id'],
|
page['id'],
|
||||||
url=page.get('url'),
|
url=page.get('url'),
|
||||||
@@ -332,7 +333,7 @@ def graphql_to_page(page):
|
|||||||
photo=page['profile_picture'].get('uri'),
|
photo=page['profile_picture'].get('uri'),
|
||||||
name=page.get('name'),
|
name=page.get('name'),
|
||||||
message_count=page.get('messages_count'),
|
message_count=page.get('messages_count'),
|
||||||
event_reminders=event_reminders
|
plan=plan,
|
||||||
)
|
)
|
||||||
|
|
||||||
def graphql_queries_to_json(*queries):
|
def graphql_queries_to_json(*queries):
|
||||||
|
Reference in New Issue
Block a user