-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathadd_article.py
More file actions
35 lines (25 loc) · 880 Bytes
/
add_article.py
File metadata and controls
35 lines (25 loc) · 880 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
29
30
31
32
33
34
35
from models import Article, Author
from session import session, commit_on_success
@commit_on_success
def main():
answer = input("Do you want to add article? Y/N: ")
if answer.lower() == "y":
run = True
else:
run = False
while run:
login = input("Provide author login: ")
author = session.query(Author).filter_by(login=login).first()
if author is None:
print(f"Author {login} not found")
continue
title = input("Provide article title: ")
content = input("Provide article content: ")
article = Article(title=title, content=content)
author.articles.append(article)
print(f"Article {title} added")
answer = input("Do you want to add article? Y/N: ")
if answer.lower() != "y":
run = False
if __name__ == "__main__":
main()