Beispiel #1
0
def changeActivity():
    result = {}
    json_data = request.json
    account = Account.query.filter_by(id=json_data['accountId']).first()
    if(account):
        Account.query.filter_by(id=json_data['accountId']).update({'activity':json_data['activity']})
        db.session.commit()
        restart_celery_beat()
        result['status'] = 1
        result['msg'] = 'Successfully change activity status.'
    else:
        result['status'] = 0
        result['msg'] = 'Occured error in change activity status.'
    db.session.close()
    return jsonify({'result': result})
Beispiel #2
0
def uploadCSVList():
    result = {}
    accountId = request.form['accountId']
    listname = request.form['listname']
    total_count = 0
    pool = Pool.query.filter_by(accountid=accountId, listname=listname).first()
    if (pool):
        result['status'] = 0
        result['msg'] = 'List name is existed'
        return jsonify({'result': result})
    if 'file' not in request.files:
        result['status'] = 0
        result['msg'] = 'No selected file'
        return jsonify({'result': result})
    file = request.files['file']  # if user does not select file, browser also
    # submit a empty part without filename
    if file.filename == '':
        result['status'] = 0
        result['msg'] = 'No selected file'
        return jsonify({'result': result})
    if file and allowed_file(file.filename):
        pool = Pool(
            accountid=accountId,
            listname=listname
        )
        db.session.add(pool)
        db.session.commit()
        listreader = csv.reader(file, delimiter=' ', quotechar='|')
        for row in listreader:
            if (row[0][0] != '@'):
                continue
            total_count = total_count + 1
            follow = Following(
                poolid=pool.id,
                name=row[0]
            )
            db.session.add(follow)
        Pool.query.filter_by(id=pool.id).update({'total_count': total_count})
        db.session.commit()
        restart_celery_beat()
        result['status'] = 1
        result['msg'] = 'File uploaded successfully'
    else:
        result['status'] = 0
        result['msg'] = 'Something went wrong.'
    db.session.close()
    return jsonify({'result': result})
Beispiel #3
0
def changeUnFollowScheduleStatus():
    result = {}
    json_data = request.json
    account = Account.query.filter_by(id=json_data['accountId']).first()
    if(account):
        Account.query.filter_by(id=json_data['accountId']) \
                     .update({
                        'unfollow_schedule_status':json_data['unfollow_schedule_status'],
                        'unfollow_schedule_option':json_data['unfollow_schedule_option']})
        db.session.commit()
        restart_celery_beat()
        result['status'] = 1
        result['msg'] = 'Successfully change UnFollow Schedule status.'
    else:
        result['status'] = 0
        result['msg'] = 'Occured error in change UnFollow Schedule status.'
    db.session.close()
    return jsonify({'result': result})
Beispiel #4
0
def delList():
    result = {}
    json_data = request.json
    pool = Pool.query.filter_by(id=json_data['id']).first()
    if (pool):
        try:
            followings = Following.query.filter_by(poolid=pool.id).all()
            for following in followings:
                db.session.delete(following)
            db.session.commit()
            db.session.delete(pool)
            db.session.commit()
            result['status'] = 1
            result['msg'] = 'Succefully deleted List.'
            restart_celery_beat()
        except:
            result['status'] = 0
            result['msg'] = 'Occured error in db session.'
    else:
        result['status'] = 0
        result['msg'] = 'Selected list is not existed'
    db.session.close()
    return jsonify({'result': result})