mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
fix: update outdated examples in openbb-apachebeam (#7286)
- examples/openbb-apachebeam/README.md: Fix test-run command to point to example tests directory, fix typos and grammar - examples/openbb-apachebeam/requirements.txt: Add core 'openbb' dependency required by example - examples/openbb-apachebeam/tests/test_obb_pipeline.py: Fix code formatting, fix 'Print nes' typo to 'Print news' Fixes #7181 Co-authored-by: Murat Aslan <murataslan1@users.noreply.github.com> Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
This commit is contained in:
15
examples/openbb-apachebeam/README.md
vendored
15
examples/openbb-apachebeam/README.md
vendored
@@ -1,12 +1,13 @@
|
|||||||
# OBB Dataflow Sample
|
# OBB Dataflow Sample
|
||||||
|
|
||||||
|
This is a sample on how to invoke OBB fetchers in an Apache Beam pipeline. (GCP Dataflow is built on Apache Beam)
|
||||||
|
|
||||||
This is a sample how to invoke OBB fetchers in an Apache Beam pipeline. (GCP dataflow is build on Apache Beam)
|
|
||||||
Pre-requisites
|
Pre-requisites
|
||||||
- You need to create a Conda environment (or a virtual env) using requirements.txt in this directory
|
- You need to create a Conda environment (or a virtual env) using `requirements.txt` in this directory
|
||||||
- The script exercise 3 OBB endpoints, all of which require no credentials
|
- The script exercises three OBB endpoints, all of which require no credentials
|
||||||
- Run the test from the main directory
|
- Run the test from this directory:
|
||||||
python -m unittest .\tests\test_obb_pipeline.py
|
cd examples/openbb-apachebeam
|
||||||
|
python -m unittest tests/test_obb_pipeline.py
|
||||||
|
|
||||||
The script will run a pipeline consisting of 3 task which will fetch AAPL quote, profile and news
|
The script will run a pipeline consisting of three tasks which will fetch an AAPL quote, profile, and news.
|
||||||
This is just a very basic sample which can be used as building block to create more complex scenarios
|
This is just a very basic sample which can be used as a building block to create more complex scenarios
|
||||||
|
|||||||
@@ -22,26 +22,35 @@ class AsyncProcess(beam.DoFn):
|
|||||||
def process(self, element: str):
|
def process(self, element: str):
|
||||||
return asyncio.run(self.fetch_data(element))
|
return asyncio.run(self.fetch_data(element))
|
||||||
|
|
||||||
|
|
||||||
class MyTestCase(unittest.TestCase):
|
class MyTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
def test_sample_pipeline(self):
|
def test_sample_pipeline(self):
|
||||||
credentials = {} # Running OBB endpoints which do not require credentials
|
credentials = {} # Running OBB endpoints which do not require credentials
|
||||||
debug_sink = beam.Map(print)
|
debug_sink = beam.Map(print)
|
||||||
ticker = 'AAPL'
|
ticker = 'AAPL'
|
||||||
|
|
||||||
with TestPipeline(options=PipelineOptions()) as p:
|
with TestPipeline(options=PipelineOptions()) as p:
|
||||||
quote = (p | 'Start Quote' >> beam.Create([ticker])
|
quote = (
|
||||||
| 'Run Quote' >> beam.ParDo(AsyncProcess(credentials, quote_fetcher))
|
p
|
||||||
| 'Print quote' >> debug_sink)
|
| 'Start Quote' >> beam.Create([ticker])
|
||||||
|
| 'Run Quote' >> beam.ParDo(AsyncProcess(credentials, quote_fetcher))
|
||||||
|
| 'Print quote' >> debug_sink
|
||||||
|
)
|
||||||
|
|
||||||
profile = (p | 'Start Profile' >> beam.Create([ticker])
|
profile = (
|
||||||
| 'Run Profile' >> beam.ParDo(AsyncProcess(credentials, profile_fetcher))
|
p
|
||||||
| 'Print profile' >> debug_sink)
|
| 'Start Profile' >> beam.Create([ticker])
|
||||||
|
| 'Run Profile' >> beam.ParDo(AsyncProcess(credentials, profile_fetcher))
|
||||||
|
| 'Print profile' >> debug_sink
|
||||||
|
)
|
||||||
|
|
||||||
news = (p | 'Start News' >> beam.Create([ticker])
|
news = (
|
||||||
| 'Run News' >> beam.ParDo(AsyncProcess(credentials, news_fetcher))
|
p
|
||||||
| 'Print nes' >> debug_sink)
|
| 'Start News' >> beam.Create([ticker])
|
||||||
|
| 'Run News' >> beam.ParDo(AsyncProcess(credentials, news_fetcher))
|
||||||
|
| 'Print news' >> debug_sink
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user