-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (47 loc) · 2.4 KB
/
main.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
try:
import unzip_requirements
except ImportError:
pass
import os
from enum import Enum
from config.service_config import ServiceConfigs
from config.system_config import SystemConfig
from core.handlers.on_demand_handler.on_demand_handler import OnDemandHandler
from social_networks.facebook.services.service_factory import ServiceFactory as FacebookServiceFactory
from social_networks.instagram.services.service_factory import ServiceFactory as InstagramServiceFactory
from social_networks.tiktok.services.service_factory import ServiceFactory as TiktokServiceFactory
class SocialNetworkServiceFactory(Enum):
FACEBOOK = FacebookServiceFactory
INSTAGRAM = InstagramServiceFactory
TIKTOK = TiktokServiceFactory
class ServicesRunner:
def __init__(self):
self.system_config = SystemConfig.get_system_config()
self.service_config = ServiceConfigs.get_service_config()
def run(self):
service_name, social_network = self.service_config['SERVICE_NAME'], self.system_config.SOCIAL_NETWORK
service_factory = getattr(SocialNetworkServiceFactory, social_network).value
service = service_factory.create_service(service_name=service_name,
service_config=self.service_config)
service.start()
class ServiceOnDemandRunner:
def __init__(self, event, context):
os.environ['LAMBDA'] = 'LAMBDA'
self.on_demand_handler = OnDemandHandler(event=event, context=context)
service_name, social_network = self.on_demand_handler.get_service_name_social_network_from_event()
self.system_config = SystemConfig.get_system_config(social_network)
def run(self):
service_name, social_network = self.on_demand_handler.get_service_name_social_network_from_event()
service_factory = getattr(SocialNetworkServiceFactory, social_network.upper()).value
service = service_factory.create_service(service_name=service_name,
service_config=None,
on_demand_handler=self.on_demand_handler
)
service.start()
def lambda_handler(event, context):
try:
return ServiceOnDemandRunner(event, context).run()
except Exception as e:
raise Exception(f'Exception: {e}, Event: {event}')
if __name__ == '__main__':
ServicesRunner().run()