コード例 #1
0
ファイル: deck.py プロジェクト: GenkoStoykov/AngularRepo
def unlinkdeck():
    result = {}
    json_data = request.json
    if (is_admin()):
        link = Link.query.filter_by(userid=json_data['userid'],
                                    deckid=json_data['deckid']).first()
        if (link == None):
            result['msg'] = 'This user is not linked with this deck.'
            result['status'] = 0
        else:
            try:
                profiles = Profile.query.filter_by(linkid=link.id).all()
                for profile in profiles:
                    if (profile.run_status == 1):
                        jobid = 'retweet_%s' % (profile.id)
                        if (is_running(jobid)):
                            scheduler.remove_job(jobid)
                    db.session.delete(profile)
                approves = Approve.query.filter_by(linkid=link.id).all()
                for approve in approves:
                    db.session.delete(approve)
                db.session.delete(link)
                db.session.commit()
                result['status'] = 1
                result['msg'] = 'Sucessfully unlinked.'
            except:
                result['msg'] = 'Occured error in db session.'
                result['status'] = 0
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    return jsonify({'result': result})
コード例 #2
0
def delUser():
    result = {}
    json_data = request.json
    if (is_admin()):
        try:
            user = User.query.filter_by(id=json_data['userid']).first()
            links = Link.query.filter_by(userid=user.id).all()
            for link in links:
                profiles = Profile.query.filter_by(linkid=link.id).all()
                for profile in profiles:
                    if (profile.run_status == 1):
                        jobid = 'retweet_%s' % (profile.id)
                        if (is_running(jobid)):
                            scheduler.remove_job(jobid)
                    db.session.delete(profile)
                approves = Approve.query.filter_by(linkid=link.id).all()
                for approve in approves:
                    db.session.delete(approve)
                db.session.delete(link)
            db.session.delete(user)
            db.session.commit()
            result['status'] = 1
            result['msg'] = 'Succefully deleted user.'
        except:
            result['status'] = -1
            result['msg'] = 'Occured error in delete user.'
    else:
        result['status'] = -1
        result['msg'] = 'Please login now.'
    db.session.close()
    return jsonify({'result': result})
コード例 #3
0
ファイル: deck.py プロジェクト: GenkoStoykov/AngularRepo
def delDeck():
    result = {}
    json_data = request.json
    try:
        deck = Deck.query.filter_by(id=json_data['id']).first()
        links = Link.query.filter_by(deckid=deck.id).all()
        user = User.query.filter_by(username=deck.name).first()
        for link in links:
            profiles = Profile.query.filter_by(linkid=link.id).all()
            for profile in profiles:
                if (profile.run_status == 1):
                    jobid = 'retweet_%s' % (profile.id)
                    if (is_running(jobid)):
                        scheduler.remove_job(jobid)
                db.session.delete(profile)
            approves = Approve.query.filter_by(linkid=link.id).all()
            for approve in approves:
                db.session.delete(approve)
            db.session.delete(link)
        removedriver(deck.name)
        db.session.delete(deck)
        db.session.delete(user)
        db.session.commit()
        result['status'] = 1
        result['msg'] = 'Succefully deleted Deck.'
    except:
        result['status'] = -1
        result['msg'] = 'Occured error in delete Deck.'
    db.session.close()
    return jsonify({'result': result})
コード例 #4
0
ファイル: profile.py プロジェクト: GenkoStoykov/AngularRepo
def delProfile():
    result = {}
    json_data = request.json
    try:
        profile = Profile.query.filter_by(id=json_data['id']).first()
        if (profile.run_status == 1):
            jobid = 'retweet_%s' % (profile.id)
            if (is_running(jobid)):
                scheduler.remove_job(jobid)
        db.session.delete(profile)
        db.session.commit()
        result['status'] = 1
        result['msg'] = 'Succefully deleted Profile.'
    except:
        result['status'] = -1
        result['msg'] = 'Occured error in delete profile.'
    db.session.close()
    return jsonify({'result': result})
コード例 #5
0
ファイル: profile.py プロジェクト: GenkoStoykov/AngularRepo
def updateProfile():
    result = {}
    json_data = request.json
    minutes = json_data['minutes']
    profile = Profile.query.filter_by(id=json_data['id']).first()
    link = Link.query.filter_by(id=profile.linkid).join(Deck).first()
    minutes = int(minutes)
    if (minutes < 10):
        result['status'] = 0
        result['msg'] = 'Interval time must to be more than %s minutes' % app.config['MINIMUM_INTERVAL_TIME']
    elif (profile == None):
        result['status'] = -1
        result['msg'] = 'Profile is not existed.'
    elif (link.deck == None):
        result['status'] = -1
        result['msg'] = 'Deck is not available.'
    else:
        Profile.query.filter_by(id=json_data['id']).update({"minutes": json_data['minutes']})
        result['status'] = 1
        result['msg'] = 'Succefully Updated Profile.'
        if (profile.run_status == 1):
            driver = getdriver(link.deck.name)
            if (driver != None):
                jobid = 'retweet_%s' % (profile.id)
                if (is_running(jobid)):
                    scheduler.remove_job(jobid)
                params = {'profile_id': profile.id, 'driver': driver}
                scheduler.add_job(
                    func=auto_rt,
                    kwargs=params,
                    trigger=IntervalTrigger(minutes=minutes),
                    # trigger=IntervalTrigger(minutes=1),
                    id='retweet_%s' % (json_data['id']),
                    replace_existing=False,
                    misfire_grace_time=app.config['MISFIRE_GRACE_TIME'])
                Profile.query.filter_by(id=profile.id).update({'run_status': 1})
            else:
                Profile.query.filter_by(id=profile.id).update({'run_status': 0})
                result['status'] = -1
                result['msg'] = 'Driver is not available.'
        db.session.commit()
    db.session.close()
    return jsonify({'result': result})
コード例 #6
0
ファイル: profile.py プロジェクト: GenkoStoykov/AngularRepo
def pauseProfile():
    result = {}
    json_data = request.json
    profile = Profile.query.filter_by(id=json_data['id']).first()
    link = Link.query.filter_by(id=profile.linkid).join(Deck).first()
    if (profile == None):
        result['status'] = -1
        result['msg'] = 'Profile is not existed.'
    elif (link.deck == None):
        result['status'] = -1
        result['msg'] = 'Deck is not available.'
    else:
        result['status'] = 1
        result['msg'] = 'Succefully Updated Profile.'
        if (profile.run_status == 1):
            jobid = 'retweet_%s' % (profile.id)
            if (is_running(jobid)):
                scheduler.remove_job(jobid)
            Profile.query.filter_by(id=profile.id).update({'run_status': 0})
            db.session.commit()
    db.session.close()
    return jsonify({'result': result})
コード例 #7
0
ファイル: profile.py プロジェクト: GenkoStoykov/AngularRepo
def runProfile():
    result = {}
    json_data = request.json
    profile = Profile.query.filter_by(id=json_data['id']).first()
    link = Link.query.filter_by(id=profile.linkid).join(Deck).first()
    if (profile == None):
        result['status'] = -1
        result['msg'] = 'Profile is not existed.'
    if(link.deck.login_code < 1):
        result['status'] = -1
        result['msg'] = 'Please login or verify deck now.'
    elif (link.deck == None):
        result['status'] = -1
        result['msg'] = 'Deck is not available.'
    else:
        result['status'] = 1
        result['msg'] = 'Succefully run Profile.'
        if (profile.run_status < 1):
            driver = getdriver(link.deck.name)
            if (driver != None):
                jobid = 'retweet_%s' % (profile.id)
                if (is_running(jobid)):
                    scheduler.remove_job(jobid)
                params = {'profile_id': profile.id, 'driver': driver}
                scheduler.add_job(
                    func=auto_rt,
                    kwargs=params,
                    trigger=IntervalTrigger(minutes=profile.minutes),
                    # trigger=IntervalTrigger(minutes=1),
                    id='retweet_%s' % (json_data['id']),
                    replace_existing=False,
                    misfire_grace_time=app.config['MISFIRE_GRACE_TIME'])
                Profile.query.filter_by(id=profile.id).update({'run_status': 1})
            else:
                result['status'] = -1
                result['msg'] = 'Driver is not available.'
        db.session.commit()
    db.session.close()
    return jsonify({'result': result})
コード例 #8
0
def acceptPendingById():
    json_data = request.json
    result = {}
    approve = Approve.query.filter_by(id=json_data['id']).first()
    if(approve == None):
        result['status'] = -1
        result['msg'] = 'Approve is not existed.'
    else:
        if (is_deck()):
            try:
                link = Link.query.filter_by(id=approve.linkid).join(Deck).first()
                profile = Profile.query.filter_by(linkid=link.id, keyword=approve.keyword).first()
                if (link.deck == None):
                    result['status'] = -1
                    result['msg'] = 'Deck is not available.'
                else:
                    if (profile != None):
                        Profile.query.filter_by(id=profile.id).update({"minutes": approve.minutes})
                        result['status'] = 1
                        result['msg'] = 'Succefully added request to profile.'
                        if (profile.run_status == 1):
                            driver = getdriver(link.deck.name)
                            if (driver != None):
                                jobid = 'retweet_%s' % (profile.id)
                                if (is_running(jobid)):
                                    scheduler.remove_job(jobid)
                                params = {'profile_id': profile.id, 'driver': driver}
                                scheduler.add_job(
                                    func=auto_rt,
                                    kwargs={'profile_id': profile.id, 'driver': driver},
                                    trigger=IntervalTrigger(minutes=approve.minutes),
                                    # trigger=IntervalTrigger(minutes=1),
                                    id='retweet_%s' % (profile.id),
                                    replace_existing=False,
                                    misfire_grace_time=app.config['MISFIRE_GRACE_TIME'])
                                Profile.query.filter_by(id=profile.id).update({'run_status': 1})
                            else:
                                Profile.query.filter_by(id=profile.id).update({'run_status': 0})
                                result['status'] = -1
                                result['msg'] = 'Driver is not available.'
                        db.session.delete(approve)
                        db.session.commit()
                    else:
                        newprofile = Profile(
                            linkid=link.id,
                            keyword=approve.keyword,
                            minutes=approve.minutes,
                            run_status=link.deck.login_code
                        )
                        db.session.add(newprofile)
                        db.session.delete(approve)
                        db.session.commit()
                        result['status'] = 1
                        result['msg'] = 'Succefully added request to profile.'
                        driver = getdriver(link.deck.name)
                        if (driver != None):
                            if (link.deck.login_code > 0):
                                scheduler.add_job(
                                    func=auto_rt,
                                    kwargs={'profile_id': newprofile.id, 'driver': driver},
                                    trigger=IntervalTrigger(minutes=approve.minutes),
                                    # trigger=IntervalTrigger(minutes=1),
                                    id='retweet_%s' % (newprofile.id),
                                    replace_existing=False,
                                    misfire_grace_time=app.config['MISFIRE_GRACE_TIME'])
                        else:
                            Profile.query.filter_by(id=newprofile.id).update({'run_status':0})
                            db.session.commit()
                            result['status'] = -1
                            result['msg'] = 'Driver is not available.'
            except:
                result['status'] = 0
                result['msg'] = 'Occured error in db session.'
        else:
            result['status'] = -1
            result['msg'] = 'Please login now.'
    return jsonify({'result': result})