Esempio n. 1
0
def addprofile():
    result = {}
    json_data = request.json
    minutes = json_data['minutes']
    profile = Profile.query.filter_by(linkid=json_data['linkid'], keyword=json_data['keyword']).first()
    link = Link.query.filter_by(id=json_data['linkid']).join(Deck).first()
    try:
        minutes = int(minutes)
        if (minutes < app.config['MINIMUM_INTERVAL_TIME']):
            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 already existed.'
        elif (link.deck == None):
            result['status'] = -1
            result['msg'] = 'Deck is not available.'
        else:
            profile = Profile(
                linkid=json_data['linkid'],
                keyword=json_data['keyword'],
                minutes=json_data['minutes'],
                run_status=link.deck.login_code
            )
            db.session.add(profile)
            db.session.commit()
            result['status'] = 1
            result['msg'] = 'Succefully Added Profile.'
            driver = getdriver(link.deck.name)
            if (driver != None):
                if (link.deck.login_code > 0):
                    scheduler.add_job(
                        func=auto_rt,
                        kwargs={'profile_id': profile.id, 'driver': driver},
                        trigger=IntervalTrigger(minutes=profile.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})
                db.session.commit()
                result['status'] = -1
                result['msg'] = 'Driver is not available.'
            #send email
            # username = User.query.filter_by(id=link.userid).first().username
            # subject = "Deck row is submitted by %s with %s deck account." % (username, link.deck.name)
            # msg = "Deck row is submitted by %s with %s , %s minutes" % (
            #     username, json_data['keyword'], json_data['minutes'])
            # if (send_email(link.deck.email_address, msg, subject) != True):
            #     result['status'] = -1
            #     result['msg'] = 'Fail to send mail.'
    except:
        result['status'] = -1
        result['msg'] = 'Occured error in db session.'
    db.session.close()
    return jsonify({'result': result})
Esempio n. 2
0
def verifydeck():
    result = {}
    json_data = request.json
    deck = Deck.query.filter_by(id=json_data['deckid']).first()
    if (deck == None):
        result['status'] = -1
        result['msg'] = 'Deck does not existed.'
    else:
        driver = getdriver(deck.name)
        if (driver != None):
            login_code = verify_tweetdeck(deck.id, driver,
                                          json_data['code'])['code']
            if (login_code == 1):
                Deck.query.filter_by(id=json_data['deckid']).update(
                    {"login_code": login_code})
                profiles = (db.session.query(
                    Profile.id, Profile.minutes,
                    Link.deckid).join(Link)).filter_by(deckid=deck.id).all()
                for profile in profiles:
                    scheduler.add_job(
                        func=auto_rt,
                        kwargs={
                            'profile_id': profile.id,
                            'driver': driver
                        },
                        trigger=IntervalTrigger(minutes=profile.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})
                db.session.commit()
                result['status'] = 1
                result['msg'] = 'Success Verify Deck Account'
            elif (login_code == 0):
                result['status'] = 0
                result[
                    'msg'] = 'Cannot login to tweetdeck. Please check your password.'
            else:
                result['status'] = 0
                result['msg'] = 'Failed verification.'
        else:
            result['status'] = -1
            result['msg'] = 'Driver is not available.'
    return jsonify({'result': result})
Esempio n. 3
0
def changeDeckPass():
    result = {}
    json_data = request.json
    deck = Deck.query.filter_by(id=json_data['deckid']).first()
    if (deck == None):
        result['status'] = -1
        result['msg'] = 'Deck does not existed.'
    else:
        Deck.query.filter_by(id=json_data['deckid']).update(
            {"password": json_data['newpass']})
        result['status'] = 1
        result['msg'] = 'Succefully Updated Password.'
        db.session.commit()
        if (not getdriver(deck.name)):
            logindeck()
    db.session.close()
    return jsonify({'result': result})
Esempio n. 4
0
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})
Esempio n. 5
0
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})
Esempio n. 6
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})