forked from SDA-workshops/bwitter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
28 lines (23 loc) · 798 Bytes
/
application.py
File metadata and controls
28 lines (23 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from models import Base, Article, Hashtag
from session import Session
if __name__ == "__main__":
session = Session()
Base.metadata.create_all(
session.get_bind()
)
article_id = input("Provide article id: ")
hashtag_id = input("Provide hashtag id: ")
article = session.query(Article).get(article_id)
if article is None:
print("No such article")
else:
print(f"Hashtags in article: {article.title}")
for hashtag in article.hashtags:
print(hashtag.hashtag)
hashtag = session.query(Hashtag).get(hashtag_id)
if hashtag is None:
print("No such hashtag")
else:
print(f"\nArticles with specific hashtag: {hashtag.hashtag}")
for article in hashtag.articles:
print(article.title)