def nuevo_video(request, slug): # suma un video a un tema template = 'videos/nuevo.html' tema = get_object_or_404(Temas, slug=slug) if request.method == 'POST': form = FormNuevoVideo(request.POST) if form.is_valid(): url = form.cleaned_data['url'] titulo = form.cleaned_data['titulo'] descripcion = form.cleaned_data['descripcion'] perfil_usuario = Perfiles.objects.get(usuario=request.user) url_data = urlparse.urlparse( url ) # para analizar la url, determinar donde esta hosteado el video query = urlparse.parse_qs(url_data.query) network_location = url_data.netloc youtube_id = "" if network_location in ("www.youtube.com", "youtube.com"): es_youtube = True youtube_id = query['v'][0] # guarda el youtube ID. else: es_youtube = False # Crea un nuevo video object nuevo_video = Videos(tema=tema, perfil=perfil_usuario, titulo=titulo, descripcion=descripcion, url=url, es_youtube=es_youtube, youtube_id=youtube_id) nuevo_video.save() # calcular nivel actividad y de popularidad del Tema popularidad_actividad_tema(tema, "positivo") return redirect('videos:videos_tema', slug=tema.slug, queryset='recientes') else: print "form invalid" return redirect('videos:nuevo_video', slug=tema.slug) else: form_nuevo_video = FormNuevoVideo() # honeypot lista_bersuit = bersuit_vergarabat() context = { 'form_nuevo_video': form_nuevo_video, 'tema': tema, 'lista_bersuit': lista_bersuit } return render(request, template, context)
def get(self): v = Videos(key_name='videos') v.users = ["ShangoRBG","Halbertis","farhad43","abatebi","iranlover100","SasanShah1","Zendoaut","hadihadithegreat","saeidkermanshah"] v.searches = ["iranelection","iran riot","tehran"] v.put() t = Twitter(key_name='twitter') t.keywords = ['iranelection', 'tehran'] t.put() self.response.out.write('init\'d')
def createVideos(postObj): try: customer = models.Customers.objects.get(user__username=postObj.username) print customer # duration = postsBll.get_video_length(filepath) video = Videos(user = customer,video=postObj.film,mov_type=postObj.mov_type,title=postObj.title, duration="5:00",mov_desc=postObj.mov_desc,thumb_img=postObj.thumb_img,poster=postObj.poster) print video video.save() print "afte save" return True except Exception, e: print e return False
def process_item(self, item, spider): m = re.findall(r"[0-9]+",item["url"]) item['k_id'] = '_'.join(m) instance = Videos(**item) session = self.Session() try: session.merge(instance) session.commit() except Exception as e: session.rollback() logging.info(e) else: logging.info('news pipe %s' % item.get('k_id')) finally: session.close() aid = item["aid"] sql = "update need_crawl_url SET finished_time="+str(time.time()) sql = sql + ' where aid='+aid connection = self.engine.connect() connection.execute(sql) connection.close() return item
def nuevo_video(request, slug): # suma un video a un tema template = 'videos/nuevo.html' tema = get_object_or_404(Temas, slug=slug) if request.method == 'POST': form = FormNuevoVideo(request.POST) if form.is_valid(): url = form.cleaned_data['url'] titulo = form.cleaned_data['titulo'] descripcion = form.cleaned_data['descripcion'] perfil_usuario = Perfiles.objects.get(usuario=request.user) url_data = urlparse.urlparse(url) # para analizar la url, determinar donde esta hosteado el video query = urlparse.parse_qs(url_data.query) network_location = url_data.netloc youtube_id = "" if network_location in ("www.youtube.com", "youtube.com"): es_youtube = True youtube_id = query['v'][0] # guarda el youtube ID. else: es_youtube = False # Crea un nuevo video object nuevo_video = Videos( tema=tema, perfil=perfil_usuario, titulo=titulo, descripcion=descripcion, url=url, es_youtube=es_youtube, youtube_id=youtube_id) nuevo_video.save() # calcular nivel actividad y de popularidad del Tema popularidad_actividad_tema(tema, "positivo") return redirect('videos:videos_tema', slug=tema.slug, queryset='recientes') else: print "form invalid" return redirect('videos:nuevo_video', slug=tema.slug) else: form_nuevo_video = FormNuevoVideo() # honeypot lista_bersuit = bersuit_vergarabat() context = {'form_nuevo_video': form_nuevo_video, 'tema': tema, 'lista_bersuit': lista_bersuit} return render(request, template, context)
def createVideo(userID): if "user_id" in session: thisUser = Users.query.get(session['user_id']) newVid = Videos(title=request.form['title'], video_link=request.form['video_link'], description=request.form['description'], video_author_id=session['user_id']) db.session.add(newVid) db.session.commit() return redirect('/create') else: return redirect('/create')
def add_video(): form = VideoForm(request.form) if request.method == "POST" and form.validate(): title = form.title.data link = form.link.data author = session['username'] video = Videos(title, link, author) db.session.add(video) db.session.commit() flash("Video created", "success") return redirect(url_for('dashboard')) else: error = form.errors return render_template('add_video.html', form=form, error=error) return render_template('add_video.html', form=form)
def get_the_latest_video(): # slug from latest scraped record latest_scraped_video = scrape_latest_video() scraped_slug = latest_scraped_video['slug'] # check if scraped slug exists in db find_latest_slug_by_scraped_slug = bool( Videos.query.filter_by(slug=scraped_slug).first()) if find_latest_slug_by_scraped_slug == False: try: add_latest_video = Videos( title=latest_scraped_video['title'], date=latest_scraped_video['slug'], slug=scraped_slug, video_link=latest_scraped_video['video_link']) db.session.add(add_latest_video) db.session.commit() except: db.session.rollback() finally: db.session.close() latest_video = Videos.query.filter_by( slug=scraped_slug).first() else: latest_video = Videos.query.filter_by(slug=scraped_slug).first() return jsonify({ 'success': True, 'videos': { 'id': latest_video.id, 'title': latest_video.title, 'date': latest_video.date, 'slug': latest_video.slug, 'video_link': latest_video.video_link } })
def get(self): v = Videos.all()[0] context = add_user_to_context({ 'users': v.users, 'searches': v.searches }) self.response.out.write( template.render(tmpl('templates/video.html'), context ))
def all_videos(): videos = Videos.query.all() if len(videos) == 0: try: scraped_videos = scrape_all_videos() for video in scraped_videos: new_video = Videos(title=video['title'], date=video['date'], slug=video['slug'], video_link=video['video_link']) db.session.add(new_video) db.session.commit() except: db.session.rollback() finally: db.session.close() videos_from_db = Videos.query.order_by(Videos.id).all() formatted_videos = [video.format() for video in videos_from_db] video_list = formatted_videos else: # check if video list is updated # slug from latest scraped record latest_scraped_video = scrape_latest_video() scraped_slug = latest_scraped_video['slug'] # check if scraped slug exists in db find_latest_slug_by_scraped_slug = bool( Videos.query.filter_by(slug=scraped_slug).first()) if find_latest_slug_by_scraped_slug == False: try: add_latest_video = Videos( title=latest_scraped_video['title'], date=latest_scraped_video['slug'], slug=scraped_slug, video_link=latest_scraped_video['video_link']) db.session.add(add_latest_video) db.session.commit() except: db.session.rollback() finally: db.session.close() videos_from_db = Videos.query.order_by(Videos.id).all() formatted_videos = [ video.format() for video in videos_from_db ] video_list = formatted_videos else: videos_from_db = Videos.query.order_by(Videos.id).all() formatted_videos = [video.format() for video in videos_from_db] video_list = formatted_videos return jsonify({'success': True, 'videos': video_list})