search steam store

This commit is contained in:
Fabien Freling 2020-05-06 00:15:15 +02:00
commit fe419d7705
4 changed files with 51 additions and 0 deletions

2
dune-project Normal file
View file

@ -0,0 +1,2 @@
(lang dune 2.5)
(name vg-store)

3
src/dune Normal file
View file

@ -0,0 +1,3 @@
(executable
(name main)
(libraries mechaml))

28
src/main.ml Normal file
View file

@ -0,0 +1,28 @@
open Mechaml
module M = Agent.Monad
open M.Infix
let require msg = function
| Some a -> a
| None -> failwith msg
let steam_search query =
let url = "https://store.steampowered.com/" in
Agent.get url
>|= (fun result ->
let form = result
|> Agent.HttpResponse.page
|> Page.form_with "[id=searchform]"
|> require "search form not found" in
let field = form
|> Page.Form.field_with "[name=term]"
|> require "q field not found" in
Page.Form.Field.set form field query)
>>= Agent.submit
>>= (fun response ->
response
|> Agent.HttpResponse.content
|> M.save_content "steam-result.html")
let _ =
M.run (Agent.init ()) (steam_search "planet")

18
vg-store.opam Normal file
View file

@ -0,0 +1,18 @@
opam-version: "2.0"
name: "vg-store"
version: "~dev"
synopsis: "Quickly check games on multiple stores"
maintainer: "Fabien Freling <public@ffreling.com>"
authors: "Fabien Freling <public@ffreling.com>"
license: "MIT"
homepage: "http://code.ffreling.com/fabs/vg-store"
bug-reports: "http://code.ffreling.com/fabs/vg-store/issues"
depends: [
"mechaml"
"lwt_ssl"
]
build: ["dune" "build" "-p" name "-j" jobs]
dev-repo: "git+http://code.ffreling.com/fabs/vg-store"
url {
src: "http://code.ffreling.com/fabs/vg-store"
}