Esempio n. 1
0
def counters_update():
    if request.method == 'GET':
        id = request.args.get('id', '')
        counter = SocialCounter.get(SocialCounter.id == id)
        form = SocialCounterForm(None, counter)
    else:
        id = request.form.get('id')
        counter = SocialCounter.get(SocialCounter.id == id)
        form = SocialCounterForm(request.form)
        form.validate()
        # urls = request.form.get('urls')
        # urls_stripped = "\n".join([line.rstrip() for line in urls.splitlines() if line.strip()])
        if form.errors:
            pass
        else:
            now = datetime.datetime.utcnow()
            counter.name = request.form.get('name')
            counter.runnable = request.form.get('runnable')
            counter.gspread_link = request.form.get('gspread_link')
            # counter.urls = urls_stripped
            counter.urls = None  # or obtained from gspread?
            counter.updated_at = now
            counter.save()
            new_counter = False
            form = SocialCounterForm(None, counter)
            flash('Social counter was updated')
            return redirect(url_for('counters.counters_list'))
    return render_template('counter.html',
                           current_user=current_user,
                           form=form,
                           new_counter=False,
                           id=id)
Esempio n. 2
0
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()
Esempio n. 3
0
def counters_create():
    form = SocialCounterForm(request.form)
    form.validate()
    # urls = request.form.get('urls')
    # urls_stripped = "\n".join([ll.rstrip() for ll in urls.splitlines() if ll.strip()])
    new_counter = True
    if form.errors:
        pass
    else:
        now = datetime.datetime.utcnow()
        counter = SocialCounter.create(
            name=request.form.get('name'),
            runnable=request.form.get('runnable'),
            gspread_link=request.form.get('gspread_link'),
            # urls=urls_stripped,
            urls=None,  # or obtained from gspread?
            created_at=now,
            updated_at=now)
        new_counter = False
        form = SocialCounterForm(None, counter)
        flash('Social counter was created')
        return redirect(url_for('counters.counters_list'))
    return render_template('counter.html',
                           current_user=current_user,
                           form=form,
                           new_counter=new_counter)
Esempio n. 4
0
def counters_summary():
    id = request.args.get('id', None)
    if id is None:
        flash('Error: id is missing for Social counter summary page!')
        return redirect(url_for('counters.counters_list'))
    sc = SocialCounter.get(SocialCounter.id == id)
    counters = SocialCount.select().where(
        SocialCount.name == sc.name).order_by(SocialCount.timestamp.desc())
    return render_template('counters_summary.html',
                           current_user=current_user,
                           counters=counters,
                           id=id)
Esempio n. 5
0
def count_now():
    # gspread columns, does the name matter? no, just the proper number of columns for the results:
    # url, tweets, google_plusses, fb_total, fb_shares, fb_likes, fb_comments, fb_clicks
    id = request.args.get('id', None)
    if id is None:
        flash('Error: id is missing, but is required to run a Social counter!')
        return redirect(url_for('counters.counters_list'))
    sc = SocialCounter.get(SocialCounter.id == id)
    if sc.is_runnable():
        # processed = SocialCount.fetch_counters(sc.name, sc.urls)
        processed = SocialCount.fetch_counters(sc)
    flash("Social counts updated for: '%s'" % sc.name)
    return redirect(url_for('counters.counters_list'))
Esempio n. 6
0
def counters_list():
    counters = SocialCounter.select()
    return render_template('counters_list.html',
                           current_user=current_user,
                           counters=counters)
Esempio n. 7
0
def social_counters():
    social_counters = SocialCounter.select()
    for sc in social_counters:
        if sc.is_runnable():
            processed = SocialCount.fetch_counters(sc.name, sc.urls)
    print("%s job: social counters processed" % datetime.utcnow())