-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add backfill_changesets command (#675)
- Loading branch information
1 parent
e3a0ea4
commit 6c6c36c
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
osmchadjango/changeset/management/commands/backfill_changesets.py
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,34 @@ | ||
from datetime import date | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from ...models import Changeset | ||
from ...tasks import create_changeset | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """Backfill missing changesets in a date range. | ||
Start and end dates should be in YYYY-MM-DD format.""" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("start_date", nargs=1, type=str) | ||
parser.add_argument("end_date", nargs=1, type=str) | ||
|
||
def handle(self, *args, **options): | ||
try: | ||
end_date = date.fromisoformat(options["end_date"][0]) | ||
except (ValueError, TypeError): | ||
end_date = date.today() | ||
|
||
cl = Changeset.objects.filter( | ||
date__gte=date.fromisoformat(options["start_date"][0]), | ||
date__lte=end_date | ||
).values_list('id') | ||
cl = [c[0] for c in cl] | ||
|
||
id = cl[len(cl) - 1] | ||
final = cl[0] | ||
while id < final: | ||
if id not in cl: | ||
create_changeset(id) | ||
id = id + 1 |
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