-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from sdslabs/magnus_major
Fixing the broken
- Loading branch information
Showing
27 changed files
with
469 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"foxundermoon.shell-format" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule hugo-geekdoc
added at
c420c6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package retrieve_data | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/sdslabs/katana/lib/mongo" | ||
"github.com/sdslabs/katana/lib/utils" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
var ticker *time.Ticker | ||
var tick int | ||
|
||
func saveJSON() { | ||
for range ticker.C { | ||
data := mongo.FetchDocs(context.Background(), "teams", bson.M{}) | ||
path := fmt.Sprintf("./json_data/data-tick-%d.json", tick) | ||
jsonData, err := convertBSONArrayToJSONArray(data) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
storeJSONToFile(jsonData, path) | ||
tick++ | ||
} | ||
} | ||
|
||
func StartSaving() { | ||
ticker = utils.GetTicker() | ||
utils.CreateDirectoryIfNotExists("json_data") | ||
go saveJSON() | ||
} | ||
|
||
func convertBSONArrayToJSONArray(bsonArray []bson.M) ([]byte, error) { | ||
var jsonArray []map[string]interface{} | ||
|
||
for _, bsonDoc := range bsonArray { | ||
delete(bsonDoc, "publicKey") | ||
delete(bsonDoc, "password") | ||
|
||
jsonArray = append(jsonArray, bsonDoc) | ||
} | ||
|
||
jsonData, err := json.Marshal(jsonArray) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal JSON array: %w", err) | ||
} | ||
|
||
return jsonData, nil | ||
} | ||
|
||
func storeJSONToFile(jsonData []byte, filePath string) error { | ||
jsonMap := map[string]interface{}{"data": json.RawMessage(jsonData)} | ||
|
||
finalJSONData, err := json.MarshalIndent(jsonMap, "", " ") | ||
if err != nil { | ||
return fmt.Errorf("failed to marshal final JSON: %w", err) | ||
} | ||
|
||
err = os.WriteFile(filePath, finalJSONData, 0644) | ||
if err != nil { | ||
return fmt.Errorf("failed to write JSON to file: %w", err) | ||
} | ||
|
||
fmt.Printf("JSON data stored in file: %s\n", filePath) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package utils | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
var Ticker *time.Ticker | ||
|
||
func InitTicker(duration time.Duration) { | ||
Ticker = time.NewTicker(duration) | ||
} | ||
|
||
func GetTicker() *time.Ticker { | ||
return Ticker | ||
} | ||
|
||
func SetTicker(ticker *time.Ticker) { | ||
Ticker = ticker | ||
} | ||
|
||
func StopTicker() { | ||
Ticker.Stop() | ||
} | ||
|
||
func ResetTicker(duration time.Duration) { | ||
Ticker.Reset(duration) | ||
} | ||
|
||
func GetRemainingTimeBeforeNextTick() time.Duration { | ||
return time.Until(<-Ticker.C) | ||
} |
Oops, something went wrong.