|
|
@@ -1,12 +1,14 @@
|
|
|
# Site Back-End Logic
|
|
|
from hmac import new
|
|
|
from unicodedata import category
|
|
|
-from flask import Blueprint, render_template, request, flash, redirect, url_for
|
|
|
+from flask import Blueprint, render_template, request, flash, redirect, url_for, send_file
|
|
|
from flask_login import login_user, login_required, logout_user, current_user
|
|
|
from werkzeug.security import generate_password_hash, check_password_hash
|
|
|
from .models import User, Bookmark, Groups
|
|
|
from . import db
|
|
|
import string, secrets
|
|
|
+import csv, os
|
|
|
+import subprocess as sp
|
|
|
|
|
|
logic = Blueprint('logic', __name__)
|
|
|
|
|
|
@@ -14,6 +16,22 @@ logic = Blueprint('logic', __name__)
|
|
|
@login_required
|
|
|
def home():
|
|
|
|
|
|
+ def generate_csv():
|
|
|
+ header = ['name', 'link', 'group', 'status']
|
|
|
+ alphanumeric = string.ascii_letters + string.digits
|
|
|
+ ralphanum = ''.join(secrets.choice(alphanumeric) for i in range(16))
|
|
|
+ open(f'app/static/generated/{ralphanum}.csv', 'a').close
|
|
|
+ with open(f'app/static/generated/{ralphanum}.csv', 'w', encoding='UTF8', newline='') as f:
|
|
|
+ writer = csv.writer(f, delimiter=',', quotechar='"')
|
|
|
+ writer.writerow(header)
|
|
|
+ for bg, bml in bb_dic.items():
|
|
|
+ for bm in bml:
|
|
|
+ writer.writerow([bm.name, bm.link, bg, bm.status])
|
|
|
+ #cwd = os.getcwd()
|
|
|
+ p1 = sp.run(f'curl --upload-file app/static/generated/{ralphanum}.csv https://transfer.raqnet.org/', shell=True, capture_output=True, text=True)
|
|
|
+ return redirect(p1.stdout, code=302)
|
|
|
+ #return send_file(f'{cwd}/app/static/generated/{ralphanum}.csv', as_attachment=True, attachment_filename='test.csv')
|
|
|
+
|
|
|
# owned groups
|
|
|
bgroups = Groups.query.filter_by(owner=current_user.id).all()
|
|
|
# owned bookmarks
|
|
|
@@ -32,6 +50,7 @@ def home():
|
|
|
passwd = request.form.get('password')
|
|
|
passwdc = request.form.get('password_confirm')
|
|
|
new_pic = request.files.get('profile_image')
|
|
|
+ dl_bookml = request.form.get('dl_bookml')
|
|
|
|
|
|
if username:
|
|
|
nusern_dbcall = User.query.filter_by(id=current_user.id).first()
|
|
|
@@ -59,6 +78,8 @@ def home():
|
|
|
new_pic_dbcall.profile_image = f'{ralphanum}.jpeg'
|
|
|
db.session.commit()
|
|
|
flash('Profile Pic updated!', category='success')
|
|
|
+ elif dl_bookml:
|
|
|
+ return generate_csv()
|
|
|
|
|
|
return render_template('home.html', user=current_user, bdic=bb_dic)
|
|
|
|