-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOandErrorHandling.cs
More file actions
91 lines (82 loc) · 2.38 KB
/
Copy pathIOandErrorHandling.cs
File metadata and controls
91 lines (82 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Data.SQLite;
namespace ArchiveMe
{
class IOandErrorHandling
{
public static void Menu()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Press 1 for thread scrapping:");
Console.WriteLine("Press 2 to display archived threads:");
}
public static bool CheckIfDatabaseExist(string board, string thread)
{
DirectoryInfo dir = new DirectoryInfo("Database");
FileInfo[] files = dir.GetFiles("*.db");
foreach (var file in files)
{
if (board == file.Name.Substring(0, file.Name.IndexOf('.')))
{
return true;
}
}
return false;
}
public static bool CheckIfTableExist(string board, string thread)
{
SQLiteConnection sql_dat = new SQLiteConnection("Data Source=Database\\" + board.ToString() + ".db");
sql_dat.Open();
string sql = "SELECT * from op" + thread;
SQLiteCommand sql_com = new SQLiteCommand(sql, sql_dat);
try
{
using (SQLiteDataReader reader = sql_com.ExecuteReader())
{
while (reader.Read())
{
}
}
}
catch
{
sql_dat.Close();
return false;
}
sql_dat.Close();
return true;
}
public static void Quit()
{
while (true)
{
string inp = Console.ReadLine();
if (inp == "quit")
{
break;
}
}
}
public static void ThreadScrappingLine()
{
Console.Write("Set board (g,fit,diy,...): ");
}
public static bool CheckUrl(string board, string thread)
{
try
{
var cliet = new WebClient();
cliet.DownloadString("https://a.4cdn.org/" + board + "/thread/" + thread + ".json");
}
catch (Exception)
{
return false;
}
return true;
}
}
}