From 9d3eacc2561cd936ecacd9a806ef4c59c6b7ba9e Mon Sep 17 00:00:00 2001 From: Alessio Date: Thu, 3 Aug 2023 13:15:39 -0300 Subject: [PATCH] Add a subcommand 'twitter webserver' to start the server --- cmd/twitter/help_message.txt | 4 ++++ cmd/twitter/main.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/twitter/help_message.txt b/cmd/twitter/help_message.txt index 15af4f4..080c2a1 100644 --- a/cmd/twitter/help_message.txt +++ b/cmd/twitter/help_message.txt @@ -66,6 +66,10 @@ This application downloads tweets from twitter and saves them in a SQLite databa unlike_tweet "Like" or un-"like" the tweet indicated by . (Requires authentication) + + webserver + Start a webserver that serves a web UI to browse the tweet archive + : -h, --help Print this message, then exit. diff --git a/cmd/twitter/main.go b/cmd/twitter/main.go index 37c8e2f..e0ad5e5 100644 --- a/cmd/twitter/main.go +++ b/cmd/twitter/main.go @@ -9,6 +9,7 @@ import ( "strings" "syscall" + "gitlab.com/offline-twitter/twitter_offline_engine/internal/webserver" "gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence" "gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper" ) @@ -31,6 +32,7 @@ func main() { flag.BoolVar(show_version_flag, "v", false, "") session_name := flag.String("session", "", "Name of session file to use") + addr := flag.String("addr", ":1488", "port to listen on") // Random port that's probably not in use how_many := flag.Int("n", 50, "") flag.IntVar(how_many, "number", 50, "") @@ -73,7 +75,7 @@ func main() { log.SetLevel(logging_level) if len(args) < 2 { - if len(args) == 1 && args[0] == "list_followed" { + if len(args) == 1 && (args[0] == "list_followed" || args[0] == "webserver") { // "list_followed" doesn't need a target, so create a fake second arg args = append(args, "") } else { @@ -150,6 +152,8 @@ func main() { like_tweet(target) case "unlike_tweet": unlike_tweet(target) + case "webserver": + start_webserver(*addr) default: die(fmt.Sprintf("Invalid operation: %s", operation), true, 3) } @@ -372,3 +376,8 @@ func list_followed() { fmt.Println(handle) } } + +func start_webserver(addr string) { + app := webserver.NewApp(profile) + app.Run(addr) +}