Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
Sample Dataset
Commits
5586da59
Commit
5586da59
authored
2 years ago
by
Aziz Berkay Yesilyurt
Browse files
Options
Download
Email Patches
Plain Diff
add folder logic
parent
37896465
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
export-sample-database.py
+27
-8
export-sample-database.py
with
27 additions
and
8 deletions
+27
-8
export-sample-database.py
+
27
-
8
View file @
5586da59
...
...
@@ -20,9 +20,7 @@ def make_message(content):
# A better way would be to preassign a timestamp for each message
time
.
sleep
(
0.001
)
return
Message
(
service
=
SERVICE
,
content
=
content
,
dateSent
=
datetime
.
datetime
.
now
()
)
return
Message
(
service
=
SERVICE
,
content
=
content
,
dateSent
=
datetime
.
datetime
.
now
())
def
create_chat
(
...
...
@@ -47,18 +45,39 @@ def create_chat(
items
.
extend
((
make_message
(
msg
)
for
msg
in
messages
))
json_items
=
[
item
.
to_json
()
for
item
in
items
]
return
json
.
dumps
(
json_items
,
indent
=
2
)
return
json
_items
def
main
(
file
:
pathlib
.
Path
):
def
write_json
(
file
,
output_file
):
with
open
(
file
,
"r"
)
as
f
:
data
=
json
.
load
(
f
)
chat_items
=
create_chat
(
messages
=
data
[
"messages"
],
user_names
=
data
[
"user_names"
],
channel_name
=
data
[
"channel_name"
],
)
with
open
(
output_file
,
"w"
)
as
f
:
json
.
dump
(
chat_items
,
f
,
indent
=
2
)
def
main
(
file
:
pathlib
.
Path
=
None
,
folder
:
pathlib
.
Path
=
None
):
"""
Read json from file and create a sample database with two users and a channel.
Args:
file : path to json file
"""
with
open
(
file
,
'r'
)
as
f
:
data
=
json
.
load
(
f
)
return
create_chat
(
messages
=
data
[
'messages'
],
user_names
=
data
[
'user_names'
],
channel_name
=
data
[
'channel_name'
])
file
=
pathlib
.
Path
(
file
)
if
file
else
None
folder
=
pathlib
.
Path
(
folder
)
if
folder
else
None
if
file
is
None
and
folder
is
None
:
raise
RuntimeError
(
"Either file or folder must be specified"
)
output_folder
=
pathlib
.
Path
(
"output"
)
if
file
:
write_json
(
file
,
output_folder
/
file
.
name
)
if
folder
:
for
file
in
folder
.
glob
(
"*.json"
):
write_json
(
file
,
output_folder
/
file
.
name
)
if
__name__
==
"__main__"
:
# Make Python Fire not use a pager when it prints a help text
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets