Compare commits
6 Commits
0dc571eb56
...
be6a3242f9
Author | SHA1 | Date |
---|---|---|
janko | be6a3242f9 | |
janko | db037c62fa | |
janko | e6186847c4 | |
janko | b1a000abc5 | |
janko | 1d30287d27 | |
janko | a5dfc7130d |
2
app.py
2
app.py
|
@ -5,6 +5,7 @@ from deck import bp as deck_bp
|
||||||
from menu import bp as menu_bp
|
from menu import bp as menu_bp
|
||||||
from sr_session import sr_session
|
from sr_session import sr_session
|
||||||
from upload import bp as upload_bp
|
from upload import bp as upload_bp
|
||||||
|
from import_link import bp as import_link_bp
|
||||||
from matches import bp as matches_bp
|
from matches import bp as matches_bp
|
||||||
from settings import bp as settings_bp
|
from settings import bp as settings_bp
|
||||||
|
|
||||||
|
@ -54,6 +55,7 @@ def create_app(test_config=None):
|
||||||
app.register_blueprint(deck_bp)
|
app.register_blueprint(deck_bp)
|
||||||
app.register_blueprint(menu_bp)
|
app.register_blueprint(menu_bp)
|
||||||
app.register_blueprint(upload_bp)
|
app.register_blueprint(upload_bp)
|
||||||
|
app.register_blueprint(import_link_bp)
|
||||||
app.register_blueprint(matches_bp)
|
app.register_blueprint(matches_bp)
|
||||||
app.register_blueprint(settings_bp)
|
app.register_blueprint(settings_bp)
|
||||||
app.add_url_rule('/', endpoint='index')
|
app.add_url_rule('/', endpoint='index')
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Card(Base):
|
||||||
item_location = Column(String(1024))
|
item_location = Column(String(1024))
|
||||||
last_review = Column(Text)
|
last_review = Column(Text)
|
||||||
share_id = Column(Text) #explain: 0 means not shared, otherwise increment from db and generate new cards for all relevant(tbd) users
|
share_id = Column(Text) #explain: 0 means not shared, otherwise increment from db and generate new cards for all relevant(tbd) users
|
||||||
|
card_type = Column(String(1024))
|
||||||
|
|
||||||
class Deck(Base):
|
class Deck(Base):
|
||||||
__tablename__ = 'deck'
|
__tablename__ = 'deck'
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
from flask import (
|
||||||
|
Blueprint, render_template, request, session, flash
|
||||||
|
)
|
||||||
|
from create_db import Card, get_session
|
||||||
|
from link_handler import check_response
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('import_link', __name__, url_prefix='/import_link')
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/", methods=["GET", "POST"])
|
||||||
|
def index():
|
||||||
|
username = session["username"]
|
||||||
|
return render_template("import_link.html", username=username)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/import', methods = ('GET', 'POST'))
|
||||||
|
def import_link():
|
||||||
|
username = session['username']
|
||||||
|
user_id = session['user_id']
|
||||||
|
if request.method == 'POST':
|
||||||
|
import_type = request.form.get("import_type", False)
|
||||||
|
print(import_type)
|
||||||
|
if import_type == "import_txt":
|
||||||
|
print("!2313232321")
|
||||||
|
else:
|
||||||
|
link = request.form.get("link", False)
|
||||||
|
if check_response(link) == 1:
|
||||||
|
print(link, 'is ok')
|
||||||
|
commit_link(link=link, user_id=user_id)
|
||||||
|
else:
|
||||||
|
print(link, 'is not ok')
|
||||||
|
|
||||||
|
return render_template("import_link.html", user_id=user_id, username=username)
|
||||||
|
|
||||||
|
|
||||||
|
def commit_link(link, user_id):
|
||||||
|
dbsession = get_session()
|
||||||
|
|
||||||
|
existing_link = dbsession.query(Card).filter_by(owner_id=user_id, item_location=link).first()
|
||||||
|
if existing_link:
|
||||||
|
flash(f"{link} has already been imported.")
|
||||||
|
else:
|
||||||
|
#add card
|
||||||
|
#TODO ni razlike med title in vsebino urlja ??
|
||||||
|
card = Card(title=link,
|
||||||
|
interest_rate=-1.0,
|
||||||
|
owner_id=user_id,
|
||||||
|
item_location=link,
|
||||||
|
last_review=None,
|
||||||
|
card_type="URL",
|
||||||
|
share_id=0)
|
||||||
|
dbsession.add(card)
|
||||||
|
dbsession.commit()
|
||||||
|
flash(f"{link} imported successfully")
|
||||||
|
|
||||||
|
dbsession.close()
|
||||||
|
|
||||||
|
|
||||||
|
def import_list_of_links(list_of_links, user_id):
|
||||||
|
#TODO nekak bi bilo dobro, da pokaže kateri so failali....
|
||||||
|
for link in list_of_links:
|
||||||
|
commit_link(link, user_id)
|
|
@ -0,0 +1,63 @@
|
||||||
|
import requests
|
||||||
|
import re
|
||||||
|
from flask import render_template
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
def check_response(link):
|
||||||
|
"""
|
||||||
|
responds 1 if link is ok
|
||||||
|
2 if there's conncetion error
|
||||||
|
3 if link is invalid (no "http" for example)
|
||||||
|
"""
|
||||||
|
parsed_url = urlparse(link)
|
||||||
|
if parsed_url.scheme and parsed_url.netloc:
|
||||||
|
try:
|
||||||
|
response = requests.head(link)
|
||||||
|
if response.status_code == 200:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
#TODO drugi statusi code?
|
||||||
|
return "WEIRD"
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
print("conncetion error")
|
||||||
|
return 2
|
||||||
|
else:
|
||||||
|
print("link not valid (https:// missing??)")
|
||||||
|
return 3
|
||||||
|
|
||||||
|
|
||||||
|
# kako vse možne linke embeddat?
|
||||||
|
def render_embed_link(cm_username, card, maybe_in, no_in):
|
||||||
|
url = card.item_location
|
||||||
|
if re.match(r'^https?://(www\.)?twitter\.com/.*/status/\d+$', url):
|
||||||
|
tweet_id = url.split("/")[-1]
|
||||||
|
return render_template("embed_link/twitter_embed.html",
|
||||||
|
card=card,
|
||||||
|
tweet_id=tweet_id,
|
||||||
|
username=cm_username,
|
||||||
|
maybe_in=maybe_in,
|
||||||
|
no_in=no_in)
|
||||||
|
|
||||||
|
elif re.match(r'^https?://(www\.)?youtube\.com/watch\?.*v=([-\w]+)', url):
|
||||||
|
youtube_id = re.search(r'v=([-\w]+)', url).group(1)
|
||||||
|
return render_template("embed_link/youtube_embed.html",
|
||||||
|
youtube_id=youtube_id,
|
||||||
|
card=card,
|
||||||
|
username=cm_username,
|
||||||
|
maybe_in=maybe_in,
|
||||||
|
no_in=no_in)
|
||||||
|
|
||||||
|
#TODO kill me wtf about the instances.........
|
||||||
|
elif re.match(r'^https?://(www\.)?mastodon\.social/@[a-zA-Z0-9]+/\d+', url):
|
||||||
|
username, post_id = url.split("/")[-3:-1]
|
||||||
|
return render_template("embed_link/mastodon_embed.html", username=username, post_id=post_id)
|
||||||
|
|
||||||
|
else:
|
||||||
|
#TODO what if iframe fails
|
||||||
|
return render_template("embed_link/iframe_embed.html",
|
||||||
|
url=url,
|
||||||
|
card=card,
|
||||||
|
username=cm_username,
|
||||||
|
maybe_in=maybe_in,
|
||||||
|
no_in=no_in)
|
2
menu.py
2
menu.py
|
@ -43,6 +43,8 @@ def index():
|
||||||
return redirect(url_for("matches.index"))
|
return redirect(url_for("matches.index"))
|
||||||
elif action == "upload":
|
elif action == "upload":
|
||||||
return redirect(url_for("upload.index"))
|
return redirect(url_for("upload.index"))
|
||||||
|
elif action == "import-link":
|
||||||
|
return redirect(url_for("import_link.index"))
|
||||||
elif action == "settings":
|
elif action == "settings":
|
||||||
settings = get_settings(user_id)
|
settings = get_settings(user_id)
|
||||||
return render_template("settings.html", username=username, user_id=user_id, settings=settings)
|
return render_template("settings.html", username=username, user_id=user_id, settings=settings)
|
||||||
|
|
|
@ -5,6 +5,9 @@ from sqlalchemy import desc
|
||||||
from share import share
|
from share import share
|
||||||
from create_db import Card, Rating, get_session
|
from create_db import Card, Rating, get_session
|
||||||
from settings import get_settings
|
from settings import get_settings
|
||||||
|
from link_handler import render_embed_link
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
testing
|
testing
|
||||||
"""
|
"""
|
||||||
|
@ -266,5 +269,19 @@ def sr_session():
|
||||||
show_card = dbsession.query(Card).get(next_card_id)
|
show_card = dbsession.query(Card).get(next_card_id)
|
||||||
interval = get_interval(next_card_id)
|
interval = get_interval(next_card_id)
|
||||||
|
|
||||||
#these factors should be better packaged
|
card_type = show_card.card_type
|
||||||
return render_template("deck.html", username=username, card=show_card, maybe_in=round(interval*maybe_factor), no_in=round(no_factor*interval))
|
print("card type: ", card_type)
|
||||||
|
|
||||||
|
if card_type == 'PDF':
|
||||||
|
#these factors should be better packaged
|
||||||
|
return render_template("deck.html", username=username, card=show_card, maybe_in=round(interval*maybe_factor), no_in=round(no_factor*interval))
|
||||||
|
elif card_type == 'URL':
|
||||||
|
#templates for different kinds of links
|
||||||
|
return render_embed_link(cm_username=username,
|
||||||
|
card=show_card,
|
||||||
|
maybe_in=round(interval*maybe_factor),
|
||||||
|
no_in=round(no_factor*interval))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#return render_template("link.html", username=username, card=show_card, maybe_in=round(interval*maybe_factor), no_in=round(no_factor*interval))
|
|
@ -0,0 +1,5 @@
|
||||||
|
{% extends 'link.html' %}
|
||||||
|
|
||||||
|
{% block link %}
|
||||||
|
<iframe src="{{ card.item_location }}" width="100%" height="600px"></iframe>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,11 @@
|
||||||
|
{% extends 'link.html' %}
|
||||||
|
|
||||||
|
{% block link %}
|
||||||
|
<div class="embed">
|
||||||
|
<blockquote class="twitter-tweet" data-dnt="true">
|
||||||
|
<a href="https://twitter.com/twitter/status/{{ tweet_id }}"></a>
|
||||||
|
</blockquote>
|
||||||
|
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{% extends 'link.html' %}
|
||||||
|
|
||||||
|
{% block link %}
|
||||||
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/{{ youtube_id }}" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
{% extends 'partials/base.html' %}
|
||||||
|
|
||||||
|
{% block name %}upload{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<main>
|
||||||
|
<form method="post" enctype="multipart/form-data" action="/import_link/import">
|
||||||
|
<ol>
|
||||||
|
<li> <input placeholder="insert link" type="link" name="import_type"/></li>
|
||||||
|
<li> <button name="import_type" type="submit" value="import_txt">.txt file list of links</button></li>
|
||||||
|
<li> <button name="import_type" type="submit" value="import_twitter_bookmarks">import twitter bookmarks</button></li>
|
||||||
|
<li> <button name="import_type" type="submit" value="import_raindrop_links">import links from raindrop.io</button></li>
|
||||||
|
</ol>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends 'partials/base.html' %}
|
||||||
|
|
||||||
|
{% block name %}import{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<main>
|
||||||
|
<form class="dropzone dropzone-form" method="post" enctype="multipart/form-data" action="/upload/uploader">
|
||||||
|
<span id="dropzone-txt" class="dropzone-txt">Drop file here or click to upload.</span>
|
||||||
|
<input class="dropzone-input" type="file" name="file" runat="server" accept=".txt" multiple >
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script src="{{ url_for('static', filename='js/dropzone.js') }}"></script>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
{% extends 'partials/base.html' %}
|
||||||
|
|
||||||
|
{% block name %}deck{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<main>
|
||||||
|
<article>
|
||||||
|
{% block link %}{% endblock %}
|
||||||
|
<footer>
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="card_id" value="{{ card['id'] }}">
|
||||||
|
<!-- <span id="buttonContainer" style="display: flex; justify-content: space-around;"> -->
|
||||||
|
<span id="buttonContainer">
|
||||||
|
<button type="submit" name="rate" value="Yes" accesskey="1">Yes (1)</button> <!--ti keyi so alt+shit+key...-->
|
||||||
|
<button type="submit" name="rate" value="Maybe" accesskey="2">Maybe ({{maybe_in}})</button>
|
||||||
|
<button type="submit" name="rate" value="No" accesskey="3">No ({{no_in}})</button>
|
||||||
|
<button type="submit" name="rate" value="Delete" accesskey="d">Delete</button>
|
||||||
|
<button type="submit" name="share" value="Share" accesskey="s">Share</button>
|
||||||
|
</span>
|
||||||
|
</form>
|
||||||
|
</footer>
|
||||||
|
</article>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
<button type="submit" name="menu" value="upload">Upload</button>
|
<button type="submit" name="menu" value="upload">Upload</button>
|
||||||
|
|
||||||
|
<button type="submit" name="menu" value="import-link">Import Link</button>
|
||||||
|
|
||||||
<button type="submit" name="menu" value="settings">Settings</button>
|
<button type="submit" name="menu" value="settings">Settings</button>
|
||||||
|
|
||||||
<button type="submit" name="menu" value="instructions">Instructions</button>
|
<button type="submit" name="menu" value="instructions">Instructions</button>
|
||||||
|
|
Loading…
Reference in New Issue