예제 #1
0
def database():
    form = SearchForm()
    if form.validate_on_submit(
    ):  # if validates on sub then put it in lowercase and take the "@" sign if there is one
        form.username.data = form.username.data.lower()
        if form.username.data[0] == "@":
            form.username.data = form.username.data[1:]
        try:
            # if the user exists then report them
            scanning.get_twitter_info(form.username.data)
            return redirect(
                url_for("database_search", username=form.username.data,
                        page=1))
        except:
            flash(f"Sorry. That account does not exist", "danger")
    elif form.submit.data:
        flash(f"Sorry. That username is invalid.", "danger")
    page = request.args.get("page", 1, type=int)
    # fetch a paginated list of recent reports in order of date submitted desc
    reports = Report.query.order_by(
        Report.date_submitted.desc()).paginate(per_page=5)
    return render_template('database.html',
                           form=form,
                           reports=reports,
                           title="Database")
예제 #2
0
def report():
    form = ReportForm()  # form to report an account
    if form.validate_on_submit():  # if form val on submit
        form.username.data = form.username.data.lower(
        )  # turn input to lowercase
        if form.username.data[
                0] == "@":  # if username was entered with an @ at the start
            form.username.data = form.username.data[1:]  # remove it
        try:
            # check if account exists
            scanning.get_twitter_info(form.username.data)
            report = Report(
                account_id=form.username.data,
                threat_type=form.threat_field.data,
                summary=form.summary.data,
                author=current_user)  # make report for account if it does
            db.session.add(report)  # then add report
            db.session.commit()  # commit changes
            # show a flash message that the operation was a success
            flash(f"Report Submitted For @{form.username.data}!", "success")
            return redirect(url_for("database"))
        except:
            # if account doesn't exist then flash this
            flash(f"Sorry. That account does not exist", "danger")
    elif form.summary.data is not None:
        if len(form.summary.data) < 10:
            flash(f"Summary must contain a minimum of 10 characters",
                  "danger")  # flash if summary not long enough
        else:
            flash(f"Sorry. That username is invalid.",
                  "danger")  # if username is invalid then flash this
    return render_template('report.html', form=form, title="Make A Report")
예제 #3
0
def report_ranked():
    page = request.args.get("page", 1, type=int)
    count = db.session.query(
        Report.account_id,
        func.count(Report.account_id).label("total")
    ).group_by(
        Report.account_id
    )  # this gets the total reports grouped by account, ordered by total reports
    # it is a list of tuples (screen_name, count)
    count = count.order_by(desc('total'))
    # this variable is just a paginated version of count^
    counts2 = count.paginate(per_page=5)
    user_profiles = []
    for tup in count:  # for tuple in count variable
        # get the twitter profile of the screen_name
        user_profile = scanning.get_twitter_info(tup[0])
        user_profiles.append(user_profile)  # add it to a list
    length = len(user_profiles)
    return render_template('report_ranked.html',
                           count=count,
                           counts2=counts2,
                           user_profiles=user_profiles,
                           length=length,
                           page=page,
                           title="Reports Ranked")
예제 #4
0
def database_search(username):
    page = request.args.get("page", 1, type=int)
    if Report.query.filter_by(account_id=username).first() != None:
        reports = Report.query.filter_by(account_id=username).order_by(
            Report.date_submitted.desc()).paginate(per_page=5)
        # returns list of all recently submitted reports
    else:
        reports = None
    user_profile = scanning.get_twitter_info(username)
    return render_template('database_search.html',
                           reports=reports,
                           user_profile=user_profile,
                           title="Database Search")
예제 #5
0
def scan_all(username, follower_count):
    # get x most recent followers ids for target's account
    followers = scanning.get_followers(username, follower_count)
    # scan all these followers and save results
    scan_results = scanning.scan_all_function(followers)
    user_profile = scanning.get_twitter_info(
        username)  # get the user's profile
    # get the length of the scan results (to iterate through list on the html page)
    length = len(scan_results)
    return render_template('scan_all.html',
                           user_profile=user_profile,
                           length=length,
                           scan_results=scan_results,
                           title="Scan All")
예제 #6
0
def process_followers():
    form = request.form
    # Creates a list with the usernames of the users selected
    followers = list(form.keys())
    # Logged in username, which is sent in the form as a hidden field
    username = followers.pop(0)
    user_profile = scanning.get_twitter_info(username)
    scan_results = scanning.scan_all_function(followers)
    length = len(scan_results)
    return render_template('scan_all.html',
                           user_profile=user_profile,
                           length=length,
                           scan_results=scan_results,
                           title="Scan All")
예제 #7
0
def my_reports():
    # set author to current user
    author = User.query.filter_by(username=current_user.username).first()
    page = request.args.get("page", 1, type=int)
    # fileter database report by this user as author
    if Report.query.filter_by(author=author).first() != None:
        reports = Report.query.filter_by(author=author).order_by(
            Report.date_submitted.desc()).paginate(per_page=5)
    else:
        reports = None
    user_profile = scanning.get_twitter_info(author.username)
    return render_template('database_search.html',
                           reports=reports,
                           user_profile=user_profile,
                           title="My Reports")
예제 #8
0
def scan_choose(username):
    # slider for choosing the amount of recent followers to scan in an account
    slider_form = SliderForm()
    if slider_form.submit.data:  # if user submits slider
        # redirect to scan_all page with x amount of followers to scan
        return redirect(
            url_for("scan_all",
                    username=username,
                    follower_count=slider_form.follower_count.data))
    # returns list of followers screen_name's
    followers = scanning.get_followers(username)
    follower_profiles = []
    user_profile = scanning.get_twitter_info(
        username)  # fetch the info of the person making the scan
    for i in range(len(followers)):
        # get the twitter profile of all the follower's that there is an option of being scanned
        follower_profile = scanning.get_twitter_info(followers[i])
        # so that the user can click and select them
        follower_profiles.append(follower_profile)
    return render_template("scan_choose.html",
                           follower_list=follower_profiles,
                           form=slider_form,
                           user_profile=user_profile,
                           title="Choose Followers To Scan")