Re-added count checks to api calls and indented for them. Main forum chat is now using the content check. Attachments is checking application/ should have no changes.

This commit is contained in:
Brett Papineau 2020-04-28 16:08:27 -07:00
parent c352a95952
commit 76eeb4f6bf
1 changed files with 151 additions and 146 deletions

View File

@ -84,7 +84,7 @@ def extract_message_attachments(
if 'image/' in file['type']:
has_image = True
file_extension = '.' + file['type'][6:]
if 'application' in file['type']:
if 'application/' in file['type']:
file_extension = '.' + file['type'][12:]
# zulip expects size, created, name
@ -174,7 +174,7 @@ def create_zulip_topics_and_import_messages(user_map: dict,
zulip_message = build_message(topic_name=main_topic_name,
date_sent=message_time,
message_id=message_id,
content=main_topic_chat['body'][:10000],
content=main_topic_content,
rendered_content=rendered_content,
user_id=user_map[ryver_user_id],
recipient_id=main_topic_recipient_id)
@ -208,7 +208,7 @@ def create_zulip_topics_and_import_messages(user_map: dict,
# The first message is embedded in this object and not available in /posts
post_id = forum_topic['id'] # used below for the rest of the messages
topic_name = forum_topic['subject'][:60]
topic_content = forum_topic['body'] # This cannot be null which is None in json
topic_content = forum_topic['body'] # This can be null which is None in json
if topic_content is not None:
topic_content = topic_content[:10000]
else:
@ -280,6 +280,7 @@ def create_zulip_topics_and_import_messages(user_map: dict,
# Main Topic
raw_tw_main_topic_chats_count = api_call_build_execute('/workrooms(id={})/Chat.History()'.format(tw_id), only_count=True) # Chat.History() is a shortcut for count here
if raw_tw_main_topic_chats_count > 0:
raw_tw_main_topic_chats = api_call_build_execute('/workrooms(id={})/Chat.History()'.format(tw_id), results=raw_tw_main_topic_chats_count, hard_results=True, select_str='from,body,when,attachments', expand='attachments', only_count=False)
# main_topic_name = raw_tw['name'][:60]
main_topic_name = '(no topic)' # Zulip standard for main topic in a stream
@ -326,6 +327,7 @@ def create_zulip_topics_and_import_messages(user_map: dict,
# Topics only exists if this flag is true
if raw_tw['sharePosts'] == True:
raw_tw_topics_count = api_call_build_execute('/workrooms(id={})/Post.Stream()'.format(tw_id), only_count=True)
if raw_tw_topics_count > 0:
raw_tw_topics = api_call_build_execute('/workrooms(id={})/Post.Stream()'.format(tw_id), only_count=False, results=raw_tw_topics_count, hard_results=True, select_str='id,subject,createDate,body,createUser,attachments', expand='attachments')
for tw_topic in raw_tw_topics:
@ -367,6 +369,7 @@ def create_zulip_topics_and_import_messages(user_map: dict,
# Get the rest of the messages
raw_topic_posts_count = api_call_build_execute('/posts(id={})/comments'.format(post_id), only_count=True)
if raw_topic_posts_count > 0:
raw_topic_posts = api_call_build_execute('/posts(id={})/comments'.format(post_id), only_count=False, results=raw_topic_posts_count, select_str='createDate,comment,createUser,attachments', expand='createUser,attachments')
for post in raw_topic_posts:
@ -524,6 +527,7 @@ def create_streams_and_map(timestamp: Any) -> (list, dict, dict, dict, dict, dic
# get the raw forum data,
# !! NOTE the user has to be a participant/member of the forum or workroom/team in order to query these !!
forum_count = api_call_build_execute('/forums', results=0, only_count=True)
if forum_count > 0:
raw_api_forums = api_call_build_execute('/forums', only_count=False, select_str='id,name,description,createDate,members', expand='members', results=forum_count) # results=1
for forum in raw_api_forums:
@ -560,6 +564,7 @@ def create_streams_and_map(timestamp: Any) -> (list, dict, dict, dict, dict, dic
# get the raw team/workroom data,
# !! NOTE the user has to be a participant/member of the forum or workroom/team in order to query these !!
team_workroom_count = api_call_build_execute('/workrooms', only_count=True)
if team_workroom_count > 0:
raw_api_workrooms_teams = api_call_build_execute('/workrooms', only_count=False, select_str='id,description,createDate,name,members', expand='members', results=team_workroom_count) # results=1
for tw in raw_api_workrooms_teams:
if tw['id'] not in teams_workrooms_stream_map: