Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
replace_property_keys
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
suraksha.pv
replace_property_keys
Commits
8a1aeb46
Commit
8a1aeb46
authored
Aug 02, 2023
by
suraksha.pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace keys
parent
18f3c1c0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
35 deletions
+42
-35
replace_mongo_properties.py
replace_mongo_properties.py
+42
-35
No files found.
replace_mongo_properties.py
View file @
8a1aeb46
import
json
from
pymongo
import
MongoClient
input_json_file_name
=
'input_json.json'
MONGO_URI
=
"mongodb://ilens:ilens4321@192.168.0.220:2717/"
database_ilens_assistant
=
"ilens_assistant"
database_ilens_configuration
=
"ilens_configuration"
input_json_file_name
=
'input_json.json'
# input_json_file
input_project_id
=
"project_099"
input_logbook_id
=
"logbook_131"
input_step_id
=
'step_182'
input_logbook_id
=
[
"logbook_131"
]
input_step_id
=
[
'step_182'
]
step_type
=
"NON-PERIODIC"
# NON-PERIODIC,PERIODIC
CONNECTION_STRING
=
"mongodb://ilens:ilens4321@192.168.0.220:2717/"
CONNECTION_STRING
=
MONGO_URI
client
=
MongoClient
(
CONNECTION_STRING
)
# add correct database names below
ilens_assistant
=
client
[
"ilens_assistant"
]
ilens_configuration
=
client
[
"ilens_configuration"
]
ilens_assistant
=
client
[
database_ilens_assistant
]
ilens_configuration
=
client
[
database_ilens_configuration
]
task_instances
=
ilens_assistant
[
'task_instances'
]
task_instance_data
=
ilens_assistant
[
'task_instance_data'
]
periodic_data
=
ilens_configuration
[
'periodic_data'
]
# ---------------------------code execution---------------------------------------#
with
open
(
input_json_file_name
)
as
user_file
:
input_json
=
user_file
.
read
()
input_dict
=
json
.
loads
(
input_json
)
...
...
@@ -37,6 +42,7 @@ def replace_keys(data, replacements):
if
step_type
==
'NON-PERIODIC'
:
for
logbook_id
in
input_logbook_id
:
query
=
{
"logbook_id"
:
input_logbook_id
,
"project_id"
:
input_project_id
}
data
=
[]
if
logbook_data
:
=
list
(
ilens_assistant
.
task_instances
.
find
(
query
)):
...
...
@@ -51,12 +57,13 @@ if step_type == 'NON-PERIODIC':
updated_y
.
append
(
item
)
for
item
in
updated_y
:
if
item
[
'task_id'
]
in
data
:
update_query
=
{
"task_id"
:
item
[
'task_id'
],
"step_id"
:
input_step_id
,
"project_id"
:
input_project_id
}
update_query
=
{
"task_id"
:
item
[
'task_id'
],
"step_id"
:
input_step_id
,
"project_id"
:
input_project_id
}
ilens_assistant
.
task_instance_data
.
update_one
(
update_query
,
{
"$set"
:
item
})
elif
step_type
==
"PERIODIC"
:
query
=
{
"step_id"
:
input_
step_id
}
for
step_id
in
input_step_id
:
query
=
{
"step_id"
:
step_id
}
periodic_step_data
=
list
(
ilens_assistant
.
periodic_data
.
find
(
query
))
updated_y
=
[]
if
periodic_step_data
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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