Several upgrades
This commit is contained in:
parent
7b28f482b1
commit
ae2a4e86a9
@ -132,7 +132,7 @@ class ytPost():
|
|||||||
class youtubeFollow(db.Model):
|
class youtubeFollow(db.Model):
|
||||||
__tablename__ = 'channel'
|
__tablename__ = 'channel'
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
channelId = db.Column(db.String(30), nullable=False, unique=True)
|
channelId = db.Column(db.String(30), nullable=False)
|
||||||
channelName = db.Column(db.String(30))
|
channelName = db.Column(db.String(30))
|
||||||
followers = db.relationship('User',
|
followers = db.relationship('User',
|
||||||
secondary=channel_association,
|
secondary=channel_association,
|
||||||
@ -144,7 +144,7 @@ class youtubeFollow(db.Model):
|
|||||||
class twitterFollow(db.Model):
|
class twitterFollow(db.Model):
|
||||||
__tablename__ = 'twitterAccount'
|
__tablename__ = 'twitterAccount'
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
username = db.Column(db.String(30), unique=True)
|
username = db.Column(db.String(30), nullable=False)
|
||||||
followers = db.relationship('User',
|
followers = db.relationship('User',
|
||||||
secondary=twitter_association,
|
secondary=twitter_association,
|
||||||
back_populates="twitterFollowed")
|
back_populates="twitterFollowed")
|
||||||
|
@ -19,8 +19,8 @@ import json
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
# Instances - Format must be instance.tld (No '/' and no 'https://')
|
# Instances - Format must be instance.tld (No '/' and no 'https://')
|
||||||
nitterInstance = "https://nitter.net/"
|
nitterInstanceII = "https://nitter.net/"
|
||||||
nitterInstanceII = "https://nitter.mastodont.cat/"
|
nitterInstance = "https://nitter.mastodont.cat/"
|
||||||
|
|
||||||
ytChannelRss = "https://www.youtube.com/feeds/videos.xml?channel_id="
|
ytChannelRss = "https://www.youtube.com/feeds/videos.xml?channel_id="
|
||||||
invidiousInstance = "invidio.us"
|
invidiousInstance = "invidio.us"
|
||||||
@ -92,24 +92,23 @@ def deleteSaved(id):
|
|||||||
def follow(username):
|
def follow(username):
|
||||||
form = EmptyForm()
|
form = EmptyForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
if twFollow(username):
|
if followTwitterAccount(username):
|
||||||
flash("{} followed!".format(username))
|
flash("{} followed!".format(username))
|
||||||
else:
|
|
||||||
flash("Something went wrong...")
|
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
|
|
||||||
def twFollow(username):
|
def followTwitterAccount(username):
|
||||||
if isTwitterUser(username):
|
if isTwitterUser(username):
|
||||||
try:
|
if not current_user.is_following_tw(username):
|
||||||
follow = twitterFollow()
|
try:
|
||||||
follow.username = username
|
follow = twitterFollow()
|
||||||
follow.followers.append(current_user)
|
follow.username = username
|
||||||
db.session.add(follow)
|
follow.followers.append(current_user)
|
||||||
db.session.commit()
|
db.session.add(follow)
|
||||||
return True
|
db.session.commit()
|
||||||
except:
|
return True
|
||||||
flash("Couldn't follow {}. Maybe you are already following!".format(username))
|
except:
|
||||||
return False
|
flash("Twitter: Couldn't follow {}. Already followed?".format(username))
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
flash("Something went wrong... try again")
|
flash("Something went wrong... try again")
|
||||||
return False
|
return False
|
||||||
@ -121,8 +120,6 @@ def unfollow(username):
|
|||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
if twUnfollow(username):
|
if twUnfollow(username):
|
||||||
flash("{} unfollowed!".format(username))
|
flash("{} unfollowed!".format(username))
|
||||||
else:
|
|
||||||
flash("Something went wrong...")
|
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
|
|
||||||
def twUnfollow(username):
|
def twUnfollow(username):
|
||||||
@ -130,7 +127,6 @@ def twUnfollow(username):
|
|||||||
user = twitterFollow.query.filter_by(username=username).first()
|
user = twitterFollow.query.filter_by(username=username).first()
|
||||||
db.session.delete(user)
|
db.session.delete(user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("{} unfollowed!".format(username))
|
|
||||||
except:
|
except:
|
||||||
flash("There was an error unfollowing the user. Try again.")
|
flash("There was an error unfollowing the user. Try again.")
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
@ -252,19 +248,21 @@ def ytfollow(channelId):
|
|||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
|
|
||||||
def followYoutubeChannel(channelId):
|
def followYoutubeChannel(channelId):
|
||||||
channel = youtubeFollow.query.filter_by(channelId=channelId).first()
|
|
||||||
channelData = YoutubeSearch.channelInfo(channelId, False)
|
channelData = YoutubeSearch.channelInfo(channelId, False)
|
||||||
try:
|
try:
|
||||||
follow = youtubeFollow()
|
if not current_user.is_following_yt(channelId):
|
||||||
follow.channelId = channelId
|
follow = youtubeFollow()
|
||||||
follow.channelName = channelData[0]['name']
|
follow.channelId = channelId
|
||||||
follow.followers.append(current_user)
|
follow.channelName = channelData[0]['name']
|
||||||
db.session.add(follow)
|
follow.followers.append(current_user)
|
||||||
db.session.commit()
|
db.session.add(follow)
|
||||||
flash("{} followed!".format(channelData[0]['name']))
|
db.session.commit()
|
||||||
return True
|
flash("{} followed!".format(channelData[0]['name']))
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
except:
|
except:
|
||||||
flash("Couldn't follow {}. Maybe you are already following!".format(channelData[0]['name']))
|
flash("Youtube: Couldn't follow {}. Already followed?".format(channelData[0]['name']))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@app.route('/ytunfollow/<channelId>', methods=['POST'])
|
@app.route('/ytunfollow/<channelId>', methods=['POST'])
|
||||||
@ -374,7 +372,7 @@ def export():
|
|||||||
return redirect(url_for('error/405'))
|
return redirect(url_for('error/405'))
|
||||||
|
|
||||||
def exportData():
|
def exportData():
|
||||||
twitterFollowing = current_user.following_list()
|
twitterFollowing = current_user.twitter_following_list()
|
||||||
youtubeFollowing = current_user.youtube_following_list()
|
youtubeFollowing = current_user.youtube_following_list()
|
||||||
data = {}
|
data = {}
|
||||||
data['twitter'] = []
|
data['twitter'] = []
|
||||||
@ -413,15 +411,20 @@ def importdata():
|
|||||||
flash('No selected file')
|
flash('No selected file')
|
||||||
return redirect(request.url)
|
return redirect(request.url)
|
||||||
if file and allowed_file(file.filename):
|
if file and allowed_file(file.filename):
|
||||||
filename = secure_filename(file.filename)
|
importAccounts(file)
|
||||||
data = json.load(file)
|
return render_template('settings.html')
|
||||||
for acc in data['twitter']:
|
|
||||||
if twFollow(acc['username']):
|
|
||||||
print("{} followed!".format(acc['username']))
|
|
||||||
else:
|
|
||||||
print("Something went wrong!")
|
|
||||||
return redirect(request.referrer)
|
return redirect(request.referrer)
|
||||||
|
|
||||||
|
def importAccounts(file):
|
||||||
|
filename = secure_filename(file.filename)
|
||||||
|
data = json.load(file)
|
||||||
|
for acc in data['twitter']:
|
||||||
|
r = followTwitterAccount(acc['username'])
|
||||||
|
|
||||||
|
for acc in data['youtube']:
|
||||||
|
r = followYoutubeChannel(acc['channelId'])
|
||||||
|
|
||||||
def allowed_file(filename):
|
def allowed_file(filename):
|
||||||
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||||
|
|
||||||
@ -461,7 +464,7 @@ def getTimeDiff(t):
|
|||||||
return timeString
|
return timeString
|
||||||
|
|
||||||
def isTwitterUser(username):
|
def isTwitterUser(username):
|
||||||
request = requests.get('https://nitter.net/{}/rss'.format(username), timeout=5)
|
request = requests.get('{instance}{user}/rss'.format(instance=nitterInstance, user=username))
|
||||||
if request.status_code == 404:
|
if request.status_code == 404:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@ -470,7 +473,7 @@ def getFeed(urls):
|
|||||||
avatarPath = "img/avatars/{}.png".format(str(random.randint(1,12)))
|
avatarPath = "img/avatars/{}.png".format(str(random.randint(1,12)))
|
||||||
feedPosts = []
|
feedPosts = []
|
||||||
with FuturesSession() as session:
|
with FuturesSession() as session:
|
||||||
futures = [session.get('https://nitter.net/{}/rss'.format(u.username)) for u in urls]
|
futures = [session.get('{instance}{user}/rss'.format(instance=nitterInstance, user=u.username)) for u in urls]
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
resp = future.result()
|
resp = future.result()
|
||||||
rssFeed=feedparser.parse(resp.content)
|
rssFeed=feedparser.parse(resp.content)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<br>
|
<br>
|
||||||
<div class="ui one column centered grid">
|
<div style="margin-bottom: 1em;" class="ui one column centered grid">
|
||||||
<h2 class="ui icon header">
|
<h2 class="ui icon header">
|
||||||
<i class="settings icon"></i>
|
<i class="settings icon"></i>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@ -11,8 +11,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
|
||||||
<br>
|
|
||||||
|
<div class="ui one column centered grid" style="margin-bottom: 1.4em;">
|
||||||
|
<div class="ui icon message" style=" width: 55%;">
|
||||||
|
<i class="info circle icon"></i>
|
||||||
|
<div class="content">
|
||||||
|
<div class="header">
|
||||||
|
Imports can take up to 2 minutes.
|
||||||
|
</div>
|
||||||
|
<p>But you can still use Parasitter.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="ui one column centered grid">
|
<div class="ui one column centered grid">
|
||||||
<div class="ui relaxed divided list">
|
<div class="ui relaxed divided list">
|
||||||
@ -30,7 +41,7 @@
|
|||||||
<input type = "file" name = "file"/>
|
<input type = "file" name = "file"/>
|
||||||
<input type = "submit"/>
|
<input type = "submit"/>
|
||||||
</form>
|
</form>
|
||||||
<div class="description">Import data from JSON file</div>
|
<div class="description">Import from JSON export.</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user