-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplate_Method.py
92 lines (69 loc) · 2.31 KB
/
Template_Method.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from abc import ABC, abstractmethod
class Network(ABC):
def __init__(self, username, password):
self.username = username
self.password = password
def post(self, message: str) -> bool:
"""
Authenticate before posting. Every network uses a different authentication method.
"""
if self.logIn():
# Send the post data.
result = self.sendData(message)
self.logOut()
return result
return False
@abstractmethod
def logIn(self) -> bool:
pass
@staticmethod
@abstractmethod
def sendData(data: str) -> bool:
pass
@abstractmethod
def logOut(self) -> None:
pass
class Facebook(Network):
def logIn(self) -> bool:
print("\nChecking user's parameters")
print(f"Name: {self.username}")
print(f"Password: {'*' * len(self.password)}")
print("\n\nLogIn success on Facebook")
return True
@staticmethod
def sendData(data: str) -> bool:
messagePosted = True
if messagePosted:
print(f"Message: '{data}' was posted on Facebook")
return True
return False
def logOut(self) -> None:
print(f"User: '{self.username}' was logged out from Facebook")
class Instagram(Network):
def logIn(self) -> bool:
print("\nChecking user's parameters")
print(f"Name: {self.username}")
print(f"Password: {'*' * len(self.password)}")
print("\n\nLogIn success on Instagram")
return True
@staticmethod
def sendData(data: str) -> bool:
messagePosted = True
if messagePosted:
print(f"Message: '{data}' was posted on Intagram")
return True
return False
def logOut(self) -> None:
print(f"User: '{self.username}' was logged out from Instagram")
if __name__ == "__main__":
username = input("Input user name: ")
password = input("Input password: ")
message = input("\nInput message: \n")
choice = int(input("\nChoose social network for posting message.\n" +
"1 - Facebook\n" +
"2 - Instagram\n"))
if choice == 1:
network = Facebook(username, password)
elif choice == 2:
network = Instagram(username, password)
network.post(message)