def channels_update(): # FIXME ugly code to do both edit/update if request.method == 'GET': id = request.args.get('id', '') counter = ChannelCounter.get(ChannelCounter.id == id) form = YoutubeChannelForm(None, counter) else: id = request.form.get('id') counter = ChannelCounter.get(ChannelCounter.id == id) form = YoutubeChannelForm(request.form) form.validate() if form.errors: pass else: now = datetime.utcnow() counter.name = request.form.get('name') counter.runnable = request.form.get('runnable') counter.gspread_link = request.form.get('gspread_link') counter.channel = None counter.updated_at = now counter.save() new_counter = False form = YoutubeChannelForm(None, counter) flash('Video counter was updated') return redirect(url_for('channels.channels_list')) return render_template('channel.html', current_user=current_user, form=form, new_counter=False, id=id)
def db_create(): db.connect() User.create_table(True) # True means fail siliently if table exists SocialCounter.create_table(True) SocialCount.create_table(True) ChannelCounter.create_table(True) Channel.create_table(True) UserFunction.create_table(True) FunctionResult.create_table(True) Crawler.create_table(True) CrawlerPage.create_table(True) Mozscape.create_table(True) MozscapeResult.create_table(True) MozscapeIndexMetadata.create_table(True) db.close()
def fetch_channel_counts(): id = request.args.get('id', None) if id is None: flash('Error: video counter id is missing!') return redirect(url_for('channels.channels_list')) cc = ChannelCounter.get(ChannelCounter.id == id) if cc.is_runnable(): # results = Channel.scrape(cc.name, cc.channel) results = Channel.scrape(cc) else: results = {} flash("Video counters were updated") return redirect(url_for('channels.channels_list'))
def channels_summary(): id = request.args.get('id', None) if id is None: flash('Error: id is missing for Video counter summary page!') return redirect(url_for('channels.channels_list')) cc = ChannelCounter.get(ChannelCounter.id == id) channel_name = cc.channel counters = Channel.select().where(Channel.name == cc.name).order_by( Channel.timestamp.desc()) return render_template('channels_summary.html', current_user=current_user, counters=counters, id=id, channel_name=channel_name)
def channels_create(): form = YoutubeChannelForm(request.form) form.validate() new_counter = True if form.errors: pass else: now = datetime.utcnow() counter = ChannelCounter.create( name=request.form.get('name'), runnable=request.form.get('runnable'), gspread_link=request.form.get('gspread_link'), channel=None, created_at=now, updated_at=now) new_counter = False form = YoutubeChannelForm(None, counter) flash('Video counter was created') return redirect(url_for('channels.channels_list')) return render_template('channel.html', current_user=current_user, form=form, new_counter=new_counter)
def youtube_channels(): counters = ChannelCounter.select() for c in counters: if c.is_runnable(): processed = Channel.scrape(c.name, c.urls) print("%s job: youtube channels processed" % datetime.utcnow())
def channels_list(): # glink = unicode(c.gspread_link, 'ascii') counters = ChannelCounter.select() return render_template('channels_list.html', current_user=current_user, counters=counters)