contentmatcher/populate_db_once.py

26 lines
810 B
Python

from create_db import Card, get_session, get_engine
from config import CONFIG
import nextcloud_client
dbsession = get_session()
nc = nextcloud_client.Client('https://obzorje.kompot.si')
nc.login(CONFIG['NC_USER'],CONFIG['NC_PASSWORD'])
l = nc.list("/GIA CLOUD")
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, last_review=None, share_id="0")
Session = get_session()
with Session() as dbsession:
dbsession.add(card)
dbsession.commit()
dbsession.close()
get_engine().dispose()