Browse Source

nova nc knjiznica za pridobivanje public link in sprememba db da vsebuje te linke

master
Kostanjevec 3 weeks ago
parent
commit
418d8b2b70
  1. 12
      app.py
  2. 2
      create_db.py
  3. 11
      get_files.py
  4. 21
      populate_db_once.py

12
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)

2
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)

11
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)
for file in get_file_list():
link = client.get_url(file)
print(link)
info = client.info("/GIA CLOUD")

21
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()

Loading…
Cancel
Save