File size: 1,748 Bytes
dbaa71b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import logging
import os
import sys

from obsei.analyzer.dummy_analyzer import DummyAnalyzer, DummyAnalyzerConfig
from obsei.processor import Processor
from obsei.sink.slack_sink import SlackSink, SlackSinkConfig
from obsei.source.playstore_scrapper import (PlayStoreScrapperConfig,
                                             PlayStoreScrapperSource)
from obsei.workflow.store import WorkflowStore
from obsei.workflow.workflow import Workflow, WorkflowConfig


def print_state(identifier: str):
    logger.info(f"Source State: {source.store.get_source_state(identifier)}")


logger = logging.getLogger(__name__)
logging.basicConfig(stream=sys.stdout, level=logging.INFO)


workflow_store = WorkflowStore()

source_config = PlayStoreScrapperConfig(
    app_url='https://play.google.com/store/apps/details?id=com.google.android.gm&hl=en_IN&gl=US',
    max_count=3
)

source = PlayStoreScrapperSource(store=workflow_store)

sink_config = SlackSinkConfig(
    slack_token=os.environ["SLACK_TOKEN"],
    channel_id="C01TUPZ23NZ",
    jinja_template="""
```
     {%- for key, value in payload.items() recursive%}
         {%- if value is mapping -%}
{{loop(value.items())}}
         {%- else %}
{{key}}: {{value}}
         {%- endif %}
     {%- endfor%}
```
   """
)
sink = SlackSink(store=workflow_store)

analyzer_config = DummyAnalyzerConfig()
analyzer = DummyAnalyzer()

workflow = Workflow(
    config=WorkflowConfig(
        source_config=source_config,
        sink_config=sink_config,
        analyzer_config=analyzer_config,
    ),
)
workflow_store.add_workflow(workflow)

processor = Processor(
    analyzer=analyzer, sink=sink, source=source, analyzer_config=analyzer_config
)

processor.process(workflow=workflow)

print_state(workflow.id)