From a724f324708dcd7e539bb62e39faea6ff2e77a24 Mon Sep 17 00:00:00 2001 From: Alessio Date: Thu, 16 Mar 2023 17:50:36 -0300 Subject: [PATCH] Allow specifying session files with .session extension at command line --- cmd/tests.sh | 3 +++ cmd/twitter/main.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/cmd/tests.sh b/cmd/tests.sh index ecabcf7..53dd169 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -319,6 +319,9 @@ test "$(sqlite3 twitter.db "select count(*) from tweets where id = 1562714727968 tw --session Offline_Twatter fetch_tweet_only https://twitter.com/PandasAndVidya/status/1562714727968428032 test "$(sqlite3 twitter.db "select count(*) from tweets where id = 156271472796842803")" == "0" +# Test that you can pass a session with the `.session` file extension too +tw --session Offline_Twatter.session list_followed > /dev/null # Dummy operation + # TODO: Maybe this file should be broken up into multiple test scripts echo -e "\033[32mAll tests passed. Finished successfully.\033[0m" diff --git a/cmd/twitter/main.go b/cmd/twitter/main.go index 25fe047..fbe5c85 100644 --- a/cmd/twitter/main.go +++ b/cmd/twitter/main.go @@ -6,6 +6,7 @@ import ( log "github.com/sirupsen/logrus" "golang.org/x/term" "os" + "strings" "syscall" "offline_twitter/persistence" @@ -94,6 +95,10 @@ func main() { } if *session_name != "" { + if strings.HasSuffix(*session_name, ".session") { + // Lop off the ".session" suffix (allows using `--session asdf.session` which lets you tab-autocomplete at command line) + *session_name = (*session_name)[:len(*session_name)-8] + } scraper.InitApi(profile.LoadSession(scraper.UserHandle(*session_name))) // fmt.Printf("Operating as user: @%s\n", scraper.the_api.UserHandle) } else {