add closed registrations

This commit is contained in:
pluja 2020-08-30 01:15:48 +02:00
parent 47cd3c0732
commit c82640991f
7 changed files with 64 additions and 51 deletions

View File

@ -22,12 +22,12 @@ import urllib
import json import json
import re import re
# Instances - Format must be instance.tld (No '/' and no 'https://') ##########################
nitterInstance = "https://nitter.net/" #### Config variables ####
nitterInstanceII = "https://nitter.mastodont.cat/" ##########################
NITTERINSTANCE = "https://nitter.net/" # Must be https://.../
ytChannelRss = "https://www.youtube.com/feeds/videos.xml?channel_id=" YOUTUBERSS = "https://www.youtube.com/feeds/videos.xml?channel_id="
invidiousInstance = "invidio.us" REGISTRATIONS = False
########################## ##########################
#### Global variables #### #### Global variables ####
@ -457,7 +457,7 @@ def register():
db.session.commit() db.session.commit()
flash('Congratulations, you are now a registered user!') flash('Congratulations, you are now a registered user!')
return redirect(url_for('login')) return redirect(url_for('login'))
return render_template('register.html', title='Register', form=form) return render_template('register.html', title='Register', registrations=REGISTRATIONS, form=form)
@app.route('/error/<errno>') @app.route('/error/<errno>')
def error(errno): def error(errno):
@ -476,14 +476,14 @@ def getTimeDiff(t):
return timeString return timeString
def isTwitterUser(username): def isTwitterUser(username):
response = requests.get('{instance}{user}/rss'.format(instance=nitterInstance, user=username)) response = requests.get('{instance}{user}/rss'.format(instance=NITTERINSTANCE, user=username))
if response.status_code == 404: if response.status_code == 404:
return False return False
return True return True
def twitterUserSearch(terms): def twitterUserSearch(terms):
response = urllib.request.urlopen('{instance}search?f=users&q={user}'.format(instance=nitterInstance, user=urllib.parse.quote(terms))).read() response = urllib.request.urlopen('{instance}search?f=users&q={user}'.format(instance=NITTERINSTANCE, user=urllib.parse.quote(terms))).read()
html = BeautifulSoup(str(response), "lxml") html = BeautifulSoup(str(response), "lxml")
results = [] results = []
@ -495,14 +495,14 @@ def twitterUserSearch(terms):
user = { user = {
"fullName": item.find('a', attrs={'class':'fullname'}).getText().encode('latin_1').decode('unicode_escape').encode('latin_1').decode('utf8'), "fullName": item.find('a', attrs={'class':'fullname'}).getText().encode('latin_1').decode('unicode_escape').encode('latin_1').decode('utf8'),
"username": item.find('a', attrs={'class':'username'}).getText().encode('latin_1').decode('unicode_escape').encode('latin_1').decode('utf8'), "username": item.find('a', attrs={'class':'username'}).getText().encode('latin_1').decode('unicode_escape').encode('latin_1').decode('utf8'),
'avatar': "{i}{s}".format(i=nitterInstance, s=item.find('img', attrs={'class':'avatar'})['src'][1:]) 'avatar': "{i}{s}".format(i=NITTERINSTANCE, s=item.find('img', attrs={'class':'avatar'})['src'][1:])
} }
results.append(user) results.append(user)
return results return results
def getTwitterUserInfo(username): def getTwitterUserInfo(username):
response = urllib.request.urlopen('{instance}{user}'.format(instance=nitterInstance, user=username)).read() response = urllib.request.urlopen('{instance}{user}'.format(instance=NITTERINSTANCE, user=username)).read()
#rssFeed = feedparser.parse(response.content) #rssFeed = feedparser.parse(response.content)
html = BeautifulSoup(str(response), "lxml") html = BeautifulSoup(str(response), "lxml")
@ -529,14 +529,14 @@ def getTwitterUserInfo(username):
"following":html.find_all('span', attrs={'class':'profile-stat-num'})[1].string, "following":html.find_all('span', attrs={'class':'profile-stat-num'})[1].string,
"followers":numerize.numerize(int(html.find_all('span', attrs={'class':'profile-stat-num'})[2].string.replace(",",""))), "followers":numerize.numerize(int(html.find_all('span', attrs={'class':'profile-stat-num'})[2].string.replace(",",""))),
"likes":html.find_all('span', attrs={'class':'profile-stat-num'})[3].string, "likes":html.find_all('span', attrs={'class':'profile-stat-num'})[3].string,
"profilePic":"{instance}{pic}".format(instance=nitterInstance, pic=html.find('a', attrs={'class':'profile-card-avatar'})['href'][1:]) "profilePic":"{instance}{pic}".format(instance=NITTERINSTANCE, pic=html.find('a', attrs={'class':'profile-card-avatar'})['href'][1:])
} }
return user return user
def getFeed(urls): def getFeed(urls):
feedPosts = [] feedPosts = []
with FuturesSession() as session: with FuturesSession() as session:
futures = [session.get('{instance}{user}'.format(instance=nitterInstance, user=u.username)) for u in urls] futures = [session.get('{instance}{user}'.format(instance=NITTERINSTANCE, user=u.username)) for u in urls]
for future in as_completed(futures): for future in as_completed(futures):
res = future.result().content.decode('utf-8') res = future.result().content.decode('utf-8')
html = BeautifulSoup(res, "html.parser") html = BeautifulSoup(res, "html.parser")
@ -566,8 +566,8 @@ def getFeed(urls):
newPost.username = newPost.op newPost.username = newPost.op
newPost.isRT = False newPost.isRT = False
newPost.profilePic = nitterInstance+post.find('a', attrs={'class':'tweet-avatar'}).find('img')['src'][1:] newPost.profilePic = NITTERINSTANCE+post.find('a', attrs={'class':'tweet-avatar'}).find('img')['src'][1:]
newPost.url = nitterInstance + post.find('a', attrs={'class':'tweet-link'})['href'][1:] newPost.url = NITTERINSTANCE + post.find('a', attrs={'class':'tweet-link'})['href'][1:]
if post.find('div', attrs={'class':'quote'}): if post.find('div', attrs={'class':'quote'}):
newPost.isReply = True newPost.isReply = True
quote = post.find('div', attrs={'class':'quote'}) quote = post.find('div', attrs={'class':'quote'})
@ -575,7 +575,7 @@ def getFeed(urls):
newPost.replyingTweetContent = Markup(quote.find('div', attrs={'class':'quote-text'})) newPost.replyingTweetContent = Markup(quote.find('div', attrs={'class':'quote-text'}))
if quote.find('a', attrs={'class':'still-image'}): if quote.find('a', attrs={'class':'still-image'}):
newPost.replyAttachedImg = nitterInstance+quote.find('a', attrs={'class':'still-image'})['href'][1:] newPost.replyAttachedImg = NITTERINSTANCE+quote.find('a', attrs={'class':'still-image'})['href'][1:]
newPost.replyingUser=quote.find('a', attrs={'class':'username'}).text newPost.replyingUser=quote.find('a', attrs={'class':'username'}).text
post.find('div', attrs={'class':'quote'}).decompose() post.find('div', attrs={'class':'quote'}).decompose()
@ -583,7 +583,7 @@ def getFeed(urls):
if post.find('div', attrs={'class':'attachments'}): if post.find('div', attrs={'class':'attachments'}):
if not post.find(class_='quote'): if not post.find(class_='quote'):
if post.find('div', attrs={'class':'attachments'}).find('a', attrs={'class':'still-image'}): if post.find('div', attrs={'class':'attachments'}).find('a', attrs={'class':'still-image'}):
newPost.attachedImg = nitterInstance + post.find('div', attrs={'class':'attachments'}).find('a')['href'][1:] newPost.attachedImg = NITTERINSTANCE + post.find('div', attrs={'class':'attachments'}).find('a')['href'][1:]
feedPosts.append(newPost) feedPosts.append(newPost)
return feedPosts return feedPosts
@ -592,7 +592,7 @@ def getPosts(account):
posts = [] posts = []
#Gather profile info. #Gather profile info.
rssFeed = feedparser.parse('{instance}{user}/rss'.format(instance=nitterInstance, user=account)) rssFeed = feedparser.parse('{instance}{user}/rss'.format(instance=NITTERINSTANCE, user=account))
#Gather posts #Gather posts
if rssFeed.entries != []: if rssFeed.entries != []:
for post in rssFeed.entries: for post in rssFeed.entries:

BIN
app/static/img/closed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -0,0 +1,9 @@
<div class="ui center aligned text container">
<div class="ui row">
<img class="ui image" src="{{ url_for('static',filename='img/closed.png') }}">
</div>
<div class="ui row">
<h2 class="ui header">Registrations are currently closed.</h2>
</div>
</div>

View File

@ -1,9 +1,9 @@
<div style="margin-top: 2em;" class="ui one column centered grid"> <div class="ui text container">
<div style="margin: 1.5em;" class="ui row"> <div class="ui row">
<img class="ui medium circular image" src="{{ url_for('static',filename='img/empty.png') }}"> <img class="ui medium circular image" src="{{ url_for('static',filename='img/empty.png') }}">
</div> </div>
<div style="margin: 1.5em;" class="ui row"> <div class="ui row">
<h2 class="ui header">This feed is empty.</h2> <h2 class="ui header">This feed is empty.</h2>
</div> </div>
</div> </div>

View File

@ -1,32 +1,36 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<h2 class="ui centered header">Register</h2> {% if registrations %}
<div class="ui one column centered grid" id="container"> <h2 class="ui centered header">Register</h2>
<form class="ui form" action="" method="post"> <div class="ui text container" id="container">
{{ form.hidden_tag() }} <form class="ui form" action="" method="post">
<p> {{ form.hidden_tag() }}
{{ form.username.label }}<br> <p>
{{ form.username(size=32) }}<br> {{ form.username.label }}<br>
{% for error in form.username.errors %} {{ form.username(size=32) }}<br>
<span style="color: red;">[{{ error }}]</span> {% for error in form.username.errors %}
{% endfor %} <span style="color: red;">[{{ error }}]</span>
</p> {% endfor %}
<p> </p>
{{ form.password.label }}<br> <p>
{{ form.password(size=32) }}<br> {{ form.password.label }}<br>
{% for error in form.password.errors %} {{ form.password(size=32) }}<br>
<span style="color: red;">[{{ error }}]</span> {% for error in form.password.errors %}
{% endfor %} <span style="color: red;">[{{ error }}]</span>
</p> {% endfor %}
<p> </p>
{{ form.password2.label }}<br> <p>
{{ form.password2(size=32) }}<br> {{ form.password2.label }}<br>
{% for error in form.password2.errors %} {{ form.password2(size=32) }}<br>
<span style="color: red;">[{{ error }}]</span> {% for error in form.password2.errors %}
{% endfor %} <span style="color: red;">[{{ error }}]</span>
</p> {% endfor %}
<p>{{ form.submit() }}</p> </p>
</form> <p>{{ form.submit() }}</p>
</div> </form>
</div>
{% else %}
{% include '_closed_registrations.html' %}
{% endif %}
{% endblock %} {% endblock %}

View File

@ -30,7 +30,7 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -8,7 +8,7 @@
<video class="video-js vjs-default-skin" <video class="video-js vjs-default-skin"
data-setup='{ "playbackRates": [0.5, 1, 1.25,1.5, 2] }' data-setup='{ "playbackRates": [0.5, 1, 1.25,1.5, 2] }'
width="1080" width="1080"
controls = "1" controls
buffered buffered
preload="none"> preload="none">
<source src="/stream?v={{video.id}}" type="video/mp4"> <source src="/stream?v={{video.id}}" type="video/mp4">