def addbot(): form = BotForm() if form.validate_on_submit(): insta_user = form.insta_user.data insta_password = form.insta_password.data tags = form.tags.data comments = form.comments.data location = form.location.data radius = form.radius.data media = form.media.data created_dt = datetime.now() paid = False user_id = current_user.get_id() status = 'Created' end_dt = None results = None # Using INstaloader to get stats import instaloader import requests L = instaloader.Instaloader() L.login(insta_user, insta_password) profile = instaloader.Profile.from_username(L.context, insta_user) bio = profile.biography followers = profile.followers followees = profile.followees post_iterator = profile.get_posts() posts = post_iterator.count img = profile.get_profile_pic_url() response = requests.get(img) img_data = response.content image_string = base64.b64encode(img_data) new_bot = Bot( insta_user, insta_password, image_string, bio, followers, followees, posts, tags, comments, location, radius, media, created_dt, paid, status, end_dt, results, user_id ) # Commit these changes to the database db.session.add(new_bot) db.session.commit() flash("Your Inst@Bot creation was successfull!") return redirect(url_for('profile')) return render_template('create_bot.html', form=form)
def new(request): if request.method == 'POST': form = BotForm(request.POST) if form.is_valid(): bot = Bot(**form.cleaned_data) bot.save() return HttpResponseRedirect(bot.get_absolute_url()) else: form = BotForm() return render_to_response('bots/new.html', {'form': form}, context_instance=RequestContext(request))
def edit_bot(channel, bot): form = BotForm(obj=bot) if form.validate_on_submit(): bot.name = form.data.get('name') bot.activated = form.data.get('activated') bot.code=form.data.get('code') choir.UnloadBot(channel, bot) try: bot.put() flash(u'Bot %s successfully saved.' % bot.name, 'success') except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return render_template("edit_bot.html", channel=channel, bot=bot, form=form)
def create_bot(channel): form = BotForm() if form.validate_on_submit(): bot = Bot( name = form.name.data, activated = form.activated.data, code = form.code.data, channel = channel.key ) try: bot.put() flash(u'Bot %s successfully saved.' % bot.name, 'success') return redirect(url_for('qq.edit_bot', channel=channel.id, bot=bot.name)) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return redirect(url_for('qq.list_bots', channel=channel.id)) return render_template("new_bot.html", channel=channel, form=form)
def list_bots(): """List all bots""" bots = BotModel.all() form = BotForm() if form.validate_on_submit(): keywords = form.keywords.data.split(',') bot = BotModel( bot_username=form.bot_username.data, consumer_key=form.consumer_key.data, consumer_secret=form.consumer_secret.data, access_token=form.access_token.data, access_token_secret=form.access_token_secret.data, keywords=keywords ) try: bot.put() bot_id = bot.key().id() flash(u'Bot %s successfully saved.' % bot.bot_username, 'success') return redirect(url_for('list_bots')) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return redirect(url_for('list_bots')) return render_template('list_bots.html', bots=bots, form=form)