Beispiel #1
0
def test_login_with_correct_data_post():
    app = Flask(__name__, template_folder='../src/templates')
    app.secret_key = "CS9163Assignment02WebsiteFlaskSessionSecretKeyForPytestOnly"
    app.WTF_CSRF_SECRET_KEY = "CS9163Assignment02WebsiteFlaskWTFCSRFToken"

    configure_routes(app)
    app.testing = True
    csrf = CSRFProtect(app)
    client = app.test_client()

    url = ROOT_URL + "/register"
    response = client.post(url,
                           data={
                               "uname": "testusername",
                               "pword": "testpassword",
                               "2fa": "testnumber"
                           })
    url = ROOT_URL + "/login"
    response = client.post(url,
                           data={
                               "uname": "testusername",
                               "pword": "testpassword",
                               "2fa": "testnumber"
                           },
                           follow_redirects=True)
    assert response.status_code == 200
    assert b"Login" in response.data
    assert b"Login success" in response.data
Beispiel #2
0
def test_spell_get():
    app = Flask(__name__, template_folder='../src/templates')
    app.secret_key = "CS9163Assignment02WebsiteFlaskSessionSecretKeyForPytestOnly"
    app.WTF_CSRF_SECRET_KEY = "CS9163Assignment02WebsiteFlaskWTFCSRFToken"

    app.testing = True
    configure_routes(app)
    csrf = CSRFProtect(app)
    client = app.test_client()

    url = ROOT_URL + "/spell_check"
    response = client.get(url, follow_redirects=True)
    assert response.status_code == 200
    assert b"Register" in response.data
    assert b"uname" in response.data
    assert b"pword" in response.data
    assert b"2fa" in response.data
from apscheduler.schedulers.blocking import BlockingScheduler

## declare static variables

## access tokens from twitter
access_token = "4415348663-5pNNm5YQLmGrBMwWuJ1yObWbaESTIw1fNSPPDA9"
access_token_secret = "gafJtISvaAdfUWuc9xsSpY2R1rHu5ICbhQEMDmqG8SWT3"
consumer_secret = "1Qhn2zclLLAs82mQPEKeThJbS5CdCyYYsWtVvQi7S4oVCDdFJU"
consumer_key = "6FiPNQ2wpHQSiBB58m31V0l1v"
HOURS = 24
screen_name = 'NowLivecodingtv'

# create the application object
app = Flask(__name__)
app.secret_key = "/\xfa-\x84\xfeW\xc3\xda\x11%/\x0c\xa0\xbaY\xa3\x89\x93$\xf5\x92\x9eW}"
app.WTF_CSRF_SECRET_KEY  = "secret_key"
app.CSRF_ENABLED = True
app.debug = True

## scheduler that runs every 24 hours and likes/RTs tweets
sched = BlockingScheduler()
@sched.scheduled_job('interval', hours = HOURS)
def timed_job():
    likeTweetTimelineTweets()
    
def in24Hours(d):
    """function to check if the tweet is older than a day/24 hours"""
    age = int(time.time() - (d - datetime(1970,1,1)).total_seconds())
    return age<86400

def likeTweetTimelineTweets():
Beispiel #4
0
from functools import wraps
from dbconnect import connection
import gc
import datetime
import pygal
from collections import Counter

app = Flask(__name__)
admin = Admin(app)
mail = Mail()
path = op.join(op.dirname(__file__), 'static/test')
admin.add_view(FileAdmin(path, '/static/test', name='Static Files'))

# set the secret key.  keep this really secret:
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
app.WTF_CSRF_SECRET_KEY = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
app.config['RECAPTCHA_PUBLIC_KEY'] = '6Ld14VEUAAAAACNJAmUPEAcFg1xRGSXUlN5rJSFw'
app.config[
    'RECAPTCHA_PRIVATE_KEY'] = '6Ld14VEUAAAAAOO5hyLVR-evTwtQVlaNQpwPcDfV'
#--mail--
app.config["MAIL_SERVER"] = "mail.btinternet.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = '******'
app.config["MAIL_PASSWORD"] = '******'

mail.init_app(app)


class RegistrationForm(Form):
    username = StringField('Username', [validators.Length(min=3, max=25)])
from threading import Thread
from mechanize import Browser
from flask.ext import excel
from unidecode import unidecode
from logging import FileHandler
from amazon.api import AmazonAPI
from werkzeug.serving import WSGIRequestHandler
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

# create the application object
app = Flask(__name__)
app.secret_key = "/\xfa-\x84\xfeW\xc3\xda\x11%/\x0c\xa0\xbaY\xa3\x89\x93$\xf5\x92\x9eW}"
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
app.WTF_CSRF_SECRET_KEY = "amazoneuapp"
app.CSRF_ENABLED = True
app.debug = True

AMAZON_ACCESS_KEY = 'AKIAIRGYI76BYPQZXAQQ'
AMAZON_SECRET_KEY = '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'
AMAZON_ASSOC_TAG = 273589934636

AMAZON_ACCESS_KEY1 = 'AKIAIYWGSVATZRMKAIRA'
AMAZON_SECRET_KEY1 = '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'
AMAZON_ASSOC_TAG1 = 289838321798

amazon_uk = AmazonAPI(AMAZON_ACCESS_KEY,
                      AMAZON_SECRET_KEY,
                      AMAZON_ASSOC_TAG,
                      region="UK")
Beispiel #6
0
		else:
			pass
		subprocess.call("rm -rf ./{}".format(_tmp_filename), shell=True)
		return out


# Create Flask app as a global variable.
# This enables app to be executed by command:
#   - export FLASK_APP=app.py
#   - flask run
app = Flask(__name__, template_folder="./templates")

# app.secret_key = "CS9163Assignment02WebsiteFlaskSessionSecretKey"
# app.WTF_CSRF_SECRET_KEY = "CS9163Assignment02WebsiteFlaskWTFCSRFToken"
app.secret_key = get_secret_key("flask_session_secret_key", "DefaultCS9163Assignment04SecretKey")
app.WTF_CSRF_SECRET_KEY = get_secret_key("flask_wtf_csrf_token", "DefaultCS9163Assignment04SecretKey")
# Random secret_key does work, but this will lose all existed sessions
# when current flask application restarts.
# app.secret_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(32))
# app.WTF_CSRF_SECRET_KEY = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(32))

app.config.update(
	SQLALCHEMY_DATABASE_URI='sqlite:///sqlite3/cs9163.sqlite3'
)

app.config.update(
	SESSION_COOKIE_HTTPONLY=True,
	SESSION_COOKIE_SAMESITE='Lax',
	PERMANENT_SESSION_LIFETIME=600
)
csrf = CSRFProtect(app)
Beispiel #7
0
        # Create and set result to the command which finds all the articles created by a specific user
        result = cur.execute("SELECT * FROM articles WHERE author = %s",
                             [username])
        # Set articles to all the articles associated with that user
        articles = cur.fetchall()
        # Close the connection
        cur.close()
        # Return the jsonify of the articles by that user
        return jsonify({'Forum Posts': articles})
    # Conditional else statement
    else:
        # Create a cursor object
        cur = mysql.connection.cursor()
        # Set result variable to the command which selects all the articles
        result = cur.execute("SELECT * FROM articles")
        # Set articles to all of the articles
        articles = cur.fetchall()
        # Close the connection
        cur.close()
        # Return the jsonify of all the articles
        return jsonify({'Article Posts': articles})


# Check if the python file is valid (Also contains the debug=True)
if __name__ == '__main__':
    # app.secret_key='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
    # Secret key for CSRF
    app.WTF_CSRF_SECRET_KEY = 'shakilsecret'
    # Set debug to true
    app.run(debug=False, host='0.0.0.0', port=8000)
searchString = '%27Xbox+One%27'
top = 20
offset = 0

url = 'https://api.datamarket.azure.com/Bing/Search/Image?' + \
      'Query=%s&$top=%d&$skip=%d&$format=json' % (searchString, top, offset)


reload(sys)
sys.setdefaultencoding('utf-8')

# create the application object
app = Flask(__name__)
app.secret_key = "/\xfa-\x84\xfeW\xc3\xda\x11%/\x0c\xa0\xbaY\xa3\x89\x93$\xf5\x92\x9eW}"
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
app.WTF_CSRF_SECRET_KEY  = "spinningbot"
app.CSRF_ENABLED = True
app.debug = True


@app.route('/', methods=['GET'])
def home():
    """ flask view for the home page"""
    return render_template('index_2.html')

def getGoodURLs(include, exclude, urls):
    return_urls = []
    for url in urls:
        if ((any(word in url for word in include)) and (not (any(word in url for word in exclude)))):
            return_urls.append(url)
Beispiel #9
0
        out, err = proc.communicate()
        if err == b'':
            out = out.decode().replace('\n', ',')
        else:
            pass
        subprocess.call("rm -rf ./{}".format(_tmp_filename), shell=True)
        return out


# Create Flask app as a global variable.
# This enables app to be executed by command:
#   - export FLASK_APP=app.py
#   - flask run
app = Flask(__name__, template_folder="./templates")
app.secret_key = "CS9163Assignment02WebsiteFlaskSessionSecretKey"
app.WTF_CSRF_SECRET_KEY = "CS9163Assignment02WebsiteFlaskWTFCSRFToken"
# Random secret_key does work, but this will lose all existed sessions
# when current flask application restarts.
# app.secret_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(32))
# app.WTF_CSRF_SECRET_KEY = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(32))

app.config.update(SQLALCHEMY_DATABASE_URI='sqlite:///sqlite3/cs9163.sqlite3')

app.config.update(SESSION_COOKIE_HTTPONLY=True,
                  SESSION_COOKIE_SAMESITE='Lax',
                  PERMANENT_SESSION_LIFETIME=600)
csrf = CSRFProtect(app)
paranoid = Paranoid(app)
configure_routes(app)
paranoid.redirect_view = ROOT_URL + '/login'
Beispiel #10
0
import os 
from flask import Flask, render_template, send_from_directory, request, flash, redirect, url_for
from flask.ext.basicauth import BasicAuth

app = Flask(__name__)

app.secret_key = "notemetaipo"
app.CSRF_ENABLED = True
app.WTF_CSRF_SECRET_KEY = '*YQUIHDHQYP#*p94uUOI'

app.config.update(
    DEBUG=True
)

app.config['BASIC_AUTH_USERNAME'] = '******'
app.config['BASIC_AUTH_PASSWORD'] = ''
basic_auth = BasicAuth(app)

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

    
@app.route("/", methods=['GET', 'POST'])
def index():
    return render_template('index.html')
    
@app.route("/basics", methods=['GET', 'POST'])
@basic_auth.required
def basics():
    return render_template('basics.html')
Beispiel #11
0
import os
from flask import Flask, render_template, send_from_directory, request, flash, redirect, url_for
from flask.ext.basicauth import BasicAuth

app = Flask(__name__)

app.secret_key = "notemetaipo"
app.CSRF_ENABLED = True
app.WTF_CSRF_SECRET_KEY = '*YQUIHDHQYP#*p94uUOI'

app.config.update(DEBUG=True)

app.config['BASIC_AUTH_USERNAME'] = '******'
app.config['BASIC_AUTH_PASSWORD'] = ''
basic_auth = BasicAuth(app)


@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404


@app.route("/", methods=['GET', 'POST'])
def index():
    return render_template('index.html')


@app.route("/basics", methods=['GET', 'POST'])
@basic_auth.required
def basics():
    return render_template('basics.html')
Beispiel #12
0
import os 
from flask import Flask, render_template, send_from_directory, request, flash, redirect, url_for
import MySQLdb
#from events import *
from marketsim import analysis
from forms import InputForm
from find_events import *
from kalman import *
from util import *
from flask import jsonify

app = Flask(__name__)

app.secret_key = "talca"
app.CSRF_ENABLED = True
app.WTF_CSRF_SECRET_KEY = 'a random string'

app.config.update(
    DEBUG=True
)

con = mdb.connect(host='localhost', user='******', db='stocks2')
cur = con.cursor()

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

    
@app.route("/", methods=['GET', 'POST'])
def index():