Commit e77142b8 authored by Mario Chirinos Colunga's avatar Mario Chirinos Colunga 💬

audio list

parent beef9215
No preview for this file type
import sys
import argparse
import os
import subprocess
from numpy import array_equal
from datetime import datetime, timedelta
BASEDIR = "/home/mario/"
#-------------------------------------------------------------------------------
def getRecordingDays(initTimestamp, endTimestamp):
initialDate = datetime.fromtimestamp(initTimestamp) #+ timedelta(hours=6)
endDate = datetime.fromtimestamp(endTimestamp) #+ timedelta(hours=6)
print(initialDate)
print(endDate)
iDate = [initialDate.day, initialDate.month, initialDate.year]
eDate = [endDate.day, endDate.month, endDate.year]
days = 1
if array_equal(iDate, eDate):
# Iterate over the same day dir
return days
else:
while not array_equal(iDate, eDate):
days += 1
initialDate += timedelta(days=1)
iDate = [initialDate.day, initialDate.month, initialDate.year]
return days
#-------------------------------------------------------------------------------
def getAudiosList2Convert(streamPublisher, initTimestamp, endTimestamp, days):
recordingsPath = BASEDIR+'virtualHDD/m3/recordings/'
initialDate = datetime.fromtimestamp(initTimestamp) #+ timedelta(hours=6)
endDate = datetime.fromtimestamp(endTimestamp) #+ timedelta(hours=6)
audiosList = []
for i in range(days):
audiosPath = '{0}/{1}/{2:02d}/{3:02d}/'.format(
streamPublisher,
initialDate.year,
initialDate.month,
initialDate.day
)
print('Now enter in: {0}'.format(audiosPath))
print(recordingsPath+audiosPath)
if os.path.exists(recordingsPath+audiosPath):
print ("PATH EXIST")
for file in os.listdir(recordingsPath+audiosPath):
# print (file)
audioTimestamp = int(file.split(".")[0])
if audioTimestamp >= initTimestamp and audioTimestamp <= endTimestamp:
audiosList.append(recordingsPath+audiosPath+file)
#audiosList.append((recordingsPath+audiosPath, file))
# Next day dir
initialDate += timedelta(days=1)
return audiosList
#-------------------------------------------------------------------------------
def convertAudios2Mp3(audiosList):
mp3Path = BASEDIR+'virtualHDD/m3/recordings/mp3/'
if not os.path.exists(mp3Path):
print('Mp3 created...')
os.mkdir(mp3Path)
for (audioPath, audioName) in audiosList:
timestamp = audioName.split('.')[0]
print('Timestamp: {0} - Date format: {1}'.format(timestamp, datetime.fromtimestamp(float(timestamp))))
mp3Name = timestamp + '.mp3'
convertionCommand = 'ffmpeg -i "{0}" -qscale:a 20 {1}'.format(audioPath+audioName, mp3Path+mp3Name)
subprocess.run(convertionCommand, shell=True)
#-------------------------------------------------------------------------------
def getAudioList(streamPublisher, initTimestamp, endTimestamp):
print("getAudioList(", streamPublisher, ",", initTimestamp, ",", endTimestamp, ")")
initTimestamp = float(initTimestamp)
endTimestamp = float(endTimestamp)
days = getRecordingDays(initTimestamp, endTimestamp)
print('Recording days: {0}'.format(days))
audiosList = getAudiosList2Convert(streamPublisher, initTimestamp, endTimestamp, days)
return audiosList
...@@ -2,33 +2,32 @@ ...@@ -2,33 +2,32 @@
from django import forms from django import forms
#from django.contrib.auth.forms import UserCreationForm #from django.contrib.auth.forms import UserCreationForm
#from django.contrib.auth.models import User #from django.contrib.auth.models import User
from catalog.models import Publisher, News, Profile from catalog.models import Publisher, News, Profile, Search
from django.db.models import Q from django.db.models import Q
from django.contrib.admin.widgets import FilteredSelectMultiple from django.contrib.admin.widgets import FilteredSelectMultiple
import os import os
from django.conf import settings from django.conf import settings
from django.urls import reverse from django.urls import reverse
class SearchForm(forms.ModelForm):
class Meta:
model = Search
exclude = ["user"]
# fields = '__all__'
class SearchForm(forms.Form): widgets = {'startDate': forms.DateInput(attrs={'type':'date', 'class':"form-control"}),
startDate = forms.DateField(label="Fecha de Inicio", widget=forms.DateInput(attrs={'type':'date', 'class':"form-control"}), required=False) 'endDate': forms.DateInput(attrs={'type':'date', 'class':"form-control"}),
endDate = forms.DateField(label="Fecha de Fin", widget=forms.DateInput(attrs={'type':'date', 'class':"form-control"}), required=False) 'text':forms.TextInput(attrs={'class':"form-control", "placeholder":"Palabras clave"}),
'publishers':forms.SelectMultiple(attrs={'class':"form-control"}),
'user': forms.HiddenInput(),
}
labels = {'startDate':"Fecha de Inicio", 'endDate':"Fecha de Fin", 'text': "Palabras Clave", 'publishers':"Fuentes",}
# news = News.objects.all() def save(self, user):
# publishersList = Publisher.objects.all().filter( Q(id__in = news.values('publisher').distinct())) form = super(SearchForm, self).save(commit=False)
# choice = [ (r.id,r.name) for r in publishersList ] form.user = user
# publishers = forms.MultipleChoiceField(label="Fuentes", widget=forms.SelectMultiple(attrs={'class':"form-control"}), choices=choice, required=False) form.save()
publishers = forms.MultipleChoiceField(label="Fuentes", widget=forms.SelectMultiple(attrs={'class':"form-control"}), choices=[], required=False)
text = forms. CharField(label="Palabras Clave", widget=forms.TextInput(attrs={'class':"form-control", "placeholder":"Palabras clave"}), required=False)
def __init__(self, *args, **kwargs):
super(SearchForm, self).__init__(*args, **kwargs)
news = News.objects.all()
publishersList = Publisher.objects.all().filter( Q(id__in = news.values('publisher').distinct()))
choice = [ (r.id,r.name) for r in publishersList ]
self.fields['publishers'] = forms.MultipleChoiceField(label="Fuentes", widget=forms.SelectMultiple(attrs={'class':"form-control"}), choices=choice, required=False)
class ProfileForm(forms.Form): class ProfileForm(forms.Form):
subscriptions = forms.ModelMultipleChoiceField(queryset=Publisher.objects.all(), widget=FilteredSelectMultiple("Publishers", is_stacked=False), required=False) subscriptions = forms.ModelMultipleChoiceField(queryset=Publisher.objects.all(), widget=FilteredSelectMultiple("Publishers", is_stacked=False), required=False)
...@@ -39,3 +38,30 @@ class ProfileForm(forms.Form): ...@@ -39,3 +38,30 @@ class ProfileForm(forms.Form):
# in the temple # in the temple
css = {'all': (os.path.join(settings.BASE_DIR, '/static/admin/css/widgets.css'),),} css = {'all': (os.path.join(settings.BASE_DIR, '/static/admin/css/widgets.css'),),}
js = ('/catalog/js/jsi18n',) js = ('/catalog/js/jsi18n',)
class SubscriptionsForm(forms.ModelForm):
# def __init__(self, *args, **kwargs):
# super(SubscriptionsForm, self).__init__(*args, **kwargs)
# news = News.objects.all()
# publishersList = Publisher.objects.all().filter( Q(id__in = news.values('publisher').distinct()))
# choice = [ (r.id,r.name) for r in publishersList ]
# self.fields['subscriptions'].choices = []
class Meta:
model = Profile
fields = ('subscriptions',)
# field_classes = {'subscriptions': forms.ModelMultipleChoiceField,}
widgets = {'subscriptions': FilteredSelectMultiple("Publishers", is_stacked=False),}
class Media:
# Django also includes a few javascript files necessary
# for the operation of this form element. You need to
# include <script src="/admin/jsi18n"></script>
# in the temple
css = {'all': (os.path.join(settings.BASE_DIR, '/static/admin/css/widgets.css'),),}
js = ('/catalog/js/jsi18n')
#forms.MultipleChoiceField(label="Fuentes", widget=forms.SelectMultiple(attrs={'class':"form-control"}), choices=choice, required=False)
No preview for this file type
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from catalog.models import News, Publisher, Topic from catalog.models import News, Publisher, Topic, audioTime
from django.db.models import Q from django.db.models import Q
import os import os
import json import json
import datetime import datetime
from django.utils import timezone from django.utils import timezone
import dateutil.parser import dateutil.parser
import itertools
from datetime import date
class Command(BaseCommand): class Command(BaseCommand):
help = 'Update database' help = 'Update database'
...@@ -14,6 +17,25 @@ class Command(BaseCommand): ...@@ -14,6 +17,25 @@ class Command(BaseCommand):
parser.add_argument('basedir', nargs=1, type=str) parser.add_argument('basedir', nargs=1, type=str)
def handle(self, *args, **options): def handle(self, *args, **options):
#update radio stations recotding time
print("Recording Time:")
recordingsDir = "/home/mario/virtualHDD/m3/recordings/"
audioTime.objects.all().delete()
publishers = Publisher.objects.all().filter(type="audio")
for p in publishers:
files = [files for r, d, files in os.walk(recordingsDir+p.shortName)]
files = list(itertools.chain.from_iterable(files))
minutes = len(files)
sortedFiles = sorted([(f[:f.find(".flac")]) for f in files if f.find(".flac")>0 and f.count(".")==1])
print(p.shortName+": "+ str(minutes))
if len(sortedFiles)>2:
print("timestamp: " + sortedFiles[0])
print("len timestamp: " + str(len(sortedFiles[0])))
#print (files)
#print (sortedFiles)
since = datetime.datetime.utcfromtimestamp(int(sortedFiles[0]))
audioTime.objects.update_or_create(publisher=p, defaults={'minutes': minutes, "startDate": since},)
#load news
os.chdir(options['basedir'][0]) os.chdir(options['basedir'][0])
publisherList = os.listdir(options['basedir'][0]) publisherList = os.listdir(options['basedir'][0])
for p in publisherList: for p in publisherList:
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-14 18:25
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('catalog', '0008_profile_subscriptions'),
]
operations = [
migrations.CreateModel(
name='Search',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('startDate', models.DateTimeField(verbose_name=b'Start Date')),
('endDate', models.DateTimeField(verbose_name=b'End Date')),
('text', models.CharField(max_length=128)),
('publishers', models.ManyToManyField(to='catalog.Publisher')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-14 18:52
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0009_search'),
]
operations = [
migrations.AlterField(
model_name='search',
name='publishers',
field=models.ManyToManyField(blank=True, to='catalog.Publisher'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-18 18:43
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0010_auto_20171214_1852'),
]
operations = [
migrations.AlterField(
model_name='search',
name='text',
field=models.CharField(blank=True, max_length=128),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-21 16:47
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0011_auto_20171218_1843'),
]
operations = [
migrations.AlterField(
model_name='search',
name='endDate',
field=models.DateTimeField(blank=True, verbose_name=b'End Date'),
),
migrations.AlterField(
model_name='search',
name='startDate',
field=models.DateTimeField(blank=True, verbose_name=b'Start Date'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-21 17:28
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0012_auto_20171221_1647'),
]
operations = [
migrations.AlterField(
model_name='search',
name='endDate',
field=models.DateTimeField(blank=True, null=True, verbose_name=b'End Date'),
),
migrations.AlterField(
model_name='search',
name='startDate',
field=models.DateTimeField(blank=True, null=True, verbose_name=b'Start Date'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-12-21 18:20
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0013_auto_20171221_1728'),
]
operations = [
migrations.AlterField(
model_name='search',
name='endDate',
field=models.DateTimeField(verbose_name=b'End Date'),
),
migrations.AlterField(
model_name='search',
name='startDate',
field=models.DateTimeField(verbose_name=b'Start Date'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-01-31 20:50
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('catalog', '0014_auto_20171221_1820'),
]
operations = [
migrations.CreateModel(
name='audioTime',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('startDate', models.DateTimeField(verbose_name=b'Start Date')),
('seconds', models.BigIntegerField(default=0)),
('publisher', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='catalog.Publisher')),
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-01-31 21:05
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('catalog', '0015_audiotime'),
]
operations = [
migrations.RenameField(
model_name='audiotime',
old_name='seconds',
new_name='minutes',
),
]
...@@ -8,6 +8,8 @@ from django.dispatch import receiver ...@@ -8,6 +8,8 @@ from django.dispatch import receiver
# Create your models here. # Create your models here.
#-------------------------------------------------------------------------------
class Publisher(models.Model): class Publisher(models.Model):
name = models.CharField(max_length=128) name = models.CharField(max_length=128)
shortName = models.CharField(max_length=32, default="") shortName = models.CharField(max_length=32, default="")
...@@ -23,7 +25,7 @@ class Publisher(models.Model): ...@@ -23,7 +25,7 @@ class Publisher(models.Model):
verbose_name_plural = 'Medios' verbose_name_plural = 'Medios'
ordering = ('name',) ordering = ('name',)
#-------------------------------------------------------------------------------
class Topic(models.Model): class Topic(models.Model):
name = models.CharField(verbose_name='Tema', max_length=256) name = models.CharField(verbose_name='Tema', max_length=256)
...@@ -34,12 +36,12 @@ class Topic(models.Model): ...@@ -34,12 +36,12 @@ class Topic(models.Model):
verbose_name = 'Tema' verbose_name = 'Tema'
verbose_name_plural = 'Temas' verbose_name_plural = 'Temas'
ordering = ('name',) ordering = ('name',)
#-------------------------------------------------------------------------------
class PostManager(models.Manager): class PostManager(models.Manager):
def with_documents(self): def with_documents(self):
vector = SearchVector('text') vector = SearchVector('text')
return self.get_queryset().annotate(document=vector) return self.get_queryset().annotate(document=vector)
#-------------------------------------------------------------------------------
class News(models.Model): class News(models.Model):
title = models.CharField(max_length=512) title = models.CharField(max_length=512)
publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE, default='') publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE, default='')
...@@ -65,19 +67,36 @@ class News(models.Model): ...@@ -65,19 +67,36 @@ class News(models.Model):
verbose_name_plural = 'Noticias' verbose_name_plural = 'Noticias'
ordering = ('date',) ordering = ('date',)
indexes = [ GinIndex(fields=['search_vector']) ] indexes = [ GinIndex(fields=['search_vector']) ]
#-------------------------------------------------------------------------------
class Search(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
startDate = models.DateTimeField(verbose_name='Start Date')
endDate = models.DateTimeField(verbose_name='End Date')
text = models.CharField(max_length=128,blank=True)
publishers = models.ManyToManyField(Publisher,blank=True)
#-------------------------------------------------------------------------------
class Profile(models.Model): class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE) user = models.OneToOneField(User, on_delete=models.CASCADE)
subscriptions = models.ManyToManyField(Publisher) subscriptions = models.ManyToManyField(Publisher)
# def __init__(self, *args, **kwargs):
# self.subscriptions = Publisher.objects.all()
# super().__init__(*args, **kwargs)
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs): def create_user_profile(sender, instance, created, **kwargs):
if created: if created:
Profile.objects.create(user=instance) Profile.objects.create(user=instance)#, subscriptions=Publisher.objects.all())
print ("profile created")
@receiver(post_save, sender=User) @receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs): def save_user_profile(sender, instance, **kwargs):
instance.profile.save() instance.profile.save()
#-------------------------------------------------------------------------------
class audioTime(models.Model):
publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)
startDate = models.DateTimeField(verbose_name='Start Date')
minutes = models.BigIntegerField(default=0)
No preview for this file type
body {padding: 0; color: #888;}
.page-wrapper {margin-top: 0px; overflow: hidden;}
.page-content, .footer-content {padding:0px 0; padding-bottom: 30px;}
.head-content {padding-top: 80px;}
.container {padding: 0;}
.navbar-fixed-top {padding: 20px 0; height: auto; background-color: rgba(255, 255, 255, 0.5); border: none; margin: 0;}
.navbar-fixed-top .btn{font-size: 16px; font-weight: bold; padding: 0 15px;}
.navbar-default .navbar-brand {padding: 0; margin: 0;}
.navbar-fixed-top .navbar-collapse {width: 100%;}
.logo {}
.logo .path { fill: #fff;}
.logo {width: 130px;height: 140px;}
.footer-content {margin-top: 60px; background-color: #555; padding: 30px;}
.footer-content .download{padding: 30px;text-align: center;border-bottom: 1px solid #666;width: 100%;margin-bottom: 30px;}
.footer-content .download .glyphicon{font-size: 40px;color: #FFF;}
.footer-content .download .btn {border: 0;}
.jumbotron {padding:20px 15px;border: none; background: none; margin-bottom: 0;}
.jumbotron .btn-group .btn {background-color: transparent;border: 1px solid transparent; font-size: 22px; font-weight: bold; padding: 15px 30px; border: 0; }
.jumbotron .btn-group .btn .glyphicon {color: rgba(0,0,0,0.2); margin-right: 10px;font-size: 20px;}
.jumbotron .btn-group .btn:hover .glyphicon {color: #fff;}
.calendar-view .sample-calendar { margin: 30px 0;}
.range-cal-trigger{ border: 0; height: 100%; background-color: transparent;}
.range-cal-trigger .glyphicon {}
.themes-group .btn { border: 0; margin: 0 0px; padding: 10px 15px; height: 10px; position: relative;}
.themes-group .btn .glyphicon {font-size: 14px; line-height: 16px; opacity: .0; display: none; color: rgba(255,255,255,.8); margin: 0; padding: 0;margin-right: 10px; display: none; }
.themes-group .btn .title {font-weight: 100;font-size: 14px; float: left;}
.themes-group .btn .half-color { right: 0; top: 0; width: 50%;height: 100%; position: absolute; background-color: #f9f9f9;}
.themes-group .btn.selected {border: 1px solid rgba(255,255,255,0.5);}
.themes-group .btn.selected .glyphicon {color: #fff; opacity: 1.0; margin: 0; display: none;float: left; margin-right: 5px; margin-top: -10px; height: 20px;}
.themes-group .btn.selected .title {display: block;}
.themes-group .btn.selected .half-color { opacity: 0.5;}
.themes-group .colors-info .title{ font-weight: bold; font-size: 16px; display: block; clear: both; margin-bottom: 5px; opacity: 0.5; }
.themes-group .colors-info .subtitle{ font-weight: 100; font-size: 16px; width: 100px;display: block; clear: both;}
.themes-group .colors-info .title .glyphicon {margin-right: 5px; opacity: 0.5;}
.page-content .calendar-values { display: none;}
.calendar-values {margin-top: 30px;margin-bottom: 30px;}
.calendar-values .col { text-align: center; color: #888;}
.calendar-values > .col-md-3,.calendar-values >.col-md-4 { border-right: 1px solid #eee;}
.calendar-values .col.last { border: 0;}
.calendar-values .col .glyphicon {font-size: 40px;padding: 5px 0;margin-bottom: 5px;}
.calendar-values .col .glyphicon-comment {margin-top: 0;font-size: 63px;padding-top: 0;}
.calendar-values .col .title {width: 100%;text-align: center;font-size: 20px;font-weight: bold;display: block;clear: both;text-transform: uppercase;}
.calendar-values .col .subtitle {width: 100%;text-align: center;font-size: 12px;font-weight: bold;display: block;clear: both;text-transform: uppercase;}
.calendar-values .col .value {width: 100%; text-align: center; font-size: 40px; font-weight: bold; display: block; clear: both}
.calendar-values .col .label {width: 100%;text-align: center; font-size: 14px;font-weight: bold; display: block; clear: both; text-transform: uppercase; color: #666 }
.calendar-values .col .label small { margin-left: 5px;color: #888; font-weight: 100}
#how .pre {border: 1px solid #eee; background-color: transparent;}
.modal {}
.modal .modal-content {box-shadow: none; border: 0; margin: 0; background-color: #f9f9f9;}
.modal .modal-footer {box-shadow: none; border: 0; margin: 0;}
.modal .btn-close {position: absolute;top: 0;right: 0;border: 0;margin: 15px;}
.modal .calendar-values { padding: 20px 0; margin: 0px;}
.modal .range-calendar {padding: 10px 0;}
.modal .calendar-values .col .glyphicon {font-size: 22px;}
.modal .calendar-values .col .glyphicon-comment {font-size: 22px;}
.modal .calendar-values .col .title {font-size: 12px;}
.modal .calendar-values .col .subtitle {font-size: 12px;}
.modal .calendar-values .col .value {font-size: 30px;}
.modal .calendar-values .col .label {font-size: 14px;}
#langs {margin-left: 10px;}
#langs .dropdown-toggle {color: #666;}
.colorization-group { margin-top: 15px;}
.colorization-group .btn {padding: 15px; border: 0; border-radius: 1px;}
.colorization-group .btn .glyphicon {font-size: 14px; line-height: 16px; opacity: .0; display: none; color: rgba(255,255,255,.8); margin: 0; padding: 0;margin-right: 10px; display: none; }
.colorization-group .btn .title {font-weight: 100;font-size: 14px; float: left;}
.colorization-group .btn .half-color { right: 0; top: 0; width: 50%;height: 100%; position: absolute; background-color: #f9f9f9;}
.colorization-group .btn.selected {border: 1px solid rgba(255,255,255,0.5);}
.colorization-group .btn.selected .glyphicon {color: #fff; opacity: 1.0; margin: 0; display: none;float: left; margin-right: 5px; margin-top: -10px; height: 20px;}
.colorization-group .btn.selected .title {display: block;}
.colorization-group .btn.selected .half-color { opacity: 0.5;}
.colorization-group .colors-info .title{ font-weight: bold; font-size: 16px; display: block; clear: both; margin-bottom: 5px; opacity: 0.5; }
.colorization-group .colors-info .subtitle{ font-weight: 100; font-size: 16px; width: 100px;display: block; clear: both;}
.colorization-group .colors-info .title .glyphicon {margin-right: 5px; opacity: 0.5;}
.section {padding-bottom: 15px; margin-bottom: 15px;clear: both; display: block;}
.section .section-title {color: #666; margin-bottom: 15px;}
.section .content {margin-bottom: 15px;}
.section .code {padding: 30px 15px;background-color: #333; color: #f9f9f9; width: 100%;display: block;border-radius: 0; line-height: 25px; display: block;clear: both; margin-bottom: 10px;}
.section .code .sample-title {clear: both;margin-bottom: 15px;width: 100%;display: block;line-height: 60px;font-size: 25px;font-weight: bold;}
.section .range-calendar {margin-top: 15px;}
p {font-size: 22px;}
.form-required { display: none; }
This diff is collapsed.
This diff is collapsed.
{% extends "base_generic.html" %} {% extends "base_generic.html" %}
{% block lefPanel %}{% include "leftMenuBar.html" %}{% endblock %}
{% load humanize %} {% load humanize %}
{% load mathfilters %}
{% block dash-title %} {% block dash-title %}
...@@ -37,12 +40,13 @@ ...@@ -37,12 +40,13 @@
<tbody> <tbody>
{% for p in publishers %} {% for p in publishers %}
<tr class="odd gradeX"> <tr class="odd gradeX">
<td><a href="{% url 'audio'%}{{p.shortName}}">{{p.name}}</a></td> <td><a href="{% url 'audio'%}{{p.publisher.shortName}}">{{p.publisher.name}}</a></td>
<td>{{p.shortName}}</td> <td>{{p.publisher.shortName}}</td>
<td><a href="{{p.url}}" target="blank">{{p.url}}</a></td> <td><a href="{{p.publisher.url}}" target="blank">{{p.publisher.url}}</a></td>
<td>{{p.date}}</td> <td>{{p.startDate}}</td>
<td><a href="{% url 'news-list'%}?publishers={{p.id}}&{{queryurl}}">{{p.news|intcomma}}</a></td>
<td>{{p.type}}</td> <td>{{p.minutes|div:60|floatformat:2 }}</td>
<td>{{p.publisher.type}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
......
{% extends "base_generic.html" %} {% extends "base_generic.html" %}
{% block lefPanel %}{% include "leftMenuBar.html" %}{% endblock %}
{% block headMedia %}
{% load static %}
<link rel="stylesheet" id="rangecalendar-style-css" href="{% static 'css/rangecalendar.css' %}" type="text/css" media="all">
<link rel="stylesheet" id="rangecalendar-style-css" href="{% static 'css/calendar-style.css' %}" type="text/css" media="all">
<link rel="stylesheet" id="rangecalendar-style-css" href="{% static 'css/audioplayer.css' %}" type="text/css" media="all">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/themes/smoothness/jquery-ui.css">
{% endblock %}
{% load humanize %} {% load humanize %}
{% block dash-title %} {% block dash-title %}
...@@ -21,13 +30,10 @@ ...@@ -21,13 +30,10 @@
<!-- /.panel-heading --> <!-- /.panel-heading -->
<div class="panel-body"> <div class="panel-body">
<div id="audioCalendar"></div>
<div id="audioDiv">audio tag</div>
<div id="cal1">holas</div>
<!-- /.table-responsive --> <!-- /.table-responsive -->
</div> </div>
<!-- /.panel-body --> <!-- /.panel-body -->
</div> </div>
...@@ -41,13 +47,83 @@ ...@@ -41,13 +47,83 @@
{% block scripts %} {% block scripts %}
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment-with-langs.min.js"></script>
<script type="text/javascript" src="{% static 'js/jquery.rangecalendar.js' %}"></script>
<script> <script>
$(document).ready(function() { function getAudioList(publisher, startdate, enddate)
$('#dataTables-example').DataTable({ {
responsive: true, var xmlhttp;
"language": {"url": "/static/languages/Spanish.json" } if (window.XMLHttpRequest)
}); {//IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// document.getElementById("topics").innerHTML=xmlhttp.responseText;
var jsonObj = JSON.parse(xmlhttp.responseText);
console.log(jsonObj);
}
}
xmlhttp.open("GET", "/catalog/ws/playlist/?startdate="+startdate+"&enddate="+enddate+"&publisher="+publisher,true);
xmlhttp.send();
};
$(document).ready(function () {
var emptyMonths = [
{month: '01', year: '2016'},
{month: '06', year: '2016'},
{month: '09', year: '2016'},
{month: '03', year: '2017'},
{month: '07', year: '2017'},
{month: '11', year: '2017'}
];
var calendar = $("#audioCalendar").rangeCalendar({
theme:"full-red-theme",
lang: "es",
startDate: moment(20160101, "YYYYMMDD"),
endDate: moment(),
start: "0",
minRangeWidth: 1,
maxRangeWidth: 1,
maxTimeRangeWidth: 6,
changeRangeCallback: rangeChanged,
emptyMonths: emptyMonths
}); });
var today = new Date();
calendar.setStartDate(today);
function rangeChanged(target, range) {
console.log(range);
var audioDiv = document.getElementById("audioDiv");
while (audioDiv.firstChild)
audioDiv.removeChild(audioDiv.firstChild);
var sound = document.createElement('audio');
sound.id = 'audio-player';
sound.controls = 'controls';
sound.src = 'media/Blue Browne.mp3';
sound.type = 'audio/mpeg';
audioDiv.appendChild(sound);
getAudioList("{{publisher.shortName}}",range.start,range.end);
}
});
</script> </script>
{% endblock %} {% endblock %}
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
<title>Monitoreo de Multiples Medios</title> <title>Monitoreo de Multiples Medios</title>
{% load staticfiles %} {% load staticfiles %}
<script type="text/javascript" src="{% static 'static_jquery/js/jquery.js' %}" ></script> <script type="text/javascript" src="{% static 'static_jquery/js/jquery.js' %}" ></script>
<script type="text/javascript" src="{% static 'admin/js/jquery.init.js' %}" ></script> <script type="text/javascript" src="{% static 'admin/js/jquery.init.js' %}" ></script>
<link rel="stylesheet" href="{% static 'css/forms.css' %}">
<!-- Custom CSS --> <!-- Custom CSS -->
<!-- Bootstrap Core CSS --> <!-- Bootstrap Core CSS -->
......
...@@ -11,31 +11,32 @@ ...@@ -11,31 +11,32 @@
<a href="#"><i class="fa fa-search fa-fw"></i>Busqueda<span class="fa arrow"></span></a> <a href="#"><i class="fa fa-search fa-fw"></i>Busqueda<span class="fa arrow"></span></a>
<ul class="nav nav-second-level collapse in" aria-expanded="true"> <ul class="nav nav-second-level collapse in" aria-expanded="true">
<form role="form"> <form role="form" >
<li> <li>
<div class="form-group"> <!-- <div class="form-group">-->
{{form.publishers.label_tag}} <!-- {{form.publishers.label_tag}}-->
{{form.publishers}} <!-- {{form.publishers}}-->
</div> <!-- </div>-->
</li> <!-- </li>-->
<li> <!-- <li>-->
<div class="form-group"> <!-- <div class="form-group">-->
{{form.startDate.label_tag}} <!-- {{form.startDate.label_tag}}-->
{{form.startDate}} <!-- {{form.startDate}}-->
</div> <!-- </div>-->
</li> <!-- </li>-->
<li> <!-- <li>-->
<div class="form-group"> <!-- <div class="form-group">-->
{{form.endDate.label_tag}} <!-- {{form.endDate.label_tag}}-->
{{form.endDate}} <!-- {{form.endDate}}-->
</div> <!-- </div>-->
</li> <!-- </li>-->
<li> <!-- <li>-->
<div class="form-group"> <!-- <div class="form-group">-->
{{form.text.label_tag}} <!-- {{form.text.label_tag}}-->
{{form.text}} <!-- {{form.text}}-->
</div> <!-- </div>-->
{{form}}
</li> </li>
......
{% extends "settings_base.html" %}
{% block dash-title %}
<b>{{form.text.value|default:"Busquedas Realizadas"|capfirst}}</b>
[{{form.startDate.value}}, {{form.endDate.value}}]
{% endblock %}
{% block dash %}
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Busquedas
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-search">
<thead>
<tr>
<th>Texto</th>
<th>Inicio</th>
<th>Fin</th>
<th>Fuentes</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Texto</th>
<th>Inicio</th>
<th>Fin</th>
<th>Fuentes</th>
</tr>
</tfoot>
</table>
<!-- /.table-responsive -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
{% endblock %}
{% block scripts %}
<script>
$(document).ready(function() {
$('#dataTables-search').DataTable({
"order": [[ 2, "desc" ]],
"responsive": true,
"processing": true,
"serverSide": true,
"language": {"url": "/static/languages/Spanish.json" },
"ajax": {
"url":"/catalog/ws/searches/",
"data":{},
}
});
});
//console.log(" {{form.publishers.data|safe}} ");
</script>
{% endblock %}
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
<li> <li>
<a href="{% url 'settings-subscriptions' %}"><i class="fa fa-rss fa-fw"></i>Subscripciones</a> <a href="{% url 'settings-subscriptions' %}"><i class="fa fa-rss fa-fw"></i>Subscripciones</a>
</li> </li>
<li>
<a href="{% url 'settings-search' %}"><i class="fa fa-search fa-fw"></i>Busquedas</a>
</li>
<!-- <li>--> <!-- <li>-->
<!-- <a href=""><i class="fa fa-user fa-rss"></i>Subscripciones</a>--> <!-- <a href=""><i class="fa fa-user fa-rss"></i>Subscripciones</a>-->
<!-- </li>--> <!-- </li>-->
......
...@@ -12,10 +12,14 @@ urlpatterns = [ ...@@ -12,10 +12,14 @@ urlpatterns = [
url(r'^publishers/(?P<type>\w+)$', views.publisherList, name='publishers-list'), url(r'^publishers/(?P<type>\w+)$', views.publisherList, name='publishers-list'),
url(r'^news/details/(?P<newsId>\w+)/$', views.newsDetails, name='news-details'), url(r'^news/details/(?P<newsId>\w+)/$', views.newsDetails, name='news-details'),
url(r'^news/$', views.newsList, name='news-list'), url(r'^news/$', views.newsList, name='news-list'),
url(r'^ws/news/$', views.wsNewsList, name='ws-news-list'), url(r'^ws/news/$', views.wsNewsList, name='ws-news-list'),
url(r'^ws/jsonnews/$', views.wsNewsList2, name='ws-news-list2'), url(r'^ws/jsonnews/$', views.wsNewsList2, name='ws-news-list2'),
url(r'^ws/graphs/$', views.wsGraphs, name='ws-graphs'), url(r'^ws/graphs/$', views.wsGraphs, name='ws-graphs'),
url(r'^ws/download/$', views.wsDownloadNews, name='ws-download-news'), url(r'^ws/download/$', views.wsDownloadNews, name='ws-download-news'),
url(r'^ws/searches/$', views.wsSearchList, name='ws-search-list'),
url(r'^ws/playlist/$', views.wsAudioList, name='ws-audio-list'),
url(r'^audio/$', views.audioList, name='audio'), url(r'^audio/$', views.audioList, name='audio'),
url(r'^audio/(?P<publisher>\w+)$', views.audioPublisher, name='audio'), url(r'^audio/(?P<publisher>\w+)$', views.audioPublisher, name='audio'),
...@@ -23,6 +27,7 @@ urlpatterns = [ ...@@ -23,6 +27,7 @@ urlpatterns = [
url(r'^settings/profile$', views.settings, name='settings-profile'), url(r'^settings/profile$', views.settings, name='settings-profile'),
url(r'^settings/subscriptions$', views.settings, name='settings-subscriptions'), url(r'^settings/subscriptions$', views.settings, name='settings-subscriptions'),
url(r'^settings/password$', views.settings, name='settings-password'), url(r'^settings/password$', views.settings, name='settings-password'),
url(r'^settings/searches$', views.settingsSearches, name='settings-search'),
] ]
No preview for this file type
...@@ -6,28 +6,99 @@ from django.shortcuts import render ...@@ -6,28 +6,99 @@ from django.shortcuts import render
# Create your views here. # Create your views here.
from catalog.models import Publisher, News from catalog.models import Publisher, News, Search, audioTime
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import redirect from django.shortcuts import redirect
from django.http import HttpResponse from django.http import HttpResponse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Count
from django.core.urlresolvers import reverse
from django.db.models.functions import TruncMonth, TruncYear
from .forms import SearchForm, ProfileForm, SubscriptionsForm
from django.db.models import Q
import json import json
import datetime import datetime
import time
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
import dateutil.parser
from django.db.models import Q
from .forms import SearchForm, ProfileForm
import urllib import urllib
from django.db.models import Count
from django.core.urlresolvers import reverse
import json import json
import StringIO import StringIO
#from io import StringIO
import time import time
import zipfile import zipfile
import csv import csv
from django.db.models.functions import TruncMonth, TruncYear
from quantiphy import Quantity from quantiphy import Quantity
from .audioList import getAudioList
#-------------------------------------------------------------------------------
def getAudiosList2Convert(streamPublisher, initTimestamp, endTimestamp, days):
recordingsPath = '/home/mario/virtualHDD/m3/recordings/'
initialDate = datetime.fromtimestamp(initTimestamp) #+ timedelta(hours=6)
endDate = datetime.fromtimestamp(endTimestamp) #+ timedelta(hours=6)
audiosList = []
for i in range(days):
audiosPath = '{0}/{1}/{2:02d}/{3:02d}/'.format(
streamPublisher,
initialDate.year,
initialDate.month,
initialDate.day
)
print('Now enter in: {0}'.format(audiosPath))
if os.path.exists(recordingsPath+audiosPath):
for file in os.listdir(recordingsPath+audiosPath):
audioTimestamp = int(file.split(".")[0])
if audioTimestamp >= initTimestamp and audioTimestamp <= endTimestamp:
audiosList.append(recordingsPath+audiosPath+file)
#audiosList.append((recordingsPath+audiosPath, file))
# Next day dir
initialDate += timedelta(days=1)
return audiosList
#-------------------------------------------------------------------------------
def getRecordingDays(initTimestamp, endTimestamp):
initialDate = datetime.fromtimestamp(initTimestamp) #+ timedelta(hours=6)
endDate = datetime.fromtimestamp(endTimestamp) #+ timedelta(hours=6)
print(initialDate)
print(endDate)
iDate = [initialDate.day, initialDate.month, initialDate.year]
eDate = [endDate.day, endDate.month, endDate.year]
days = 1
if array_equal(iDate, eDate):
# Iterate over the same day dir
return days
else:
while not array_equal(iDate, eDate):
days += 1
initialDate += timedelta(days=1)
iDate = [initialDate.day, initialDate.month, initialDate.year]
return days
#-------------------------------------------------------------------------------
def getAudiosList(streamPublisher, initTimestamp, endTimestamp):
initTimestamp = float(initTimestamp)
endTimestamp = float(endTimestamp)
days = getRecordingDays(initTimestamp, endTimestamp)
print('Recording days: {0}'.format(days))
audiosList = getAudiosList2Convert(streamPublisher, initTimestamp, endTimestamp, days)
return audiosList
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def news2JSON(news): def news2JSON(news):
data = list() data = list()
...@@ -42,18 +113,30 @@ def news2JSON(news): ...@@ -42,18 +113,30 @@ def news2JSON(news):
return data return data
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def settings(request): def settings(request):
form = ProfileForm(request.POST.copy())
print(request.POST)
# form = ProfileForm( initial={'subscriptions':[ v for v in request.user.profile.subscriptions.all().values_list('id', flat=True)]})
print ("subS",[ v for v in request.user.profile.subscriptions.all().values_list('id', flat=True)])
print(request.POST)
# print(form)
#User.objects.get(username=) #User.objects.get(username=)
print( request.user.profile.subscriptions ) if request.method == "POST":
if 'subscriptions' in request.POST: form = ProfileForm(request.POST)
request.user.profile.subscriptions = Publisher.objects.all().filter(id__in=request.POST['subscriptions']) if form.is_valid():
request.user.save() request.user.profile.subscriptions=form.cleaned_data['subscriptions']
print( request.user.profile.subscriptions ) else:
form = ProfileForm( initial={'subscriptions':[ v for v in request.user.profile.subscriptions.all().values_list('id', flat=True)]})
news = News.objects.all()
publishersList = Publisher.objects.all().filter( Q(id__in = news.values('publisher').distinct()))
choice = [ (r.id,r.name) for r in publishersList ]
form.fields['subscriptions'].choices=choice
print( request.user.profile.subscriptions.all() )
return render(request,'userprofile.html',{"form":form}) return render(request,'userprofile.html',{"form":form})
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def settingsSearches(request):
return render(request,'searches.html',{})
#-------------------------------------------------------------------------------
def getNewsByRequest(request): def getNewsByRequest(request):
print ("getNewsByRequest\n\n\n") print ("getNewsByRequest\n\n\n")
...@@ -64,6 +147,8 @@ def getNewsByRequest(request): ...@@ -64,6 +147,8 @@ def getNewsByRequest(request):
if 'publishers' in request.GET and request.GET['publishers']!="None" and request.GET['publishers']!="" and request.GET['publishers']!="[]": if 'publishers' in request.GET and request.GET['publishers']!="None" and request.GET['publishers']!="" and request.GET['publishers']!="[]":
myQuery &= Q(publisher_id__in=form['publishers'].value()) myQuery &= Q(publisher_id__in=form['publishers'].value())
else:
myQuery &= Q(publisher_id__in=[ r.id for r in request.user.profile.subscriptions.all()])
if 'startDate' in request.GET and request.GET['startDate']!="None" and request.GET['startDate']!="": if 'startDate' in request.GET and request.GET['startDate']!="None" and request.GET['startDate']!="":
myQuery &= Q(date__gte=request.GET['startDate']) myQuery &= Q(date__gte=request.GET['startDate'])
...@@ -87,8 +172,20 @@ def index(request): ...@@ -87,8 +172,20 @@ def index(request):
View function for home page of site. View function for home page of site.
""" """
news = getNewsByRequest(request) news = getNewsByRequest(request)
form = SearchForm(request.GET.copy()) data = request.GET.copy()
form = SearchForm(data)
if form.is_valid():
print("DATA",form.data)
form.save(request.user)
form.save_m2m()
print ("form is valid")
else:
print ("form is NOT valid", form.errors)
subscriptions = [ (r.id,r.name) for r in request.user.profile.subscriptions.all()]
form.fields['publishers'].choices= subscriptions
if news.count()>0: if news.count()>0:
if 'startDate' not in form or ('startDate' in form and form['startDate'].value == ""): if 'startDate' not in form or ('startDate' in form and form['startDate'].value == ""):
form.data.update({'startDate':news.earliest('date').date.strftime("%Y-%m-%d")}) form.data.update({'startDate':news.earliest('date').date.strftime("%Y-%m-%d")})
...@@ -109,7 +206,7 @@ def index(request): ...@@ -109,7 +206,7 @@ def index(request):
myRequest = request.GET.copy() myRequest = request.GET.copy()
myRequest.update({"publishers":q['publisher']}) myRequest.update({"publishers":q['publisher']})
urlDict[q['publisher']] = urllib.urlencode(myRequest) urlDict[q['publisher']] = urllib.urlencode(myRequest)
print (urlDict) # print (urlDict)
donutChart = [{"label": Publisher.objects.get(id=q['publisher']).name, "value":q["count"], "url":urlDict[q['publisher']]} for q in queryset] donutChart = [{"label": Publisher.objects.get(id=q['publisher']).name, "value":q["count"], "url":urlDict[q['publisher']]} for q in queryset]
...@@ -160,6 +257,33 @@ def newsList(request, publisherShortName="all"): ...@@ -160,6 +257,33 @@ def newsList(request, publisherShortName="all"):
form = SearchForm(request.GET) form = SearchForm(request.GET)
return render(request,'newsList.html',{"form":form}) return render(request,'newsList.html',{"form":form})
#-------------------------------------------------------------------------------
def wsAudioList(request):
data = dict()
print("wsAudioList", request.GET)
startDate = dateutil.parser.parse(request.GET['startdate']).strftime('%s')
endDate = dateutil.parser.parse(request.GET['enddate']).strftime('%s')
print ("STARTDATE", startDate)
audioList = getAudioList(request.GET['publisher'], startDate, endDate)
# audioList = getAudioList('RadioFormula1041', '1512158400', '1512396000')
print ("audioList", audioList)
return HttpResponse(json.dumps(data), content_type="application/json")
#-------------------------------------------------------------------------------
def wsSearchList(request):
searches = Search.objects.all().filter(user=request.user)
data = dict()
data['data']=[[s.text, "*" if s is None else s.startDate.strftime('%Y-%m-%d'), "*" if s is None else s.endDate.strftime('%Y-%m-%d'), ','.join([ sub.shortName for sub in s.publishers.all()])] for s in searches]
data['recordsTotal'] = searches.count()
data['recordsFiltered'] = searches.count()
return HttpResponse(json.dumps(data), content_type="application/json")
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def wsNewsList2(request): def wsNewsList2(request):
...@@ -262,7 +386,7 @@ def wsDownloadNews(request): ...@@ -262,7 +386,7 @@ def wsDownloadNews(request):
def audioList(request): def audioList(request):
form = SearchForm(request.GET) form = SearchForm(request.GET)
publishers = Publisher.objects.all().filter( type="audio") publishers = audioTime.objects.all().filter(minutes__gt=0 ) #type="audio")
return render(request,'audioList.html',{"form":form, "publishers":publishers}) return render(request,'audioList.html',{"form":form, "publishers":publishers})
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
......
This diff is collapsed.
No preview for this file type
...@@ -38,6 +38,7 @@ INSTALLED_APPS = [ ...@@ -38,6 +38,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.humanize', 'django.contrib.humanize',
'mathfilters',
'catalog.apps.CatalogConfig', 'catalog.apps.CatalogConfig',
'django.contrib.postgres', 'django.contrib.postgres',
'django_static_jquery', 'django_static_jquery',
......
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