contentmatcher/populate_db_once.py

39 lines
1.0 KiB
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from create_db import Card, get_session
from get_files import get_file_list
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")
#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, last_review=None, share_id="0")
dbsession.add(card)
dbsession.commit()
dbsession.close()
"""
id = Column(Integer, primary_key=True, autoincrement=True)
title = Column(String(1024))
interest_rate = Column(Float)
owner_id = Column(Integer, ForeignKey("user.id"), nullable=False)
"""