Commit 2ed67f05 authored by Mario Chirinos's avatar Mario Chirinos

bulk upload

parent d8867a45
...@@ -56,11 +56,10 @@ class Command(BaseCommand): ...@@ -56,11 +56,10 @@ class Command(BaseCommand):
news = News.objects.all().filter(publisher=publisher.id).order_by("-date") news = News.objects.all().filter(publisher=publisher.id).order_by("-date")
minYear = 0 minYear = 0
lastDate = datetime.datetime(1950,1,1) lastDate = datetime.datetime(1950,1,1)
if news.count()>0: if news.count()>0:
minYear = news[0].date.year minYear = news[0].date.year
lastDate = news[0].date lastDate = news[0].date
print("LAST DATE ", lastDate)
# Year list from directory structure # Year list from directory structure
yearList = sorted([ int(y) for y in os.listdir('.') if os.path.isdir(y) ]) yearList = sorted([ int(y) for y in os.listdir('.') if os.path.isdir(y) ])
...@@ -76,7 +75,7 @@ class Command(BaseCommand): ...@@ -76,7 +75,7 @@ class Command(BaseCommand):
for f in filesList: for f in filesList:
fileDate = datetime.datetime.strptime(f[:f.find(".")], "%Y-%m-%d").date() fileDate = datetime.datetime.strptime(f[:f.find(".")], "%Y-%m-%d").date()
if fileDate >= lastDate.date(): if fileDate >= lastDate.date():
print(fileDate) print("FILE DATE ", fileDate)
#delete news form the most recent day in the database so it can upload the day again #delete news form the most recent day in the database so it can upload the day again
News.objects.filter(date__gte=fileDate).delete() News.objects.filter(date__gte=fileDate).delete()
with open(f) as data_file: with open(f) as data_file:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment