New version
This commit is contained in:
parent
c4271ae3ee
commit
148267d8d7
@ -10,6 +10,10 @@ class LoginForm(FlaskForm):
|
|||||||
remember_me = BooleanField('Remember Me')
|
remember_me = BooleanField('Remember Me')
|
||||||
submit = SubmitField('Sign In')
|
submit = SubmitField('Sign In')
|
||||||
|
|
||||||
|
class SearchForm(FlaskForm):
|
||||||
|
username = StringField('Username')
|
||||||
|
submit = SubmitField('Search')
|
||||||
|
|
||||||
|
|
||||||
class RegistrationForm(FlaskForm):
|
class RegistrationForm(FlaskForm):
|
||||||
username = StringField('Username', validators=[DataRequired()])
|
username = StringField('Username', validators=[DataRequired()])
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from flask_login import login_user, logout_user, current_user, login_required
|
from flask_login import login_user, logout_user, current_user, login_required
|
||||||
from flask import render_template, flash, redirect, url_for, request
|
from flask import render_template, flash, redirect, url_for, request
|
||||||
from app.forms import LoginForm, RegistrationForm, EmptyForm
|
from app.forms import LoginForm, RegistrationForm, EmptyForm, SearchForm
|
||||||
from app.models import User, twitterPost
|
from app.models import User, twitterPost
|
||||||
from werkzeug.urls import url_parse
|
from werkzeug.urls import url_parse
|
||||||
from flask import Markup
|
from flask import Markup
|
||||||
@ -132,16 +132,66 @@ def unfollow(username):
|
|||||||
return redirect(url_for('user', username=username))
|
return redirect(url_for('user', username=username))
|
||||||
current_user.unfollow(user)
|
current_user.unfollow(user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('You are not following {}.'.format(username))
|
flash('You are no longer following {}.'.format(username))
|
||||||
return redirect(url_for('user', username=username))
|
return redirect(url_for('user', username=username))
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
@app.route('/unfollowList/<username>', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def unfollowList(username):
|
||||||
|
form = EmptyForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
user = User.query.filter_by(username=username).first()
|
||||||
|
if user is None:
|
||||||
|
flash('User {} not found.'.format(username))
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
if user == current_user:
|
||||||
|
flash('You cannot unfollow yourself!')
|
||||||
|
return redirect(url_for('user', username=username))
|
||||||
|
current_user.unfollow(user)
|
||||||
|
db.session.commit()
|
||||||
|
flash('You are no longer following {}!'.format(username))
|
||||||
|
return redirect(url_for('following'))
|
||||||
|
else:
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
@app.route('/following')
|
||||||
|
@login_required
|
||||||
|
def following():
|
||||||
|
form = EmptyForm()
|
||||||
|
following = current_user.following_list()
|
||||||
|
followed = current_user.followed.count()
|
||||||
|
return render_template('following.html', accounts = following, count = followed, form = form)
|
||||||
|
|
||||||
|
@app.route('/search', methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
def search():
|
||||||
|
form = SearchForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
user = form.username.data
|
||||||
|
if isTwitterUser(user):
|
||||||
|
return redirect(url_for('user', username=user))
|
||||||
|
else:
|
||||||
|
flash("User {} does not exist!".format(user))
|
||||||
|
return render_template('search.html', form = form)
|
||||||
|
else:
|
||||||
|
return render_template('search.html', form = form)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/notfound')
|
||||||
|
def notfound():
|
||||||
|
return render_template('404.html')
|
||||||
|
|
||||||
@app.route('/user/<username>')
|
@app.route('/user/<username>')
|
||||||
@login_required
|
@login_required
|
||||||
def user(username):
|
def user(username):
|
||||||
user = User.query.filter_by(username=username).first()
|
user = User.query.filter_by(username=username).first()
|
||||||
isTwitter = True
|
isTwitter = True
|
||||||
|
rssFeed = feedparser.parse('https://nitter.net/{}/rss'.format(username))
|
||||||
|
if rssFeed.entries == []:
|
||||||
|
isTwitter = False
|
||||||
if user is None and isTwitter:
|
if user is None and isTwitter:
|
||||||
x = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(16))
|
x = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(16))
|
||||||
newUser = User(username=username, email="{}@person.is".format(x))
|
newUser = User(username=username, email="{}@person.is".format(x))
|
||||||
@ -149,6 +199,9 @@ def user(username):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
#flash('User {} not found.'.format(username))
|
#flash('User {} not found.'.format(username))
|
||||||
|
|
||||||
|
elif not isTwitter and user is None:
|
||||||
|
return redirect(url_for('notfound'))
|
||||||
|
|
||||||
#Gather profile info.
|
#Gather profile info.
|
||||||
rssFeed = feedparser.parse('https://nitter.net/{}/rss'.format(username))
|
rssFeed = feedparser.parse('https://nitter.net/{}/rss'.format(username))
|
||||||
|
|
||||||
@ -177,6 +230,7 @@ def user(username):
|
|||||||
posts.append(newPost)
|
posts.append(newPost)
|
||||||
|
|
||||||
form = EmptyForm()
|
form = EmptyForm()
|
||||||
|
user = User.query.filter_by(username=username).first()
|
||||||
return render_template('user.html', user=user, posts=posts, form=form, profilePic=rssFeed.channel.image.url)
|
return render_template('user.html', user=user, posts=posts, form=form, profilePic=rssFeed.channel.image.url)
|
||||||
|
|
||||||
def getTimeDiff(t):
|
def getTimeDiff(t):
|
||||||
@ -194,4 +248,10 @@ def getTimeDiff(t):
|
|||||||
timeString = "{}m".format(minutes)
|
timeString = "{}m".format(minutes)
|
||||||
else:
|
else:
|
||||||
timeString = "{}d".format(diff.days)
|
timeString = "{}d".format(diff.days)
|
||||||
return timeString
|
return timeString
|
||||||
|
|
||||||
|
def isTwitterUser(username):
|
||||||
|
rssFeed = feedparser.parse('https://nitter.net/{}/rss'.format(username))
|
||||||
|
if rssFeed.entries == []:
|
||||||
|
return False
|
||||||
|
return True
|
BIN
app/static/img/404.png
Normal file
BIN
app/static/img/404.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
10
app/templates/404.html
Normal file
10
app/templates/404.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div style="margin-top: 2em;" class="ui one column centered grid">
|
||||||
|
<img class="ui medium circular image" src="{{ url_for('static',filename='img/404.png') }}">
|
||||||
|
</div>
|
||||||
|
<div style="margin: 1.5em;" class="ui one column centered grid">
|
||||||
|
<h2 class="ui header">This page is not on the map.</h2>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -3,7 +3,7 @@
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="extra content">
|
<div class="extra content">
|
||||||
<div class="left floated author">
|
<div class="left floated author">
|
||||||
<img class="ui avatar image" src="{{ url_for('static',filename='img/avatars/')}}{{range(1, 10) | random}}.png">
|
<img class="ui avatar image" src="{{ url_for('static',filename='img/avatars/')}}{{range(1, 12) | random}}.png">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="header" id="author"><a href="{{ post.urlToPost }}">{{ post.op }}</a></div>
|
<div class="header" id="author"><a href="{{ post.urlToPost }}">{{ post.op }}</a></div>
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
{% if current_user.is_anonymous %}
|
{% if current_user.is_anonymous %}
|
||||||
<a href="{{ url_for('login') }}" class="item">Login</a>
|
<a href="{{ url_for('login') }}" class="item">Login</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
<a href="{{ url_for('search') }}" class="item">Search</a>
|
||||||
|
<a href="{{ url_for('following') }}" class="item">Following</a>
|
||||||
<a href="{{ url_for('logout') }}" class="item">Logout</a>
|
<a href="{{ url_for('logout') }}" class="item">Logout</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
35
app/templates/following.html
Normal file
35
app/templates/following.html
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div style="margin: 0em;" class="ui one column centered grid">
|
||||||
|
<div style="margin-top: 1em;" class="row">
|
||||||
|
<img class="ui tiny circular image" src="{{ url_for('static',filename='img/avatars/')}}{{range(1, 12) | random}}.png">
|
||||||
|
</div>
|
||||||
|
<div style="margin: 1.5em;" class="row">
|
||||||
|
<h2 class="ui header">Accounts you follow ({{ count }}):</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div style="margin: 0em;" class="ui one column centered grid">
|
||||||
|
<div class="ui middle aligned divided list">
|
||||||
|
{% for acc in accounts %}
|
||||||
|
<div class="item">
|
||||||
|
<div class="right floated content">
|
||||||
|
<p>
|
||||||
|
<form action="{{ url_for('unfollowList', username=acc.username) }}" method="post">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ form.submit(value='Unfollow') }}
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<img class="ui avatar image" src="{{ url_for('static',filename='img/avatars/')}}{{range(1, 12) | random}}.png">
|
||||||
|
<div class="content">
|
||||||
|
{{acc.username}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
18
app/templates/search.html
Normal file
18
app/templates/search.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="ui one column centered grid">
|
||||||
|
<form class="ui form" action="" method="post" novalidate>
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
<p>
|
||||||
|
{{ form.username.label }}<br>
|
||||||
|
{{ form.username(size=32) }}<br>
|
||||||
|
{% for error in form.username.errors %}
|
||||||
|
<span style="color: red;">[{{ error }}]</span>
|
||||||
|
{% endfor %}
|
||||||
|
</p>
|
||||||
|
<p>{{ form.submit() }}</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
Reference in New Issue
Block a user