Skip to content

Commit 121f44d

Browse files
authored
Merge pull request #2 from script-development/feat/mock-mode
feat: mock mode
2 parents edf8277 + b421f2b commit 121f44d

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

DENO_README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ A [Deno](https://deno.land) client that can be used by a scraper to ease communi
1717
],
1818
"login_users": [
1919
{"username": "scraping-site-username", "password": "scraping-site-password"}
20-
]
20+
],
21+
// For production, set mock_mode to false
22+
// "mock_mode": false
2123
}
2224
```
2325

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Check file:///.../denoexample.ts
4747
```sh
4848
# Install latest version
4949
go install github.com/script-development/rtcv_scraper_client/v2@latest
50-
# Install a spesific version
50+
# Install a specific version
5151
go install github.com/script-development/rtcv_scraper_client/v2@v2.0.3
5252
```
5353
@@ -66,14 +66,18 @@ Create a `env.json` file with the following content **(this file can also be obt
6666
],
6767
"login_users": [
6868
{"username": "scraping-site-username", "password": "scraping-site-password"}
69-
]
69+
],
70+
// For production, set mock_mode to false
71+
// "mock_mode": false
7072
}
7173
```
7274
7375
### *3.* Develop / Deploy a scraper using `rtcv_scraper_client`
7476
7577
You can now prefix your scraper's run command with `rtcv_scraper_client` and the scraper client program will run a webserver as long as your scraper runs where via you can communicate with RT-CV.
7678
79+
By default the program will run in `mock_mode`, for production you'll have to explicitly turn it off by setting `"mock_mode": false` in your env.json
80+
7781
If you have for a NodeJS project you can run your program like this:
7882
7983
```sh

api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (c *serverConn) DoRequest(method, path string, body, unmarshalResInto inter
137137
if err != nil {
138138
attempt++
139139
if attempt > 3 {
140-
return fmt.Errorf("%s, retried 4 times", err.Error())
140+
return fmt.Errorf("%s retried 4 times", err.Error())
141141
}
142142
time.Sleep(time.Second * time.Duration(attempt) * 2)
143143
continue

main.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Env struct {
1717
PrimaryServer EnvServer `json:"primary_server"`
1818
AlternativeServers []EnvServer `json:"alternative_servers"`
1919
LoginUsers []EnvUser `json:"login_users"`
20+
MockMode bool `json:"mock_mode"`
2021
}
2122

2223
func (e *Env) validate() error {
@@ -96,14 +97,24 @@ func main() {
9697
credentials = append(credentials, server.toCredArg(false))
9798
}
9899

99-
err = api.SetCredentials(credentials)
100-
if err != nil {
101-
log.Fatal(err)
100+
// Turn on mock mode by default
101+
api.SetMockMode()
102+
103+
if !env.MockMode {
104+
err = api.SetCredentials(credentials)
105+
if err != nil {
106+
log.Fatal(err)
107+
}
108+
109+
fmt.Println("credentials set")
110+
fmt.Println("testing connections..")
111+
testServerConnections(api)
112+
fmt.Println("connected to RTCV")
113+
} else {
114+
fmt.Println("In mock mode")
115+
fmt.Println("You can turn this off in by setting mock_mode to false in your env.json")
102116
}
103-
fmt.Println("credentials set")
104-
fmt.Println("testing connections..")
105-
testServerConnections(api)
106-
fmt.Println("connected to RTCV")
117+
107118
fmt.Println("running scraper..")
108119

109120
if len(os.Args) <= 1 {

0 commit comments

Comments
 (0)