Skip to content

Commit

Permalink
Fix vm harvester scripts (#3663)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Jan 25, 2024
1 parent a8f28a1 commit 1f2865a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
1 change: 0 additions & 1 deletion bims/serializers/location_site_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class Meta:
'ecosystem_type',
'wetland_name',
'user_wetland_name',
'ecosystem_type'
]


Expand Down
20 changes: 18 additions & 2 deletions scripts/management/commands/import_all_frog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Command(BaseCommand):
"""
Import all odonata data
Import all frog data
"""

def add_arguments(self, parser):
Expand Down Expand Up @@ -38,6 +38,13 @@ def add_arguments(self, parser):
default='0',
help='Start index'
)
parser.add_argument(
'-m',
'--module-name',
dest='module_name',
default='Anura',
help='Module name'
)

def handle(self, *args, **options):
api_token = options.get('token', '')
Expand Down Expand Up @@ -71,9 +78,18 @@ def handle(self, *args, **options):
f"Fetching {start_index},{limit} of {total_records} - "
f"{datetime.today()}\n"
)
print(log_text)
self.log_message(log_text)
call_command('import_frog_vm_data',
start_index=start_index,
limit=limit,
module_name=options.get('module_name'),
token=api_token)
start_index += limit

def log_message(self, message):
"""
Log a message to the console and a file.
"""
print(message)
with open('import_all_frog_log.txt', 'a') as the_file:
the_file.write(message + '\n')
8 changes: 8 additions & 0 deletions scripts/management/commands/import_all_odonata.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def add_arguments(self, parser):
default='0',
help='Start index'
)
parser.add_argument(
'-m',
'--module-name',
dest='module_name',
default='Odonate Adults',
help='Module name'
)

def handle(self, *args, **options):
api_token = options.get('token', '')
Expand Down Expand Up @@ -75,5 +82,6 @@ def handle(self, *args, **options):
call_command('import_odonata_data',
start_index=start_index,
limit=limit,
module_name=options.get('module_name'),
token=api_token)
start_index += limit
9 changes: 8 additions & 1 deletion scripts/management/commands/import_frog_vm_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def add_arguments(self, parser):
default=self.source_name,
help='Source name'
)
parser.add_argument(
'-md',
'--module-name',
dest='module_name',
default='Anurans',
help='Module Name'
)

def handle(self, *args, **options):
self.api_token = options.get('token', '')
Expand All @@ -68,7 +75,7 @@ def handle(self, *args, **options):
module_name=self.module_name,
base_api_url=self.base_api_url,
source_name=self.source_name,
taxon_group_module='Anura')
taxon_group_module=options.get('module_name'))
harvester.harvest(
start_index=start_index,
limit=limit,
Expand Down
9 changes: 8 additions & 1 deletion scripts/management/commands/import_odonata_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def add_arguments(self, parser):
default=10,
help='How many data should be retrieved'
)
parser.add_argument(
'-md',
'--module-name',
dest='module_name',
default='Odonate Adults',
help='Module Name'
)

def handle(self, *args, **options):
self.api_token = options.get('token', '')
Expand All @@ -69,7 +76,7 @@ def handle(self, *args, **options):
module_name=self.module_name,
base_api_url=self.base_api_url,
source_name=self.source_name,
taxon_group_module='Odonate Adults')
taxon_group_module=options.get('module_name'))
harvester.harvest(
start_index=start_index,
limit=limit,
Expand Down

0 comments on commit 1f2865a

Please sign in to comment.