Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
m3_webInterface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
m3
m3_webInterface
Commits
b9164254
Commit
b9164254
authored
Jul 02, 2023
by
Mario Chirinos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
urls
parent
e9959300
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
120 deletions
+5
-120
updateDB.py.save
catalog/management/commands/updateDB.py.save
+0
-114
urls.py
catalog/urls.py
+1
-1
views.py
catalog/views.py
+4
-5
No files found.
catalog/management/commands/updateDB.py.save
deleted
100644 → 0
View file @
e9959300
from django.core.management.base import BaseCommand, CommandError
from catalog.models import News, Publisher, Topic
from django.db.models import Q
import os
import json
import datetime
from django.utils import timezone
import dateutil.parser
class Command(BaseCommand):
help = 'Update database'
def add_arguments(self, parser):
parser.add_argument('basedir', nargs=1, type=str)
def handle(self, *args, **options):
os.chdir(options['basedir'][0])
publisherList = os.listdir(options['basedir'][0])
for p in publisherList:
print p
os.chdir(p)
publisher = Publisher.objects.all().filter(shortName=p)[0]
news = News.objects.all().filter(publisher=publisher.id).order_by("-date")
# print publisher.id
minYear = 0
lastDate = datetime.datetime(1950,1,1)
# print news.count()
if news.count()>0:
minYear = news[0].date.year
lastDate = news[0].date
yearList = [ int(y) for y in os.listdir('.')]
# print "LastDate"+str(lastDate)
print yearList
for y in yearList:
if y >=minYear:
os.chdir(str(y))
print os.getcwd()
filesList = os.listdir(".")
for f in filesList:
# print "file: " + f
fileDate = datetime.datetime.strptime(f[:f.find(".")], "%Y-%m-%d").date()
if fileDate >= lastDate.date():
# print "fileDate: " + str(fileDate)
with open(f) as data_file:
try:
data = json.load(data_file)
for d in data:
# if d['date'].find("+") >=0:
# date =d['date'][:d['date'].find("+")].replace("T", " ")
# newsDate = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
# else:
# date = d['date']
# newsDate = datetime.datetime.strptime(date, "%Y-%m-%d")
# print d['date']
# print d['title']
newsDate = dateutil.parser.parse(d['date'])
# newsDate = timezone.make_aware(newsDate, timezone.get_current_timezone())
# print "newsDate:"
# print newsDate
if News.objects.all().filter(Q(publisher=publisher.id)&Q(title=d['title'])&Q(date__gte=newsDate)).count() == 0:
# print "no news match"
if d['title'] == None:
d['title'] = "Sin Titulo"
if len(d['title']) >= 512:
d['title'] = d['title'][:500]
print p + " "+ str(newsDate) + ": " + d['title']
# print type(d['topic'])
news = News()
news.publisher = publisher
# print "title"
news.title = d['title']
# print "text"
news.text = d['text']
# print "url"
news.url = d['url']
# print "date"
news.date = newsDate
news.save()
# print "TOPIC: " + str(d['topic'])
# print type(d['topic'])
if d['topic'] == "" or d['topic'] == None or d['topic'] ==[]:
d['topic'] = "Sin Tema"
if type(d['topic'])=="list":
for t in d['topic']:
topic, created = Topic.objects.all().get_or_create(name=t)
news.topic.add(topic)
else:
topic, created = Topic.objects.all().get_or_create(name=d['topic'])
news.topic.add(topic)
# print news.date
# print d['date']
# #news.save()
# except (RuntimeError, TypeError, NameError, ValueError) as e:
except ValueError as e:
print e
# print e.NameError
print "Error: " + os.getcwd()+"/"+f
print type(d['topic'])
# print "TOPIC: " + str(d['topic'])
data_file.close()
os.chdir("..")
os.chdir("..")
catalog/urls.py
View file @
b9164254
#from django.conf.urls import url
#from django.conf.urls import url
from
django.urls
import
re_
path
as
url
from
django.urls
import
path
as
url
from
.
import
views
from
.
import
views
from
django.views.i18n
import
JavaScriptCatalog
from
django.views.i18n
import
JavaScriptCatalog
...
...
catalog/views.py
View file @
b9164254
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.shortcuts
import
render
from
django.shortcuts
import
render
...
@@ -260,12 +259,12 @@ def publisherList(request, type="all"):
...
@@ -260,12 +259,12 @@ def publisherList(request, type="all"):
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
newsList
(
request
,
publisherShortName
=
"all"
):
def
newsList
(
request
,
publisherShortName
=
"all"
):
form
=
SearchForm
(
request
.
GET
)
form
=
SearchForm
(
request
.
GET
)
subscriptions
=
[
(
r
.
id
,
r
.
name
)
for
r
in
request
.
user
.
profile
.
subscriptions
.
all
()]
subscriptions
=
[
(
r
.
id
,
r
.
name
)
for
r
in
request
.
user
.
profile
.
subscriptions
.
all
()]
form
.
fields
[
'publishers'
]
.
choices
=
subscriptions
form
.
fields
[
'publishers'
]
.
choices
=
subscriptions
return
render
(
request
,
'new/newsList.html'
,{
"form"
:
form
})
return
render
(
request
,
'new/newsList.html'
,{
"form"
:
form
})
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
newsDetails
(
request
,
newsId
):
def
newsDetails
(
request
,
newsId
):
form
=
SearchForm
(
request
.
GET
)
form
=
SearchForm
(
request
.
GET
)
...
...
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