resolver/
resolver.rs

1// This is free and unencumbered software released into the public domain.
2
3use std::io::Write;
4
5use asimov_module::resolve::ResolverBuilder;
6
7const YAMLS: &'static 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  flows:
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  flows:
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    flows:
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    flows:
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 mut builder = ResolverBuilder::new();
117
118    for module in YAMLS.split("---") {
119        let module: serde_yml::Mapping = serde_yml::from_str(module).unwrap();
120        let name = &module["name"].as_str().unwrap();
121
122        if let Some(protocols) = &module["handles"]["url_protocols"].as_sequence() {
123            for protocol in protocols.iter() {
124                builder
125                    .insert_protocol(name, protocol.as_str().unwrap())
126                    .unwrap();
127            }
128        }
129
130        if let Some(prefixes) = &module["handles"]["url_prefixes"].as_sequence() {
131            for prefix in prefixes.iter() {
132                builder
133                    .insert_prefix(name, prefix.as_str().unwrap())
134                    .unwrap()
135            }
136        }
137
138        if let Some(patterns) = &module["handles"]["url_patterns"].as_sequence() {
139            for pattern in patterns.iter() {
140                builder
141                    .insert_pattern(name, pattern.as_str().unwrap())
142                    .unwrap()
143            }
144        }
145    }
146
147    let resolver = builder.build().unwrap();
148
149    let mut stdout = std::io::stdout().lock();
150    let mut lines = std::io::stdin().lines();
151    loop {
152        stdout.write_all(b"query > ").unwrap();
153        stdout.flush().unwrap();
154
155        let Some(Ok(query)) = lines.next() else {
156            break;
157        };
158        let answers = resolver.resolve(&query).unwrap();
159        println!("answers:");
160        for answer in answers {
161            println!(" - {}", answer.name);
162        }
163    }
164}