Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 6 #8

Merged
merged 5 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion CLIUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class CLIUsage{
public static void WelcomeManual(){

Console.WriteLine("\nThank you for using GoodLinkOrBadLink!");
Console.WriteLine("\nRun the tool command with a file that contains URLs on your local machine and find out which are good links and which are not. For example: goodOrBad urls.txt\nUse \"goodOrBad --v\" or \"goodOrBad --version\" to get the current version of package.");
Console.WriteLine("\nRun the tool command with a file that contains URLs on your local machine and find out which are good links and which are not. For example: goodOrBad urls.txt" +
"\nUse \"goodOrBad --v\" or \"goodOrBad --version\" to get the current version of package." +
"\nUse \"goodOrBad --w\" or \"goodOrBad --wayback\" to check Wayback machine's availability.");


}
Expand Down Expand Up @@ -40,5 +42,23 @@ public static bool Version(string argument){
}

}

public static bool WayBack(string argument){

string[] args = {"--w", "--wayback", "/w"};
List<string> waybackList = new List<string>(args);

bool wayback = waybackList.Any(w => argument.Contains(w));
if(wayback){

return true;

}else{

return false;

}
}

}
}
6 changes: 5 additions & 1 deletion OSD600.GoodLinkOrBadLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
</PropertyGroup>

<ItemGroup>
<None Include="LICENSE.txt" Pack="true" PackagePath="LICENSE.txt"/>
<None Include="LICENSE.txt" Pack="true" PackagePath="LICENSE.txt" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

</Project>
131 changes: 85 additions & 46 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Net.Http;
using System.Threading.Tasks;
using System.Reflection;

using Newtonsoft.Json;

namespace OSD600.GoodLinkOrBadLink
{
Expand All @@ -26,84 +26,123 @@ static async Task Main(string[] args)
}else{

bool readArgAsFile = CLIUsage.Version(args[0]);
bool wayback = CLIUsage.WayBack(args[0]);

if(readArgAsFile){

}else{




try{
string filePath = args[0];

string file = args[0];

string[] fileContent = File.ReadAllLines(args[0]);

if(wayback) {
try {
filePath = args[1];
} catch(Exception) {
Console.WriteLine("Missing file input");

if(fileContent == null || fileContent.Length < 1){

Console.WriteLine("\"{0}\" is empty, there is nothing to test", args[0]);
System.Environment.Exit(1);
}
}
string[] fileContent = File.ReadAllLines(filePath);

}else{


Regex rx = new Regex(@"https?://[a-zA-Z0-9@:%._\+~#=]");


string[] urls = File.ReadAllLines(args[0]);


if(fileContent == null || fileContent.Length < 1){

Console.WriteLine("\"{0}\" is empty, there is nothing to test", filePath);

}else{

List<string> lines = new List<string>();

Regex rx = new Regex(@"https?://[a-zA-Z0-9@:%._\+~#=]");


string[] urls = File.ReadAllLines(filePath);

foreach(String line in urls){



List<string> lines = new List<string>();


if(rx.IsMatch(line)){

try{

HttpResponseMessage response = await client.GetAsync(line);

if((int)response.StatusCode == 200){
foreach(String line in urls){

Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[Good] ");
Console.ResetColor();
Console.WriteLine(line);



}else if((int)response.StatusCode == 400 || (int)response.StatusCode == 404){

Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[Bad] ");
Console.ResetColor();
Console.WriteLine(line);
}
if(rx.IsMatch(line)){

try{

if (wayback) {

var jsonString = new WebClient().DownloadString("http://archive.org/wayback/available?url=" + line);
dynamic x = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString);
var archived = x.archived_snapshots;
dynamic available;
try {
var closest = archived.closest;
available = closest.available;
}catch(Exception){
available = false;
}

if ((bool)available) {
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[Available] ");
Console.ResetColor();
Console.WriteLine(line);
} else {
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[Not Available] ");
Console.ResetColor();
Console.WriteLine(line);
}


}catch(HttpRequestException){
} else {
HttpResponseMessage response = await client.GetAsync(line);
if((int)response.StatusCode == 200){

Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("[Unknown] ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[Good] ");
Console.ResetColor();
Console.WriteLine(line);

}else if((int)response.StatusCode == 400 || (int)response.StatusCode == 404){


Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[Bad] ");
Console.ResetColor();
Console.WriteLine(line);
}
}

}else{


Console.WriteLine("not a URL");
}

}catch(HttpRequestException){

Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("[Unknown] ");
Console.ResetColor();
Console.WriteLine(line);



}
}

}else{

Console.WriteLine("not a URL");
}

}
}

}catch(FileNotFoundException e){

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Use this command to uninstall the tool:

#### How to use it

After installation, use the command `goodOrBad` as a command line tool along with a file arguement that you would like to check. For example, the file on your local machine is `urls.txt`, use the command `goodOrBad urls.txt` to run the tool. You can also check the version of this tool with `goodOrBad --v` or `goodOrBad --version` command.
After installation, use the command `goodOrBad` as a command line tool along with a file arguement that you would like to check. For example, the file on your local machine is `urls.txt`, use the command `goodOrBad urls.txt` to run the tool.
* You can also check the version of this tool with `goodOrBad --v` or `goodOrBad --version` command.
* You can also check the wayback availiability with `goodOrBad --w` or `goodOrBad --wayback` command.

You can use this *goodOrBad* command in any directory. You can either move to the directory that contains the file that you want to test, or just simply use file path and run it with the command.

Expand Down
18 changes: 18 additions & 0 deletions bin/Debug/netcoreapp3.1/OSD600.GoodLinkOrBadLink.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
"targets": {
".NETCoreApp,Version=v3.1": {
"OSD600.GoodLinkOrBadLink/1.0.5": {
"dependencies": {
"Newtonsoft.Json": "12.0.3"
},
"runtime": {
"OSD600.GoodLinkOrBadLink.dll": {}
}
},
"Newtonsoft.Json/12.0.3": {
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"assemblyVersion": "12.0.0.0",
"fileVersion": "12.0.3.23909"
}
}
}
}
},
Expand All @@ -18,6 +29,13 @@
"type": "project",
"serviceable": false,
"sha512": ""
},
"Newtonsoft.Json/12.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-6mgjfnRB4jKMlzHSl+VD+oUc1IebOZabkbyWj2RiTgWwYPPuaK1H97G1sHqGwPlS5npiF5Q0OrxN1wni2n5QWg==",
"path": "newtonsoft.json/12.0.3",
"hashPath": "newtonsoft.json.12.0.3.nupkg.sha512"
}
}
}
Binary file modified bin/Debug/netcoreapp3.1/OSD600.GoodLinkOrBadLink.dll
Binary file not shown.
Binary file modified bin/Debug/netcoreapp3.1/OSD600.GoodLinkOrBadLink.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"/home/heidi/.dotnet/store/|arch|/|tfm|",
"/home/heidi/.nuget/packages"
"/home/rogeryu27/.dotnet/store/|arch|/|tfm|",
"/home/rogeryu27/.nuget/packages"
]
}
}
Binary file not shown.
23 changes: 0 additions & 23 deletions bin/Debug/netcoreapp3.1/publish/OSD600.GoodLinkOrBadLink.deps.json

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file modified nupkg/OSD600.GoodLinkOrBadLink.1.0.5.nupkg
Binary file not shown.
21 changes: 0 additions & 21 deletions obj/Debug/OSD600.GoodLinkOrBadLink.1.0.0.nuspec

This file was deleted.

21 changes: 0 additions & 21 deletions obj/Debug/OSD600.GoodLinkOrBadLink.1.0.1.nuspec

This file was deleted.

21 changes: 0 additions & 21 deletions obj/Debug/OSD600.GoodLinkOrBadLink.1.0.2.nuspec

This file was deleted.

Loading