-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afb0d6f
commit 6e3b549
Showing
5 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pyrogram==1.0.1 | ||
feedparser | ||
apscheduler | ||
pickledb | ||
psycopg2-binary | ||
sqlalchemy==1.3.23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker, scoped_session | ||
|
||
DATABASE_URL = os.environ.get("DATABASE_URL") | ||
|
||
def start() -> scoped_session: | ||
engine = create_engine(DATABASE_URL) | ||
BASE.metadata.bind = engine | ||
BASE.metadata.create_all(engine) | ||
return scoped_session(sessionmaker(bind=engine, autoflush=False)) | ||
|
||
|
||
try: | ||
BASE = declarative_base() | ||
SESSION = start() | ||
except AttributeError as e: | ||
# this is a dirty way for the work-around required for #23 | ||
print("DATABASE_URL is not configured. Features depending on the database might have issues.") | ||
print(str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from sqlalchemy import Column, String, Numeric, Boolean | ||
from sql import SESSION, BASE | ||
|
||
class database(BASE): | ||
__tablename__ = "database" | ||
website = Column(String, primary_key=True) | ||
link = Column(String) | ||
|
||
def __init__(self, website, link): | ||
self.website = website | ||
self.link = link | ||
|
||
|
||
database.__table__.create(checkfirst=True) | ||
|
||
|
||
def get_link(website): | ||
try: | ||
return SESSION.query(database).get(website) | ||
except: | ||
return None | ||
finally: | ||
SESSION.close() | ||
|
||
|
||
def update_link(website, link): | ||
adder = SESSION.query(database).get(website) | ||
if adder: | ||
adder.link = link | ||
else: | ||
adder = database( | ||
website, | ||
link | ||
) | ||
SESSION.add(adder) | ||
SESSION.commit() |