37```
38
39Refer to [Twitter's search operators](https://developer.twitter.com/en/docs/twitter-api/v1/rules-and-filtering/search-operators) to fine-tune your query.
40
41### 4. Test API call
42Set `isProd = false` in the code if you are testing, to ensure there are enough tweets to display. <br>
43Toggle it back to `true` when you're ready to run this cron job in production.
65
66### NOTE: Usage Limits
67This val uses the SocialData API for Twitter data:
68- **Proxies via Val Town's SocialDataProxy**: Limited to 100 calls/day for [**Val Town Pro users**](https://www.val.town/pricing).
69- **Need more calls?** Sign up for your own [SocialData API token](https://socialdata.tools) and configure the [`socialDataSearch`](https://www.val.town/v/stevekrouse/socialDataSearch) function.
1export async function searchWithSerpApi({
2 query,
3 site,
4 daysBack,
5 apiKey,
6}: {
7 query: string;
8 site?: string;
9 daysBack?: number;
10 apiKey: string;
11}): Promise<SearchResult[]> {
12 if (!apiKey) {
13 console.warn("SERP API key not provided. Skipping search.");
14 return [];
15 }
21
22 const encodedQuery = encodeURIComponent(`${query} ${site ? `site:${site}` : ""} after:${formattedDate}`);
23 const url = `https://serpapi.com/search.json?engine=google&q=${encodedQuery}&api_key=${apiKey}&sort_by=date`;
24
25 try {
36 }));
37 } catch (error) {
38 console.error("Error occurred during SERP API search:", error);
39 return [];
40 }
37```
38
39Refer to [Twitter's search operators](https://developer.twitter.com/en/docs/twitter-api/v1/rules-and-filtering/search-operators) to fine-tune your query.
40
41### 4. Test API call
42Set `isProd = false` in the code if you are testing, to ensure there are enough tweets to display. <br>
43Toggle it back to `true` when you're ready to run this cron job in production.
61
62### NOTE: Usage Limits
63This val uses the SocialData API for Twitter data:
64- **Proxies via Val Town's SocialDataProxy**: Limited to 100 calls/day for [**Val Town Pro users**](https://www.val.town/pricing).
65- **Need more calls?** Sign up for your own [SocialData API token](https://socialdata.tools) and configure the [`socialDataSearch`](https://www.val.town/v/stevekrouse/socialDataSearch) function.
37```
38
39Refer to [Twitter's search operators](https://developer.twitter.com/en/docs/twitter-api/v1/rules-and-filtering/search-operators) to fine-tune your query.
40
41### 4. Test API call
42Set `isProd = false` in the code if you are testing, to ensure there are enough tweets to display. <br>
43Toggle it back to `true` when you're ready to run this cron job in production.
61
62### NOTE: Usage Limits
63This val uses the SocialData API for Twitter data:
64- **Proxies via Val Town's SocialDataProxy**: Limited to 100 calls/day for [**Val Town Pro users**](https://www.val.town/pricing).
65- **Need more calls?** Sign up for your own [SocialData API token](https://socialdata.tools) and configure the [`socialDataSearch`](https://www.val.town/v/stevekrouse/socialDataSearch) function.
19```
20
21You can use this library with https://www.val.town/v/maxm/transformEvalCode to return the last value without needing to export it. This is how the /eval api endpoint used to work and makes the library preform similarly to a repl.
22
23```ts
8import { Wide } from 'https://esm.town/v/maxm/wide';
9
10// Use your Val Town API Token to create a session
11const wide = new Wide(await ValSession.new(Deno.env.get("valtown")))
12
1import { ValSession } from "https://esm.town/v/maxm/valSession";
2// import type { TSearchFilter, WideApi } from "https://esm.town/v/maxm/wideApi";
3type WideApi = any;
4type TSearchFilter = any;
5import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
7
8const { htmlUrl } = extractValInfo(import.meta.url);
9const _client = hc<WideApi>("https://maxm-wideapi.web.val.run/");
10
11export class Wide {
14 constructor(sessionToken: string) {
15 // TODO: can we use a global client?
16 this.#client = hc<WideApi>("https://maxm-wideapi.web.val.run/");
17 this.#sessionToken = sessionToken;
18 }
75
76export default async function(req: Request): Promise<Response> {
77 // Use your Val Town API Token to create a session
78 const wide = new Wide(await ValSession.new(Deno.env.get("valtown")));
79 await wide.write([{
98 <script>hljs.highlightAll();</script>
99 <style>
100 @import url('https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght@900&family=Roboto+Mono:wght@400;700&display=swap');
101
102 * {
196import { Wide } from 'https://esm.town/v/maxm/wide';
197
198// Use your Val Town API Token to create a session
199const wide = new Wide(await ValSession.new(Deno.env.get("valtown")))
200
4import { ValSession } from "https://esm.town/v/maxm/valSession";
5
6// Generate a token from your valtown api key.
7const token = await ValSession.newSession(Deno.env.get("valtown"));
8
101 <pre><code class="language-typescript">import { ValSession } from "${rawUrl}";
102
103// Generate a token from your valtown api key.
104const token = await ValSession.new(Deno.env.get("valtown"));
105
127});
128
129type valSessionApi = typeof routes;
130
131const client = hc<valSessionApi>(httpEndpoint);
132
133export class ValSession {
4import { ValSession } from "https://esm.town/v/maxm/valSession";
5
6// Generate a token from your valtown api key.
7const token = await ValSession.newSession(Deno.env.get("valtown"));
8