Skip to content

Commit

Permalink
feat: add import from text data (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: Pablo <pjestradac@gmail.com>
  • Loading branch information
PJEstrada and PJEstrada committed May 10, 2023
1 parent 19952d9 commit 6000f1a
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion sdk/diffgram/file/file_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __build_packet_payload(self,
file_name: str = None,
blob_path: str = None,
parent_file_id: int = None,
text_data: str = None,
ordinal: int = 0):
packet = {'media': {}}
packet['media']['url'] = url
Expand All @@ -119,6 +120,7 @@ def __build_packet_payload(self,
# Existing Instances
packet['frame_packet_map'] = frame_packet_map
packet['ordinal'] = ordinal
packet['text_data'] = text_data
packet['type'] = type
packet['connection_id'] = connection_id
packet['parent_file_id'] = parent_file_id
Expand Down Expand Up @@ -173,12 +175,50 @@ def from_blob_path(self,
file_name = name,
directory_id = directory_id,
type = "from_blob_path",
parent_file_id=parent_file_id,
parent_file_id = parent_file_id,
ordinal = ordinal
)
self.from_packet(packet = packet)
return True

def from_text_data(self,
file_name: str,
text_data: str,
media_type: str = 'text',
instance_list: list = None,
frame_packet_map: dict = None,
parent_file_id: int = None,
directory_id: int = None,
ordinal: int = 0):
"""
Add the given text as a text File in Diffgram
:param text_data: the raw text to create the text file from.
:param media_type:
:param instance_list:
:param frame_packet_map:
:param parent_file_id: the parent file ID (for compound files)
:param ordinal: the ordinal for the child file (for compound files)
:return:
"""
if self.client.default_directory is None and directory_id is None:
raise Exception("Directory not set. call set_default_directory() to set upload directory.")
if directory_id is None:
directory_id = self.client.directory_id
name = file_name
packet = self.__build_packet_payload(
media_type = media_type,
instance_list = instance_list,
frame_packet_map = frame_packet_map,
file_name = name,
directory_id = directory_id,
type = "from_text_data",
parent_file_id = parent_file_id,
ordinal = ordinal,
text_data = text_data
)
self.from_packet(packet = packet)
return True

def from_url(
self,
url: str,
Expand Down

0 comments on commit 6000f1a

Please sign in to comment.