internal static void OpenUrl(string url) { // https://stackoverflow.com/questions/4580263/how-to-open-in-default-browser-in-c-sharp try { if (url != null) { Process.Start(url); } else { Console.WriteLine(); CliOutput.WriteError("URL is null!"); } } catch { // hack because of this: https://github.com/dotnet/corefx/issues/10361 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { url = url.Replace("&", "^&"); Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }); } else { throw; } } }
public static BasicAccount CreateAccount(bool auto) { RapidWebDriver rwd; try { CliOutput.WriteInfo("Please wait..."); rwd = RapidWebDriver.CreateQuick(true); } catch (Exception exception) { CliOutput.WriteError("Exception: {0}", exception.Message); //throw; CliOutput.WriteError("Error creating webdriver"); return(BasicAccount.Null); } string uname, pwd, email; if (auto) { uname = Strings.CreateRandom(10); pwd = Strings.CreateRandom(10); email = WebAgent.EMail.GetEmail(); } else { Console.Write("Username: "******"Password: "******"Email: "); email = Console.ReadLine(); } Console.WriteLine("\nUsername: {0}\nPassword: {1}\nEmail: {2}\n", uname, pwd, email); try { CliOutput.WriteInfo("Registering account..."); var acc = CreateAccountInternal(rwd, uname, email, pwd); CliOutput.WriteInfo("Cleaning up..."); rwd.Dispose(); return(acc); } catch (Exception exception) { CliOutput.WriteError("Exception: {0}", exception.Message); //throw; CliOutput.WriteError("Error creating account"); return(BasicAccount.Null); } }
private static BasicAccount CreateAccountInternal(RapidWebDriver rwd, string username = null, string email = null, string password = null) { var cd = rwd.Value; cd.Url = BASE_URL + "user.php"; var usernameEle = cd.FindElement(ByUsername); usernameEle.SendKeys(username); var emailEle = cd.FindElement(ByEmail); emailEle.SendKeys(email); var pwdEle = cd.FindElement(ByPassword); pwdEle.SendKeys(password); var pwd2Ele = cd.FindElement(ByPasswordConfirmation); pwd2Ele.SendKeys(password); var regEle = cd.FindElement(ByRegister); regEle.Click(); var body = cd.FindElement(ByBody); var response = body.Text; Thread.Sleep(TimeSpan.FromSeconds(5)); if (cd.Url != ACC_OV_URL || !response.Contains("welcome")) { CliOutput.WriteError("Error registering: {0} (body: {1})", cd.Url, response); return(BasicAccount.Null); } CliOutput.WriteSuccess("Success!"); // https://saucenao.com/user.php?page=search-api cd.Url = ACC_API_URL; var apiEle = cd.FindElement(ByApiKey); var apiText = apiEle.Text.Split(' ')[2]; return(new BasicAccount(username, password, email, apiText)); }
private static void RunIntegrated(IIntegrated c, Action add, Action remove) { if (c.Add) { add(); } else if (c.Remove) { remove(); } else { CliOutput.WriteError("Option unknown: {0}", c.Option); } }
private static bool IsFileValid(string img) { if (!File.Exists(img)) { CliOutput.WriteError("File does not exist: {0}", img); return(false); } bool extOkay = ImageExtensions.Any(img.EndsWith); if (!extOkay) { return(CliOutput.ReadConfirm("File extension is not recognized as a common image format. Continue?")); } return(true); }
// ____ _ ___ // / ___| _ __ ___ __ _ _ __| |_|_ _|_ __ ___ __ _ __ _ ___ // \___ \| '_ ` _ \ / _` | '__| __|| || '_ ` _ \ / _` |/ _` |/ _ \ // ___) | | | | | | (_| | | | |_ | || | | | | | (_| | (_| | __/ // |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___| // |___/ // todo: further improve UI // todo: remove SmartImage nuget package stuff // todo: fix access modifiers /** * Entry point */ private static void Main(string[] args) { Console.Title = RuntimeInfo.NAME; Console.SetWindowSize(120, 35); Console.Clear(); RuntimeInfo.Setup(); SearchConfig.ReadSearchConfigArguments(args); if (SearchConfig.Config.NoArguments) { Commands.RunCommandMenu(); Console.Clear(); } var img = SearchConfig.Config.Image; bool run = !String.IsNullOrWhiteSpace(img); if (!run) { return; } var results = new SearchResult[(int)SearchEngines.All]; var ok = Search.RunSearch(img, ref results); if (!ok) { CliOutput.WriteError("Search failed"); return; } Commands.HandleConsoleOptions(results); // Exit SearchConfig.Cleanup(); }
private SauceNaoResult[] GetApiResults(string url) { if (m_apiKey == null) { // todo return(Array.Empty <SauceNaoResult>()); } var req = new RestRequest(); req.AddQueryParameter("db", "999"); req.AddQueryParameter("output_type", "2"); req.AddQueryParameter("numres", "16"); req.AddQueryParameter("api_key", m_apiKey); req.AddQueryParameter("url", url); var res = m_client.Execute(req); WebAgent.AssertResponse(res); //Console.WriteLine("{0} {1} {2}", res.IsSuccessful, res.ResponseStatus, res.StatusCode); //Console.WriteLine(res.Content); string c = res.Content; if (String.IsNullOrWhiteSpace(c)) { CliOutput.WriteError("No SN results!"); } return(ReadResults(c)); }