forked from DadesUPC/140stories
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (49 loc) · 1.78 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from flask import Flask, render_template, redirect, url_for, request
from werkzeug import secure_filename
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from utils import values
import os
app = Flask(__name__)
app.config.from_pyfile('utils/config.py')
db = SQLAlchemy(app)
migrate = Migrate(app, db)
from utils import models, db_handler
db.create_all()
@app.route('/')
def home():
return render_template('index.html')
@app.route('/newstory/', methods=['GET', 'POST'])
def newstory():
if request.method == 'POST':
title = request.form['title']
text = request.form['text']
captcha = request.form['g-recaptcha-response']
captcha_check = db_handler.checkCaptcha(captcha)
if len(text) > 140:
return render_template('fuckyou.html', err=values.max_exceeded)
if captcha_check is False:
return render_template('fuckyou.html', err=values.wrong_captcha)
story_id = db_handler.newStory(title, text)
return redirect('/continue/' + story_id + '/')
else:
return render_template('newstory.html')
@app.route('/continue/<id>/')
def continueStory(id):
if id == '0':
story = db_handler.getRandomStory()
return redirect('/continue/' + story.story_id + '/')
else:
story = db_handler.getStoryByStoryID(id)
return render_template('continue.html', story=story)
@app.route('/add/<id>/', methods=['POST'])
def addToStory(id):
text = request.form['text']
print(text)
if len(text) > 140:
return render_template('fuckyou.html', err=values.max_exceeded)
db_handler.newTweet(text, id)
return redirect('/continue/' + id + '/')
@app.errorhandler(404)
def page_not_found(e):
return (render_template('notfound.html'))