resolver/
resolver.rs

1// This is free and unencumbered software released into the public domain.
2
3use std::io::Write;
4
5use asimov_module::{models::ModuleManifest, resolve::Resolver};
6
7const YAMLS: &str = r#"
8name: near
9label: NEAR Protocol
10summary: Data import from the NEAR Protocol blockchain network.
11links:
12  - https://github.com/asimov-modules/asimov-near-module
13  - https://crates.io/crates/asimov-near-module
14  - https://pypi.org/project/asimov-near-module
15  - https://rubygems.org/gems/asimov-near-module
16  - https://npmjs.com/package/asimov-near-module
17
18provides:
19  programs:
20    - asimov-near-fetcher
21
22handles:
23  url_protocols:
24    - near
25
26---
27name: serpapi
28label: SerpApi
29summary: Data import powered by the SerpApi search data platform.
30links:
31  - https://github.com/asimov-modules/asimov-serpapi-module
32  - https://crates.io/crates/asimov-serpapi-module
33  - https://pypi.org/project/asimov-serpapi-module
34  - https://rubygems.org/gems/asimov-serpapi-module
35  - https://npmjs.com/package/asimov-serpapi-module
36
37provides:
38  programs:
39    - asimov-serpapi-fetcher
40    - asimov-serpapi-importer
41
42handles:
43  url_prefixes:
44    - https://bing.com/search?q=
45    - https://duckduckgo.com/?q=
46    - https://google.com/search?q=
47
48---
49name: apify
50label: Apify
51summary: Data import powered by the Apify web automation platform.
52links:
53    - https://github.com/asimov-modules/asimov-apify-module
54    - https://crates.io/crates/asimov-apify-module
55    - https://pypi.org/project/asimov-apify-module
56    - https://rubygems.org/gems/asimov-apify-module
57    - https://npmjs.com/package/asimov-apify-module
58
59provides:
60    programs:
61    - asimov-apify-fetcher
62    - asimov-apify-importer
63
64handles:
65    url_patterns:
66    - https://google.com/search?q=:query
67    - https://x.com/:account/followers
68    - https://x.com/:account/following
69
70---
71name: brightdata
72label: Bright Data
73summary: Data import powered by the Bright Data web data platform.
74links:
75    - https://github.com/asimov-modules/asimov-brightdata-module
76    - https://crates.io/crates/asimov-brightdata-module
77    - https://pypi.org/project/asimov-brightdata-module
78    - https://rubygems.org/gems/asimov-brightdata-module
79    - https://npmjs.com/package/asimov-brightdata-module
80
81provides:
82    programs:
83    - asimov-brightdata-fetcher
84    - asimov-brightdata-importer
85
86handles:
87    url_prefixes:
88    - https://airbnb.com/rooms/
89    - https://amazon.com/
90    - https://amazon.com/sp?seller=
91    - https://crunchbase.com/organization/
92    - https://ebay.com/itm/
93    - https://facebook.com/events/
94    - https://facebook.com/groups/
95    - https://facebook.com/marketplace/item/
96    - https://facebook.com/share/p/
97    - https://finance.yahoo.com/quote/
98    - https://google.com/shopping/product/
99    - https://indeed.com/cmp/
100    - https://instagram.com/
101    - https://instagram.com/p/
102    - https://instagram.com/reel/
103    - https://linkedin.com/company/
104    - https://linkedin.com/in/
105    - https://linkedin.com/jobs/
106    - https://linkedin.com/posts/
107    - https://linkedin.com/pulse/
108    - https://walmart.com/global/seller/
109    - https://walmart.com/ip/
110    - https://x.com/
111    - https://youtube.com/@
112    - https://youtube.com/watch?v=
113"#;
114
115fn main() {
116    let manifests = YAMLS
117        .split("---")
118        .map(serde_yml::from_str::<'_, ModuleManifest>)
119        .map(Result::unwrap);
120    let resolver = Resolver::try_from_iter(manifests).unwrap();
121
122    let mut stdout = std::io::stdout().lock();
123    let mut lines = std::io::stdin().lines();
124    loop {
125        stdout.write_all(b"query > ").unwrap();
126        stdout.flush().unwrap();
127
128        let Some(Ok(query)) = lines.next() else {
129            break;
130        };
131        let answers = resolver.resolve(&query).unwrap();
132        println!("answers:");
133        for answer in answers {
134            println!(" - {}", answer.name);
135        }
136    }
137}