diff --git a/app.py b/app.py index 82ae223..a9f50de 100644 --- a/app.py +++ b/app.py @@ -12,6 +12,9 @@ from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from config import CONFIG +from get_public_links import test_file + + engine = create_engine(CONFIG['DB_CONNECTION']) dbsessionmaker = sessionmaker(bind=engine) dbsession = dbsessionmaker() @@ -56,7 +59,11 @@ def create_app(test_config=None): d = get_deck(user_id) deck_index+=1 - card = d[deck_index] + if deck_index < len(d): + card = d[deck_index] + else: + deck_index =-1 + return end_of_session() #for card in d: #TODO to ne dela, nevem kako renderat zapooredno kartic if request.method == 'POST': @@ -86,6 +93,9 @@ def create_app(test_config=None): session.pop("user_id", None) return index() + @app.route('/end') + def end_of_session(): + return "end" #app.register_blueprint(bp) # ?? app.register_blueprint(auth_bp) diff --git a/create_db.py b/create_db.py index 18bb25e..9c26c2c 100644 --- a/create_db.py +++ b/create_db.py @@ -32,9 +32,9 @@ class Card(Base): title = Column(String(1024)) owner_id = Column(Integer, ForeignKey("user.id"), nullable=False) interest_rate = Column(Float) + item_location = Column(String(1024)) # shared = Column(Bool) -# item_location = Column(String) # item_type = Column(String) # content_type = Column(String) # item_size = Column(Integer) diff --git a/get_files.py b/get_files.py index 530b9a5..56e8f60 100644 --- a/get_files.py +++ b/get_files.py @@ -12,9 +12,16 @@ options = { } client = Client(options) +print(dir(client)) def get_file_list(): return client.list("/GIA CLOUD") -# for file in get_file_list(): -# print(file) \ No newline at end of file +for file in get_file_list(): + link = client.get_url(file) + print(link) + + + +info = client.info("/GIA CLOUD") + diff --git a/populate_db_once.py b/populate_db_once.py index 49d3988..aa5f8c4 100644 --- a/populate_db_once.py +++ b/populate_db_once.py @@ -5,16 +5,29 @@ from create_db import Card from get_files import get_file_list from config import CONFIG +import nextcloud_client engine = create_engine(CONFIG['DB_CONNECTION']) dbsessionmaker = sessionmaker(bind=engine) dbsession = dbsessionmaker() -stuff = get_file_list() -for item in stuff: - if item[-4:] == ".pdf": - card = Card(title=item, interest_rate=-1.0, owner_id=1) +nc = nextcloud_client.Client('https://obzorje.kompot.si') + +nc.login('gia', 'gia0000!') + + +l = nc.list("/GIA CLOUD") + + +#stuff = get_file_list() +for item in l: + if item.get_name()[-4:] == ".pdf": + name = item.get_name() + + public_share = nc.share_file_with_link("/GIA CLOUD/"+name) + public_link = public_share.get_link()+"/download/"+name + card = Card(title=name, interest_rate=-1.0, owner_id=1, item_location=public_link) dbsession.add(card) dbsession.commit()