-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(export): Added year export for extraction
Signed-off-by: Lorenzo Vagliano
- Loading branch information
1 parent
5c123f2
commit 188662e
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import csv | ||
import datetime | ||
import logging | ||
|
||
from django.core.files.storage import storages | ||
from django.core.management.base import BaseCommand, CommandParser | ||
|
||
from scoap3.utils.tools import year_export | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Export article information by year" | ||
|
||
def add_arguments(self, parser: CommandParser) -> None: | ||
parser.add_argument( | ||
"--start", | ||
type=str, | ||
required=False, | ||
help="Start date.", | ||
) | ||
|
||
parser.add_argument( | ||
"--end", | ||
type=str, | ||
required=False, | ||
help="End date.", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
storage = storages["default"] | ||
result = year_export(options["start"], options["end"]) | ||
|
||
with storage.open( | ||
f"scoap3_export_years_{datetime.datetime.now()}.csv", "w" | ||
) as f: | ||
writer = csv.writer(f) | ||
writer.writerow(result["header"]) | ||
writer.writerows(result["data"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters