-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
WaybackBot
committed
Aug 21, 2020
1 parent
327114d
commit de38f2b
Showing
9 changed files
with
301 additions
and
131 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
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 |
---|---|---|
@@ -1,30 +1,125 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/wabarc/wayback" | ||
) | ||
|
||
type r = map[string]string | ||
|
||
type m struct { | ||
ia r | ||
is r | ||
ip r | ||
} | ||
|
||
var ( | ||
ia bool | ||
is bool | ||
ip bool | ||
|
||
daemon string | ||
|
||
host string | ||
port uint | ||
mode string | ||
tor bool | ||
|
||
token string | ||
chatid string | ||
debug bool | ||
|
||
rootCmd = &cobra.Command{ | ||
Use: "wayback", | ||
Short: "A CLI tool for wayback webpages.", | ||
Example: ` wayback https://www.wikipedia.org | ||
wayback https://www.fsf.org https://www.eff.org | ||
wayback --ia https://www.fsf.org | ||
wayback --ip https://www.fsf.org | ||
wayback --ia --is -d telegram -t your-telegram-bot-token | ||
WAYBACK_SLOT=pinata WAYBACK_APIKEY=YOUR-PINATA-APIKEY \ | ||
WAYBACK_SECRET=YOUR-PINATA-SECRET wayback --ip https://www.fsf.org`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
// Assign default flags | ||
assign() | ||
handle(cmd, args) | ||
}, | ||
Version: "1.0.0", | ||
} | ||
) | ||
|
||
var wbrc wayback.Broker | ||
|
||
func main() { | ||
rootCmd.Execute() | ||
} | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().StringVarP(&host, "host", "", "127.0.0.1", "IPFS daemon host.") | ||
rootCmd.PersistentFlags().UintVarP(&port, "port", "", 5001, "IPFS daemon port.") | ||
rootCmd.PersistentFlags().BoolVarP(&tor, "tor", "", false, "Saving webpage use tor proxy.") | ||
rootCmd.AddCommand(telegramCmd) | ||
rootCmd.Flags().BoolVarP(&ia, "ia", "", false, "Wayback webpages to Internet Archive.") | ||
rootCmd.Flags().BoolVarP(&is, "is", "", false, "Wayback webpages to Archive Today.") | ||
rootCmd.Flags().BoolVarP(&ip, "ip", "", false, "Wayback webpages to IPFS. (default false)") | ||
rootCmd.Flags().StringVarP(&daemon, "daemon", "d", "", "Run as daemon service.") | ||
rootCmd.Flags().StringVarP(&host, "ipfs-host", "", "127.0.0.1", "IPFS daemon host, do not require, unless enable ipfs.") | ||
rootCmd.Flags().UintVarP(&port, "ipfs-port", "p", 5001, "IPFS daemon port.") | ||
rootCmd.Flags().StringVarP(&mode, "ipfs-mode", "m", "pinner", "IPFS mode.") | ||
rootCmd.Flags().BoolVarP(&tor, "tor", "", false, "Snapshot webpage use tor proxy.") | ||
|
||
rootCmd.Flags().StringVarP(&token, "token", "t", "", "Telegram bot API Token, required.") | ||
rootCmd.Flags().StringVarP(&chatid, "chatid", "c", "", "Channel ID. default: \"\"") | ||
rootCmd.Flags().BoolVarP(&debug, "debug", "", false, "Enable debug mode. default: false") | ||
} | ||
|
||
func assign() { | ||
if !ia && !is && !ip { | ||
ia, is = true, true | ||
} | ||
} | ||
|
||
func output(tit string, args r) { | ||
fmt.Printf("[%s]\n", tit) | ||
for ori, dst := range args { | ||
fmt.Printf("%s => %s", ori, dst) | ||
} | ||
fmt.Print("\n") | ||
} | ||
|
||
func handle(cmd *cobra.Command, args []string) { | ||
switch daemon { | ||
case "telegram": | ||
telegram() | ||
default: | ||
if len(args) == 0 { | ||
cmd.Help() | ||
os.Exit(0) | ||
} | ||
|
||
r := &m{} | ||
if ia { | ||
r.ia = wbia(cmd, args) | ||
output("Internet Archive", r.ia) | ||
} | ||
if is { | ||
r.is = wbis(cmd, args) | ||
output("Archive Today", r.is) | ||
} | ||
if ip { | ||
r.ip = wbip(cmd, args) | ||
output("IPFS", r.ip) | ||
} | ||
} | ||
} | ||
|
||
func telegram() { | ||
ipfs := &wayback.IPFSRV{Host: host, Port: port, Mode: mode, UseTor: tor} | ||
handle := map[string]bool{ | ||
"ia": ia, | ||
"is": is, | ||
"ip": ip, | ||
} | ||
wbrc := wayback.NewConfig(token, debug, chatid, handle, ipfs) | ||
|
||
wbrc.Telegram() | ||
} |
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wabarc/wayback" | ||
) | ||
|
||
func wbia(cmd *cobra.Command, args []string) r { | ||
wbrc = &wayback.Handle{URI: args} | ||
|
||
return wbrc.IA() | ||
} | ||
|
||
func wbis(cmd *cobra.Command, args []string) r { | ||
wbrc = &wayback.Handle{URI: args} | ||
|
||
return wbrc.IS() | ||
} | ||
|
||
func wbip(cmd *cobra.Command, args []string) r { | ||
wbrc = &wayback.Handle{ | ||
URI: args, | ||
} | ||
|
||
return wbrc.WBIPFS() | ||
} |
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
Oops, something went wrong.